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?
PPRINT in Emacs Lisp?
Asked Answered
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. –
Outrigger
Use the pp
library which is part of GNU Emacs. For example you can use pp-macroexpand-last-sexp
for prettifying an sexp.
Easiest way is to just use
(pp object)
–
Elizbeth My... that library looks familiar. Oh yeah, I wrote it. :) –
Scrivenor
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))
When you are a buffer how can you get cl-prettyprint to replace a defun with its pretty printed version? Can –
Appellant
Thanks for this. It's weird to me that
cl-prettyprint
doesn't return a string in the first place. –
Portwine © 2022 - 2024 — McMap. All rights reserved.