With M-q (aka fill-paragraph), it is possible to format a single line of text nicely.

Is there a command or function which does a similar thing for lisps s-expressions?

It should break one-liner lisp expression where it is reasonable.
A command or function is searched.
I do not want a mode which is constantly formating the s-expressions.

Edit: Thanks to Drews comment I realized that fill-paragraph does not get called by M-q in paredit mode.

  • Check out lispy. It has commands for this: O and M. github.com/abo-abo/lispy/blob/master/README.md – John Kitchin Jun 26 '17 at 11:35
  • @John Kitchin I will have a look, but i need to drop paredit for this(?) – jue Jun 26 '17 at 11:38
  • M-q does work for sexps - it indents consistently, including indenting same-line comments etc. Its effects vary by programming language, though. But it does not split or join lines (that is typically a personal style decision, often on a case-by-case basis). – Drew Jun 26 '17 at 13:23
  • @Drew thanks for this comment! Now I realized that paredit is redefining M-q. – jue Jun 26 '17 at 17:06
  • I don't think you would have to give up paredit. Just M-x the commands those keys are bound to. – John Kitchin Jun 27 '17 at 13:58

Perhaps you're looking for indent-pp-sexp, which is bound to C-M-q by default in emacs lisp mode. With a prefix argument (e.g. C-u C-M-q) this will "pretty print" the sexp at point.

| improve this answer | |
  • C-M-q alone does not, but C-u C-M-q does the job, thank you – jue Jun 26 '17 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.