emacsparedit

when is paredit-close-round's combined nature useful?


paredit-close-round (which is usually bound to close paren) combines two things:

  1. C-M-- C-M-u

  2. delete some spaces

The doc for the function has this simple example:

(a b |c   )
->
(a b c)|

I see why C-M-- C-M-u is useful; it's useful to use before C-x C-e, and I also see why a command for deleting those spaces may be useful, but I don't see why there is a command that combines the two. There must be a usage scenario I am missing which would explain why the space cleaning feature is added particularly to paredit-close-round but not to its forward counterpart paredit-backward-up.


Solution

  • paredit-close-paren sort of implies you're done editing that sexp, so any whitespace that's left at the end should be deleted. Plus, it's bound to an "editing" key (close-paren), so it's ok that it changes buffer content.

    paredit-forward-up (or backward-up with a negative prefix) is a movement command, so it shouldn't change buffer content.

    Here's a use-case: (point is at the |)

    (let ((hi t))|
      (forward-char 1)
      )
    
    1. If you're done editing that let statement, then that newline (after the forward-char) should be deleted, so you hit ) which moves you out of the let and cleans it up nice.
    2. If you're not done editing that let, but you want to move out of it for now, then you may actually want to keep that newline (it makes it easier to move to the right place and it helps you remember there's unfinished business), so you use C-M-n instead, which moves you out of the let without editing anything.