I'd like to print a string in ielm. I don't want to print the printed representation, I want the string itself. I'd like this result:
ELISP> (some-unknown-function "a\nb\n")
a
b
ELISP>
I can't see any way to do this. The obvious functions are print
and princ
, but these give me the printable representation:
ELISP> (print "* first\n* second\n* third\n")
"* first\n* second\n* third\n"
I've played with pp
and pp-escape-newlines
, but these still escape other characters:
ELISP> (setq pp-escape-newlines nil)
nil
ELISP> (pp "a\n")
"\"a
\""
Is this possible? For inspecting large strings, message
doesn't cut it.
How about inserting directly into the buffer?
(defun p (x) (move-end-of-line 0) (insert (format "\n%s" x)))
That gets you:
ELISP> (p "a\nb\n")
a
b
nil
ELISP>
EDIT: Use format
to be able to print things other than strings.
;;; Commentary:
;; Provides a nice interface to evaluating Emacs Lisp expressions.
;; Input is handled by the comint package, and output is passed
;; through the pretty-printer.
IELM uses (pp-to-string ielm-result)
(so binding pp-escape-newlines
has an effect in general), but if you want to bypass pp
altogether then IELM doesn't provide for that, so I suspect Sean's answer is your best option.
ELISP> (setq pp-escape-newlines nil)
nil
ELISP> "foo\nbar"
"foo
bar"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With