23

Emacs Lisp does not seem to have a PPRINT function. How do you pretty print an S-EXP in elisp the way you can in Common Lisp?

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
anthonyf
  • 231
  • 2
  • 4
  • I see cl-prettyprint will print to the current buffer. I am looking for something that works with an output stream like Common Lisp's PPRINT does. – anthonyf Aug 23 '10 at 22:17

2 Answers2

27

Use the pp library which is part of GNU Emacs. For example you can use pp-macroexpand-last-sexp for prettifying an sexp.

Jérôme Radix
  • 10,285
  • 4
  • 34
  • 40
13

Assuming that the result of cl-prettyprint is good enough for you, here's how to get its output in a stream.

(defun pprint (form &optional output-stream)
  (princ (with-temp-buffer
           (cl-prettyprint form)
           (buffer-string))
         output-stream))
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254