From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: rewriting y-or-n-p to use read-char-choice Date: Thu, 10 Mar 2011 12:50:33 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <8739mulshy.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1299783062 1539 80.91.229.12 (10 Mar 2011 18:51:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 10 Mar 2011 18:51:02 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 10 19:50:58 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Pxkws-0007Q3-Cc for ged-emacs-devel@m.gmane.org; Thu, 10 Mar 2011 19:50:58 +0100 Original-Received: from localhost ([127.0.0.1]:39896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pxkwr-0000tV-SF for ged-emacs-devel@m.gmane.org; Thu, 10 Mar 2011 13:50:57 -0500 Original-Received: from [140.186.70.92] (port=35574 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pxkwn-0000tQ-EX for emacs-devel@gnu.org; Thu, 10 Mar 2011 13:50:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pxkwm-0000VW-4j for emacs-devel@gnu.org; Thu, 10 Mar 2011 13:50:53 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:40348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pxkwl-0000VO-VQ for emacs-devel@gnu.org; Thu, 10 Mar 2011 13:50:52 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Pxkwh-0007J2-WE for emacs-devel@gnu.org; Thu, 10 Mar 2011 19:50:48 +0100 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 10 Mar 2011 19:50:47 +0100 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 10 Mar 2011 19:50:47 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 26 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110014 (No Gnus v0.14) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:ymNFlSHB3wk7aXE3W1iIF96IiEQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:137047 Archived-At: 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