unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 38785@debbugs.gnu.org
Subject: bug#38785: 26.3; `y-or-n-p' leaves prompt and response in echo area
Date: Sat, 28 Dec 2019 14:55:08 -0800 (PST)	[thread overview]
Message-ID: <787722a4-9679-4160-903d-d9de42801ddf@default> (raw)

`y-or-n-p' puts its prompt in the echo area.

[Aside: That is not ideal for a prompt.  Some other interaction might be
better, such as using a pop-up for the prompt.  In any case, `y-or-n-p'
and similar functions should NOT use the minibuffer.  `read-key' should
continue to act without any use of the minibuffer.  IMHO, it would make
zero sense to use the minibuffer to read a key.]

At the end, `y-or-n-p' puts its prompt in the echo area again, followed
by the user's response (`y' or `n'):

 (unless noninteractive (message "%s%c" prompt (if ret ?y ?n)))

This is a bother, and it can confuse users, especially when there are
additional questions that follow the `y-or-n-p' prompting.

For example, consider a `y-or-n-p' followed by a `map-y-or-n-p'.  When
the latter is finished, the prompt from the preceding `y-or-n-p' gets
restored to the echo area.  That makes little sense, and it can be quite
confusing.

`map-y-or-n-p' does not leave any of its prompts in the echo area.  This
is a good thing, not a bad thing.  Instead, as a good citizen, it does
this at the end, to ensure that it hasn't left any of its echo-area
prompts behind, as litter:

 ;; Clear the last prompt from the minibuffer, and restore the
 ;; previous echo-area message, if any.
 (let ((message-log-max nil))
   (if msg (message "%s" msg) (message "")))

Perhaps that, or similar, is what `y-or-n-p' should do.

Presumably the reason that `y-or-n-p' does what it does is to provide
feedback of the char (`y' or `n') that you typed.  It's true that that's
helpful, but it also causes problems (see above).

Perhaps `y-or-n-p' should do what it does now, but then reset the echo
area after a brief delay (e.g. 1 sec), where "reset" means to do what
`map-y-or-n-p' does: restore any previous echo-area content.  IOW, it's
not bad to echo your response to the `y-or-n-p' question.  But it is bad
not to clean up afterward, leaving the echo area littered with the
prompt.

For example, have `y-or-n-p' bind `msg' to `(current-message)' at the
outset, and then do this at the end:

 (let ((ret (eq answer 'act)))
       (unless noninteractive
         (message "%s%c" prompt (if ret ?y ?n))         ; <==== (1)
         (run-with-timer 1 nil
                         (lambda () 
                           (let ((message-log-max nil)) ; <==== (2)
                             (if msg 
                                 (message "%s" msg)
                               (message ""))))))
       ret)

(1) is what `y-or-n-p' does now, to show you your response.
(2) is what `map-y-or-n-p' does, to clean up after itself.

If something similar to this 1-2 punch is not done, and if the only
available choice is for `y-or-n-p' to do what it does now (#1), or
to just clean up after itself (#2), then my vote is for #2.

In GNU Emacs 26.3 (build 1, x86_64-w64-mingw32)
 of 2019-08-29
Repository revision: 96dd0196c28bc36779584e47fffcca433c9309cd
Windowing system distributor `Microsoft Corp.', version 10.0.17763
Configured using:
 `configure --without-dbus --host=x86_64-w64-mingw32
 --without-compress-install 'CFLAGS=-O2 -static -g3''





             reply	other threads:[~2019-12-28 22:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-28 22:55 Drew Adams [this message]
2019-12-28 23:30 ` bug#38785: 26.3; `y-or-n-p' leaves prompt and response in echo area Drew Adams
2019-12-29  8:58   ` Andreas Schwab
2019-12-29 14:06     ` Eli Zaretskii
2019-12-29 14:08     ` Drew Adams
2019-12-29 14:29       ` Andreas Schwab
     [not found] <<787722a4-9679-4160-903d-d9de42801ddf@default>
     [not found] ` <<5561aae8-fa46-4228-833a-912fc49d789e@default>
     [not found]   ` <<87blrrwlsf.fsf@hase.home>
     [not found]     ` <<83blrrns4o.fsf@gnu.org>
2019-12-29 14:14       ` Drew Adams

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=787722a4-9679-4160-903d-d9de42801ddf@default \
    --to=drew.adams@oracle.com \
    --cc=38785@debbugs.gnu.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 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).