unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* rewriting y-or-n-p to use read-char-choice
@ 2011-03-10 18:50 Ted Zlatanov
  2011-03-10 19:10 ` Edward O'Connor
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ted Zlatanov @ 2011-03-10 18:50 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier asked me to look at rewriting `y-or-n-p' to use
`read-char-choice'.  This looked easy at first but I realized it's not
such a good idea because:

- `y-or-n-p' uses `query-replace-map' which could be modified
  externally.  So it would have to gather the key choices from the key
  map, and even that's not possible because it takes the default, so any
  character can potentially be meaningful.

- `read-char-choice' has special code for keyboard macros which I think
  will break `y-or-n-p'; `y-or-n-p' OTOH calls `discard-input'

- the amount of duplicated code is not much at all

So I think a better way would be to write a
`read-char-choice-from-keymap' function which can be passed
`query-replace-map' or something else AND a prompt and a list of
acceptable return values.

This function then calls `lookup-key' on the keyboard input and returns
a symbolic value.  This function could also build the a/b/c part of the
prompt dynamically based on the acceptable key choices.  But if
`y-or-n-p' is the only consumer for this functionality, it seems
pointless to add it.

Ted




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-03-11  2:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-10 18:50 rewriting y-or-n-p to use read-char-choice Ted Zlatanov
2011-03-10 19:10 ` Edward O'Connor
2011-03-10 19:46   ` Ted Zlatanov
2011-03-10 22:35 ` Drew Adams
2011-03-10 22:54   ` Ted Zlatanov
2011-03-10 23:48     ` Drew Adams
2011-03-11  2:05 ` Stefan Monnier

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).