all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kelly Dean <kellydeanch@yahoo.com>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: 12985@debbugs.gnu.org
Subject: bug#12985: eval-last-sexp looks broken when executed twice
Date: Tue, 27 Nov 2012 04:41:44 -0800 (PST)	[thread overview]
Message-ID: <1354020104.37554.YahooMailClassic@web141102.mail.bf1.yahoo.com> (raw)
In-Reply-To: <m2lidqysv1.fsf@linux-m68k.org>

> It's not a bug, it's a feature of
> eval-expression-print-format.
Sorry for the mistaken bug report. I should have read the source code, and reported this bug as a documentation deficiency instead, since the help pages for eval-last-sexp and eval-print-last-sexp say nothing about eval-expression-print-format or about behaving differently when called twice.
I propose adding to the doc strings for eval-last-sexp and eval-print-last-sexp, "If the value is an integer, and this command is called twice in succession, then in addition to printing the decimal representation, also print the octal and hex representations and char interpretation of the value."
BTW the doc string for eval-last-sexp says "print value in minibuffer." which should be "print value into echo area."

Also, eval-expression-print-format omits the char if the invoking command name is not eval-last-sexp or eval-print-last-sexp. Why? For example, if I do
M-x eval-expression [ret] 5 [ret]
I only get
5 (#o5, #x5)
I don't see why not simplify it to:

(defun eval-expression-print-format (value)
  "Format VALUE as a result of evaluated expression if invoked twice, invoked as a name other than eval-last-sexp or eval-print-last-sexp, or if in debug mode. Return a formatted string that is displayed in the echo area in addition to the value printed by prin1 in functions which display the result of expression evaluation."
  (if (and (integerp value)
           (or (not (memq this-command '(eval-last-sexp eval-print-last-sexp)))
               (eq this-command last-command)
               (if (boundp 'edebug-active) edebug-active)))
      (let ((char-string (prin1-char value)))
        (if char-string
            (format " (#o%o, #x%x, %s)" value value char-string)
          (format " (#o%o, #x%x)" value value)))))

Even then the design seems wrong. It's designed to avoid producing the string the first time eval-last-sexp or eval-print-last-sexp is called, regardless of whether the result will be displayed in the echo area (in which case I don't see any reason to avoid it) or printed into the buffer (in which case avoiding it is good since the user probably wants just the decimal representation).
And it makes one of my custom functions fail to work the same as eval-last-sexp when intended, which is what brought all this to my attention in the first place:

(defun eval-region-or-last-sexp () "Eval region if active; otherwise, eval last sexp and print value into echo area or, with prefix argument, into current buffer. See `eval-region' and `eval-last-sexp' for details."
 (interactive)
 (if mark-active
  (call-interactively 'eval-region)
  (call-interactively 'eval-last-sexp)))

I can fix my function using (setq this-command 'eval-last-sexp), but that's a kludge.
It seems a better design would be to always include the string, even the first time, when displaying in the echo area, and never include the string when printing into the buffer, regardless of the invoking command name. This is simpler, and it's how eval-expression already works.

Regarding lack of hard word wrap in the doc strings above, it's because I propose
(add-hook 'help-mode-hook (lambda () (toggle-word-wrap 1)))






  reply	other threads:[~2012-11-27 12:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-25  1:52 bug#12985: eval-last-sexp looks broken when executed twice Kelly Dean
2012-11-25  8:44 ` Andreas Schwab
2012-11-27 12:41   ` Kelly Dean [this message]
2013-05-06 19:57     ` Juri Linkov
2013-05-08 21:19       ` Juri Linkov
2013-12-19 21:03     ` Juri Linkov

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

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

  git send-email \
    --in-reply-to=1354020104.37554.YahooMailClassic@web141102.mail.bf1.yahoo.com \
    --to=kellydeanch@yahoo.com \
    --cc=12985@debbugs.gnu.org \
    --cc=schwab@linux-m68k.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.