From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Deniz Dogan Newsgroups: gmane.emacs.bugs Subject: bug#8948: 24.0.50; y-or-n-p doesn't support scroll-o-w like yes-or-no-p Date: Fri, 01 Jul 2011 11:25:03 +0200 Message-ID: <4E0D926F.1070109@dogan.se> References: <874o3a1s7g.fsf@gmail.com> <8739irxt7f.fsf@gmail.com> <4E0CCED0.20604@dogan.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1309514030 5950 80.91.229.12 (1 Jul 2011 09:53:50 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 1 Jul 2011 09:53:50 +0000 (UTC) To: 8948@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jul 01 11:53:46 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QcaPu-0001N5-7t for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Jul 2011 11:53:42 +0200 Original-Received: from localhost ([::1]:56015 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcaPt-0006wV-E7 for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Jul 2011 05:53:41 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:42326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcZzC-0007is-RT for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2011 05:26:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QcZz9-0006Y6-PR for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2011 05:26:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46994) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcZz9-0006Xj-Ac for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2011 05:26:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QcZz8-0003W9-Im; Fri, 01 Jul 2011 05:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Deniz Dogan Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Jul 2011 09:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8948 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.130951235013501 (code B ref -1); Fri, 01 Jul 2011 09:26:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Jul 2011 09:25:50 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QcZyv-0003Vi-RO for submit@debbugs.gnu.org; Fri, 01 Jul 2011 05:25:50 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QcZyt-0003VW-Oe for submit@debbugs.gnu.org; Fri, 01 Jul 2011 05:25:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QcZym-0006Vm-R1 for submit@debbugs.gnu.org; Fri, 01 Jul 2011 05:25:42 -0400 Original-Received: from lists.gnu.org ([140.186.70.17]:34867) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcZym-0006Vh-D4 for submit@debbugs.gnu.org; Fri, 01 Jul 2011 05:25:40 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:42231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcZyk-0007b4-Ax for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2011 05:25:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QcZyi-0006V8-2o for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2011 05:25:37 -0400 Original-Received: from ch-smtp05.sth.basefarm.net ([80.76.153.6]:41726) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcZyh-0006V0-GE for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2011 05:25:35 -0400 Original-Received: from c80-216-105-155.bredband.comhem.se ([80.216.105.155]:53112 helo=[192.168.0.10]) by ch-smtp05.sth.basefarm.net with esmtp (Exim 4.76) (envelope-from ) id 1QcZyK-00041L-IV for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2011 11:25:14 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: <4E0CCED0.20604@dogan.se> X-Originating-IP: 80.216.105.155 X-Scan-Result: No virus found in message 1QcZyK-00041L-IV. X-Scan-Signature: ch-smtp05.sth.basefarm.net 1QcZyK-00041L-IV 95f31bc6fb81ed9d1c1a13e582106944 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 01 Jul 2011 05:26:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:47683 Archived-At: On 2011-06-30 21:30, Deniz Dogan wrote: > On 2011-06-30 16:57, Thierry Volpiatto wrote: >> Thierry Volpiatto writes: >> >>> Hi, >>> after discussion about bug#8927, i discover that >>> from a yes-or-no-p i can scroll-other-window, but not from a >>> y-or-n-p. >> >> This allow scrolling from a y-or-n-p: >> >> >> #+BEGIN_SRC lisp >> (defun y-or-n-p (prompt) >> "Ask user a \"y or n\" question. Return t if answer is \"y\". >> PROMPT is the string to display to ask the question. It should >> end in a space; `y-or-n-p' adds \"(y or n) \" to it. >> >> No confirmation of the answer is requested; a single character is enough. >> Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses >> the bindings in `query-replace-map'; see the documentation of that >> variable >> for more information. In this case, the useful bindings are `act', >> `skip', >> `recenter', and `quit'.\) >> >> Under a windowing system a dialog box will be used if >> `last-nonmenu-event' >> is nil and `use-dialog-box' is non-nil." >> ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird >> state >> ;; where all the keys were unbound (i.e. it somehow got triggered >> ;; within read-key, apparently). I had to kill it. >> (let ((answer 'recenter)) >> (if (and (display-popup-menus-p) >> (listp last-nonmenu-event) >> use-dialog-box) >> (setq answer >> (x-popup-dialog t `(,prompt ("yes" . act) ("No" . skip)))) >> (setq prompt (concat prompt >> (if (eq ?\s (aref prompt (1- (length prompt)))) >> "" " ") >> "(y or n) ")) >> (while >> (let* ((key >> (let ((cursor-in-echo-area t)) >> (when minibuffer-auto-raise >> (raise-frame (window-frame (minibuffer-window)))) >> (read-key (propertize (if (or (eq answer 'recenter) >> (eq com 'scroll-other-window) >> (eq com 'scroll-other-window-down)) >> prompt >> (concat "Please answer y or n. " >> prompt)) >> 'face 'minibuffer-prompt))))) >> (setq answer (lookup-key query-replace-map (vector key) t)) >> (setq com (lookup-key global-map (vector key) t)) >> (cond >> ((eq com 'scroll-other-window) >> (with-selected-window (minibuffer-window) >> (scroll-other-window 1)) t) >> ((eq com 'scroll-other-window-down) >> (with-selected-window (minibuffer-window) >> (scroll-other-window -1)) t) >> ((memq answer '(skip act)) nil) >> ((eq answer 'recenter) (recenter) t) >> ((memq answer '(exit-prefix quit)) (signal 'quit nil) t) >> (t t))) >> (ding) >> (discard-input))) >> (let ((ret (eq answer 'act))) >> (unless noninteractive >> (message "%s %s" prompt (if ret "y" "n"))) >> ret))) >> >> #+END_SRC >> > > > I'm not so sure that's a suitable solution. What if someone wants yet > another command to work in `y-or-n-p'? > Here is an alternative solution which utilizes the current global map if the answer is not found in query-replace-map. I'm not sure this is suitable either since there is no telling what kind of interactive commands that can mess things up for the user. === modified file 'lisp/subr.el' --- lisp/subr.el 2011-06-21 08:55:22 +0000 +++ lisp/subr.el 2011-07-01 09:23:35 +0000 @@ -2158,15 +2158,16 @@ No confirmation of the answer is requested; a single character is enough. Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses the bindings in `query-replace-map'; see the documentation of that variable -for more information. In this case, the useful bindings are `act', `skip', -`recenter', and `quit'.\) +for more information. If the character is not found within that map, it +looks in the current global map instead.\) Under a windowing system a dialog box will be used if `last-nonmenu-event' is nil and `use-dialog-box' is non-nil." ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state ;; where all the keys were unbound (i.e. it somehow got triggered ;; within read-key, apparently). I had to kill it. - (let ((answer 'recenter)) + (let (answer + (valid-answer t)) (if (and (display-popup-menus-p) (listp last-nonmenu-event) use-dialog-box) @@ -2181,7 +2182,7 @@ (let ((cursor-in-echo-area t)) (when minibuffer-auto-raise (raise-frame (window-frame (minibuffer-window)))) - (read-key (propertize (if (eq answer 'recenter) + (read-key (propertize (if valid-answer prompt (concat "Please answer y or n. " prompt)) @@ -2189,9 +2190,14 @@ (setq answer (lookup-key query-replace-map (vector key) t)) (cond ((memq answer '(skip act)) nil) - ((eq answer 'recenter) (recenter) t) ((memq answer '(exit-prefix quit)) (signal 'quit nil) t) - (t t))) + (t (setq answer (lookup-key (current-global-map) (vector key) t)) + (if (not (commandp answer)) + (progn + (setq valid-answer nil) + t) + (call-interactively answer) + (setq valid-answer t))))) (ding) (discard-input))) (let ((ret (eq answer 'act)))