An Elisp Editing Tip
One of the first things new Emacs users learn is the eval-last-sexp
(C-x C-e
) command and that Emacs can interpret elisp anywhere it appears. Here’s a quick tip about using this command when writing elisp that you may not have discovered.
If you call it with a prefix (C-u
) argument, it prints (or attempts to print) the result in place in the buffer. Better yet, call it with an argument of 0
(C-0 C-x C-e
) to avoid truncating longer results.
Variables evaluate to their values, so here it prints the current values of these variables:
This is handy when writing elisp, for example if you want to tweak the current value of a variable:
I replace eval-last-sexp
everywhere with pp-eval-last-sexp
, which produces a cleaner result:
(global-set-key [remap eval-last-sexp] 'pp-eval-last-sexp)
That is all.