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

* Re: rewriting y-or-n-p to use read-char-choice
  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-11  2:05 ` Stefan Monnier
  2 siblings, 1 reply; 7+ messages in thread
From: Edward O'Connor @ 2011-03-10 19:10 UTC (permalink / raw)
  To: emacs-devel

Hi,

> 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:
[snip]
> 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.

I don't know if this is at all useful, but I had implemented the
functionality that `read-char-choice' provides a couple of years ago:

http://edward.oconnor.cx/elisp/read-char-spec.el

I've signed papers, so feel free to pilfer anything useful out of there.


Ted



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

* Re: rewriting y-or-n-p to use read-char-choice
  2011-03-10 19:10 ` Edward O'Connor
@ 2011-03-10 19:46   ` Ted Zlatanov
  0 siblings, 0 replies; 7+ messages in thread
From: Ted Zlatanov @ 2011-03-10 19:46 UTC (permalink / raw)
  To: emacs-devel

On Thu, 10 Mar 2011 11:10:06 -0800 "Edward O'Connor" <hober0@gmail.com> wrote: 

EO> Hi,
>> 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:
EO> [snip]
>> 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.

EO> I don't know if this is at all useful, but I had implemented the
EO> functionality that `read-char-choice' provides a couple of years ago:

EO> http://edward.oconnor.cx/elisp/read-char-spec.el

EO> I've signed papers, so feel free to pilfer anything useful out of there.

Thanks.  I think at least the ?? help behavior should be in
`read-char-choice', and appending the mapconcat-ed list of choices is a
nice feature (I did something similar for `auth-source-read-char-choice').

I really think, however, that a keymap is a necessity in this kind of
prompting function.  We want it to be flexible multilingually and we
very rarely actually want the char value of the key pressed.  We usually
want a symbolic return.  It's also nice to accept more than literal
characters.

Ted




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

* RE: rewriting y-or-n-p to use read-char-choice
  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 22:35 ` Drew Adams
  2011-03-10 22:54   ` Ted Zlatanov
  2011-03-11  2:05 ` Stefan Monnier
  2 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2011-03-10 22:35 UTC (permalink / raw)
  To: 'Ted Zlatanov', emacs-devel

> Stefan Monnier asked me to look at rewriting `y-or-n-p' to use
> `read-char-choice'.

Completely missing from your exposition of implementation issues is why.  Why
rewrite `y-or-n-p'?  What advantages are sought/expected?




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

* Re: rewriting y-or-n-p to use read-char-choice
  2011-03-10 22:35 ` Drew Adams
@ 2011-03-10 22:54   ` Ted Zlatanov
  2011-03-10 23:48     ` Drew Adams
  0 siblings, 1 reply; 7+ messages in thread
From: Ted Zlatanov @ 2011-03-10 22:54 UTC (permalink / raw)
  To: emacs-devel

On Thu, 10 Mar 2011 14:35:49 -0800 "Drew Adams" <drew.adams@oracle.com> wrote: 

>> Stefan Monnier asked me to look at rewriting `y-or-n-p' to use
>> `read-char-choice'.

DA> Completely missing from your exposition of implementation issues is why.  Why
DA> rewrite `y-or-n-p'?  What advantages are sought/expected?

See bug #8050.  The original need was, I believe, to reuse code.

Ted




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

* RE: rewriting y-or-n-p to use read-char-choice
  2011-03-10 22:54   ` Ted Zlatanov
@ 2011-03-10 23:48     ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2011-03-10 23:48 UTC (permalink / raw)
  To: 'Ted Zlatanov', emacs-devel

> > Completely missing from your exposition of implementation 
> > issues is why.  Why rewrite `y-or-n-p'?  What advantages
> > are sought/expected?
> 
> See bug #8050.  The original need was, I believe, to reuse code.

I see.  Thanks (anyway).  Might I suggest that next time you briefly describe
the problem you are trying to solve, in the thread where you invite discussion
of possible solutions?  That might help you as well as others.




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

* Re: rewriting y-or-n-p to use read-char-choice
  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 22:35 ` Drew Adams
@ 2011-03-11  2:05 ` Stefan Monnier
  2 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2011-03-11  2:05 UTC (permalink / raw)
  To: Ted Zlatanov; +Cc: emacs-devel

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

Using a keymap sounds good.  It also means that the right way to
implement it is by using read-key-sequence (temporarily overshadowing
all the normal keymaps with the one provided).


        Stefan



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