From 301202a7963ee377bf0f51f703e0282782c7a6c1 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 25 Mar 2017 23:31:11 -0400 Subject: [PATCH v1] Limit integers printed as characters (Bug#16828) * lisp/simple.el (eval-expression-print-maximum-character): New variable. (eval-expression-print-format): Only display value as character if it's equal or less than `eval-expression-print-maximum-character'. * doc/emacs/building.texi (Lisp Eval): Document it. * etc/NEWS: Announce it. --- doc/emacs/building.texi | 6 +++++- etc/NEWS | 4 ++++ lisp/simple.el | 14 +++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index ba8eae0759..2ee08e2505 100644 --- a/doc/emacs/building.texi +++ b/doc/emacs/building.texi @@ -1485,7 +1485,8 @@ Lisp Eval Emacs Lisp expression preceding point in the buffer, and displays the value in the echo area. When the result of an evaluation is an integer, it is displayed together with the value in other formats -(octal, hexadecimal, and character). +(octal, hexadecimal, and character if +@code{eval-expression-print-maximum-character} allows it). If @kbd{M-:} or @kbd{C-x C-e} is given a prefix argument, it inserts the value into the current buffer at point, rather than displaying it @@ -1524,6 +1525,7 @@ Lisp Eval @vindex eval-expression-print-level @vindex eval-expression-print-length +@vindex eval-expression-print-maximum-character @vindex eval-expression-debug-on-error The options @code{eval-expression-print-level} and @code{eval-expression-print-length} control the maximum depth and @@ -1533,6 +1535,8 @@ Lisp Eval printed in full. @code{eval-expression-debug-on-error} controls whether evaluation errors invoke the debugger when these commands are used; its default is @code{t}. +@code{eval-expression-print-maximum-character} prevents large integers +from being displayed as characters. @node Lisp Interaction @section Lisp Interaction Buffers diff --git a/etc/NEWS b/etc/NEWS index 62d06f3561..c09cc390bb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -334,6 +334,10 @@ always restricting the margin to a quarter of the window. ** Emacsclient has a new option -u/--suppress-output. The option suppresses display of return values from the server process. ++++ +** The new variable 'eval-expression-print-maximum-character' prevents +large integers from being displayed as characters. + * Editing Changes in Emacs 26.1 diff --git a/lisp/simple.el b/lisp/simple.el index 681cf83807..599c7ebf30 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1450,6 +1450,13 @@ eval-expression-debug-on-error :type 'boolean :version "21.1") +(defcustom eval-expression-print-maximum-character 127 + "The largest integer that will be displayed as a character. +This affects printing by `eval-expression-print-format'." + :group 'lisp + :type 'integer + :version "26.1") + (defun eval-expression-print-format (value) "If VALUE in an integer, return a specially formatted string. This string will typically look like \" (#o1, #x1, ?\\C-a)\". @@ -1460,9 +1467,10 @@ eval-expression-print-format (or (eq standard-output t) (zerop (prefix-numeric-value current-prefix-arg)))) (let ((char-string - (if (and (characterp value) - (char-displayable-p value)) - (prin1-char value)))) + (and (characterp value) + (<= value eval-expression-print-maximum-character) + (char-displayable-p value) + (prin1-char value)))) (if char-string (format " (#o%o, #x%x, %s)" value value char-string) (format " (#o%o, #x%x)" value value))))) -- 2.11.1