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.

jue
  • 4,476
  • 8
  • 20
  • Check out lispy. It has commands for this: O and M. https://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

1 Answers1

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.

glucas
  • 20,175
  • 1
  • 51
  • 83
  • 1
    `C-M-q` alone does not, but `C-u C-M-q` does the job, thank you – jue Jun 26 '17 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 09 '21 at 15:33