summaryrefslogtreecommitdiff
path: root/lisp/progmodes/elisp-mode.el
diff options
context:
space:
mode:
authorNoam Postavsky <npostavs@gmail.com>2017-04-23 22:21:42 -0400
committerNoam Postavsky <npostavs@gmail.com>2017-05-19 18:16:15 -0400
commit267be4bdc28564a99f45da29e84eb98838117b50 (patch)
tree3816b74e945cb1a17a1f4c8ad5e25e4abb0e8206 /lisp/progmodes/elisp-mode.el
parentc1c8b67246c4314b302cca2ac43f13a0baba4c16 (diff)
downloademacs-267be4bdc28564a99f45da29e84eb98838117b50.tar.gz
emacs-267be4bdc28564a99f45da29e84eb98838117b50.tar.bz2
emacs-267be4bdc28564a99f45da29e84eb98838117b50.zip
Refactor lisp eval result printing
* lisp/simple.el (eval-expression-print-format): Don't check `standard-output' or `current-prefix-arg'. (eval-expression-get-print-arguments): New function, centralizes decision about how to print results of `eval-expression' and `eval-last-sexp'. (eval-expression): * lisp/progmodes/elisp-mode.el (elisp--eval-last-sexp-print-value): Use it.
Diffstat (limited to 'lisp/progmodes/elisp-mode.el')
-rw-r--r--lisp/progmodes/elisp-mode.el35
1 files changed, 17 insertions, 18 deletions
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 53a0f66439b..c2fdba47a09 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -1119,29 +1119,28 @@ current buffer. If EVAL-LAST-SEXP-ARG-INTERNAL is `0', print
output with no limit on the length and level of lists, and
include additional formats for integers \(octal, hexadecimal, and
character)."
- (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)))
+ (pcase-let*
+ ((`(,insert-value ,no-truncate ,char-print)
+ (eval-expression-get-print-arguments eval-last-sexp-arg-internal)))
;; Setup the lexical environment if lexical-binding is enabled.
(elisp--eval-last-sexp-print-value
(eval (eval-sexp-add-defvars (elisp--preceding-sexp)) lexical-binding)
- eval-last-sexp-arg-internal)))
-
-(defun elisp--eval-last-sexp-print-value (value &optional eval-last-sexp-arg-internal)
- (let ((unabbreviated (let ((print-length nil) (print-level nil))
- (prin1-to-string value)))
- (print-length (and (not (zerop (prefix-numeric-value
- eval-last-sexp-arg-internal)))
- eval-expression-print-length))
- (print-level (and (not (zerop (prefix-numeric-value
- eval-last-sexp-arg-internal)))
- eval-expression-print-level))
- (beg (point))
- end)
+ (if insert-value (current-buffer) t) no-truncate char-print)))
+
+(defun elisp--eval-last-sexp-print-value
+ (value output &optional no-truncate char-print)
+ (let* ((unabbreviated (let ((print-length nil) (print-level nil))
+ (prin1-to-string value)))
+ (print-length (unless no-truncate eval-expression-print-length))
+ (print-level (unless no-truncate eval-expression-print-level))
+ (beg (point))
+ end)
(prog1
- (prin1 value)
- (let ((str (eval-expression-print-format value)))
- (if str (princ str)))
+ (prin1 value output)
+ (let ((str (and char-print (eval-expression-print-format value))))
+ (if str (princ str output)))
(setq end (point))
- (when (and (bufferp standard-output)
+ (when (and (bufferp output)
(or (not (null print-length))
(not (null print-level)))
(not (string= unabbreviated