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?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
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))))