unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Cc: emacs@whaite.ca, emacs-devel@gnu.org
Subject: Re: printing most-negative-fixnum fails
Date: Sat, 15 May 2004 11:09:07 +0300	[thread overview]
Message-ID: <87sme2jen0.fsf@mail.jurta.org> (raw)
In-Reply-To: <E1BOYrx-0008NG-1a@fencepost.gnu.org> (Richard Stallman's message of "Fri, 14 May 2004 05:20:41 -0400")

Richard Stallman <rms@gnu.org> writes:
> However, adding an option is a very undesirable way to solve such a
> problem.  It is costly in complexity and will leave many users
> unsatisfied.

Instead of adding an option, I propose to add a new function
to format values of evaluated expressions.  This function
will return a formatted string based on the result of evaluation.

Another reason for having a special formatting function is that the
same formatting is used in three places: eval-last-sexp (C-x C-e),
eval-expression (M-:) and edebug.

Currently, by default it prints a character, until the problem with
printing characters will be resolved.  But at least with a separate
formatting function users can easily change the default format by
redefining this function.

Index: emacs/lisp/simple.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/simple.el,v
retrieving revision 1.642
diff -u -r1.642 simple.el
--- emacs/lisp/simple.el	7 May 2004 22:31:54 -0000	1.642
+++ emacs/lisp/simple.el	15 May 2004 07:15:29 -0000
@@ -772,6 +819,21 @@
   :type 'boolean
   :version "21.1")
 
+(defun eval-expression-display-format (value)
+  "Default function to format values of evaluated expressions.
+Return a formatted string which is displayed in the echo area
+in addition to the value printed by prin1 in functions that
+display results of expression evaluation."
+  (if (integerp value)
+      (let ((char-string (prin1-char value)))
+        (if char-string
+            (format " (0%o, 0x%x) = %s" value value char-string)
+          (format " (0%o, 0x%x)" value value)))))
+
 ;; We define this, rather than making `eval' interactive,
 ;; for the sake of completion of names like eval-region, eval-current-buffer.
 (defun eval-expression (eval-expression-arg
@@ -806,7 +868,10 @@
 	(with-no-warnings
 	 (let ((standard-output (current-buffer)))
 	   (eval-last-sexp-print-value (car values))))
-      (prin1 (car values) t))))
+      (prog1
+          (prin1 (car values) t)
+        (let ((str (eval-expression-display-format (car values))))
+          (if str (princ str t)))))))
 
 (defun edit-and-eval-command (prompt command)
   "Prompting with PROMPT, let user edit COMMAND and eval result.

Index: emacs/lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.156
diff -u -r1.156 lisp-mode.el
--- emacs/lisp/emacs-lisp/lisp-mode.el	11 May 2004 03:17:59 -0000	1.156
+++ emacs/lisp/emacs-lisp/lisp-mode.el	15 May 2004 07:15:26 -0000
@@ -524,13 +526,13 @@
 			 (prin1-to-string value)))
 	(print-length eval-expression-print-length)
 	(print-level eval-expression-print-level)
-	(char-string (prin1-char value))
 	(beg (point))
 	end)
     (prog1
 	(prin1 value)
-      (if (and (eq standard-output t) char-string)
-	  (princ (concat " = " char-string)))
+      (if (eq standard-output t)
+          (let ((str (eval-expression-display-format value)))
+            (if str (princ str))))
       (setq end (point))
       (when (and (bufferp standard-output)
 		 (or (not (null print-length))

Index: emacs/lisp/emacs-lisp/edebug.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/edebug.el,v
retrieving revision 3.67
diff -u -r3.67 edebug.el
--- emacs/lisp/emacs-lisp/edebug.el	22 Mar 2004 15:27:46 -0000	3.67
+++ emacs/lisp/emacs-lisp/edebug.el	15 May 2004 07:15:29 -0000
@@ -3692,8 +3692,7 @@
   (setq edebug-previous-result
 	(concat "Result: "
 		(edebug-safe-prin1-to-string edebug-previous-value)
-		(let ((name (prin1-char edebug-previous-value)))
-		  (if name (concat " = " name))))))
+                (eval-expression-display-format edebug-previous-value))))
 
 (defun edebug-previous-result ()
   "Print the previous result."

-- 
Juri Linkov
http://www.jurta.org/emacs/

  parent reply	other threads:[~2004-05-15  8:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-06 20:08 printing most-negative-fixnum fails Peter Whaite
2004-05-11  0:17 ` Juri Linkov
2004-05-11  3:20   ` Stefan Monnier
2004-05-11 16:57     ` Juri Linkov
2004-05-12 19:41       ` Richard Stallman
2004-05-11 12:23   ` Richard Stallman
2004-05-11 16:47     ` Juri Linkov
2004-05-14  9:20       ` Richard Stallman
2004-05-14 11:46         ` Kenichi Handa
2004-05-15  8:17           ` Juri Linkov
2004-05-15  8:53           ` Richard Stallman
2004-05-15  9:19             ` David Kastrup
2004-05-15 20:03             ` Juri Linkov
2004-05-18 13:03               ` Kenichi Handa
2004-05-19  8:36           ` Juri Linkov
2004-05-15  8:09         ` Juri Linkov [this message]
2004-05-15 18:34           ` Richard Stallman
2004-05-15 19:32             ` Juri Linkov
2004-05-12  1:41     ` Kenichi Handa
2004-05-12  2:06       ` Stefan Monnier
2004-05-12  4:43         ` Kenichi Handa
2004-05-11  2:48 ` Stefan Monnier
2004-05-11  3:11   ` Luc Teirlinck
2004-05-11  4:26     ` Kenichi Handa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sme2jen0.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=emacs@whaite.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).