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?
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:
terpriis 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
terpri hardcodes your extra newlines. Your simplest
solution is probably to rewrite this function and strip out the calls to
(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))))
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.