0

When I run (+ 1 1) using eval-print-last-sexp in a buffer, this function inserts a newline and outputs 2. I'd rather its output were just ' 2' (space and 2).

How can I change this?

  • 1
    The question is not clear. How are you evaluating that sexp? Evaluation itself does not print anything - it simply returns 2. Your question is likely about the function (command) that is actually printing the value, but you give no recipe. The question will likely be deleted unless it is clarified. – Drew Mar 16 '17 at 14:06
  • @Drew fair enough, done. – Quora Feans Mar 16 '17 at 18:42
1

Here's the code for evaluate-print-last-sexp, minus the docstring. (Note: I found this with C-h f evaluate-print-last-sexp, and following the link to the source code.)

(defun eval-print-last-sexp (&optional eval-last-sexp-arg-internal)
  "(DOCSTRING HERE)"
  (interactive "P")
  (let ((standard-output (current-buffer)))
    (terpri)
    (eval-last-sexp (or eval-last-sexp-arg-internal t))
    (terpri)))

It calls the function terpri, whose docstring reads:

terpri is a built-in function in `C source code'.

(terpri &optional PRINTCHARFUN)

Output a newline to stream PRINTCHARFUN. If PRINTCHARFUN is omitted or nil, the value of standard-output is used.

So terpri hardcodes your extra newlines. Your simplest solution is probably to rewrite this function and strip out the calls to terpri:

(defun my-eval-print-last-sexp (&optional eval-last-sexp-arg-internal)
  "I hate newlines."
  (interactive "P")
  (let ((standard-output (current-buffer)))
    (eval-last-sexp (or eval-last-sexp-arg-internal t))))
0

You might simply use eval-last-sexp with a prefix instead of eval-print-last-sexp. For me this is already bound to C-x C-e, so I just need to type C-U C-x C-e.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.