7

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.

5
  • Check out lispy. It has commands for this: O and M. github.com/abo-abo/lispy/blob/master/README.md Jun 26, 2017 at 11:35
  • @John Kitchin I will have a look, but i need to drop paredit for this(?)
    – jue
    Jun 26, 2017 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, 2017 at 13:23
  • @Drew thanks for this comment! Now I realized that paredit is redefining M-q.
    – jue
    Jun 26, 2017 at 17:06
  • I don't think you would have to give up paredit. Just M-x the commands those keys are bound to. Jun 27, 2017 at 13:58

1 Answer 1

8

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.

2
  • 1
    C-M-q alone does not, but C-u C-M-q does the job, thank you
    – jue
    Jun 26, 2017 at 14:20
  • This doesn't work, it doesn't break the lines into multiple lines and indent. This is the same as normal indent. I'm using Scheme mode. fill-paragraph break line input multiple lines this does not.
    – jcubic
    Jan 9, 2021 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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