Search code examples
emacstransposeparedit

Paredit and transpose code blocks


If I have the following s-expression:

(if true (this) (that))

And I want:

(if true (that) (this))

How does paredit helps to transpose (this) and (that)?


Solution

  • I don't know what "paredit" is, but in stock Emacs you can place the point between (this) and (that) and hit C-M-t which runs the command transpose-sexps:

    Like C-t (transpose-chars), but applies to sexps.

    Unlike transpose-words, point must be between the two sexps and not in the middle of a sexp to be transposed.

    With non-zero prefix arg ARG, effect is to take the sexp before point and drag it forward past ARG other sexps (backward if ARG is negative). If ARG is zero, the sexps ending at or after point and at or after mark are interchanged.