[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
rewriting y-or-n-p to use read-char-choice
From: |
Ted Zlatanov |
Subject: |
rewriting y-or-n-p to use read-char-choice |
Date: |
Thu, 10 Mar 2011 12:50:33 -0600 |
User-agent: |
Gnus/5.110014 (No Gnus v0.14) Emacs/24.0.50 (gnu/linux) |
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
- rewriting y-or-n-p to use read-char-choice,
Ted Zlatanov <=