From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Confused by y-or-n-p Date: Mon, 28 Dec 2020 19:06:32 +0200 Organization: LINKOV.NET Message-ID: <87y2hhri3n.fsf@mail.linkov.net> References: <834kkcr1eo.fsf@gnu.org> <43b24209-fa65-0e26-7cbd-f99175a7ffd8@gmx.at> <87wnx7j5is.fsf@mail.linkov.net> <83im8qnyca.fsf@gnu.org> <83bleinmse.fsf@gnu.org> <56435592-d2d0-5fb6-977f-01e1931da835@gmx.at> <87k0t38g1z.fsf@mail.linkov.net> <83czyvkts6.fsf@gnu.org> <87bleetirr.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17559"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: rudalics@gmx.at, rms@gnu.org, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 28 18:24:13 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ktwFf-0004QN-Bo for ged-emacs-devel@m.gmane-mx.org; Mon, 28 Dec 2020 18:24:11 +0100 Original-Received: from localhost ([::1]:52742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktwFe-0006PH-Ek for ged-emacs-devel@m.gmane-mx.org; Mon, 28 Dec 2020 12:24:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktwDZ-0004dX-JW for emacs-devel@gnu.org; Mon, 28 Dec 2020 12:22:01 -0500 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:36213) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktwDW-00085n-TB; Mon, 28 Dec 2020 12:22:01 -0500 X-Originating-IP: 91.129.99.98 Original-Received: from mail.gandi.net (m91-129-99-98.cust.tele2.ee [91.129.99.98]) (Authenticated sender: juri@linkov.net) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 0B65920002; Mon, 28 Dec 2020 17:21:50 +0000 (UTC) In-Reply-To: (Eli Zaretskii's message of "Mon, 28 Dec 2020 11:36:09 +0200") Received-SPF: pass client-ip=217.70.183.200; envelope-from=juri@linkov.net; helo=relay7-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:262019 Archived-At: --=-=-= Content-Type: text/plain >> > Could you please make such a change? >> >> Martin suggested to add the "use the old implementation" option >> to Emacs 27.2. Is it OK with you? > > Yes, thanks. Here is the first version of the patch for master. If generally it's OK, then it could be backported to Emacs 27.2: --=-=-= Content-Type: text/x-diff; charset=iso-8859-1 Content-Disposition: inline; filename=use-read-key.patch Content-Transfer-Encoding: 8bit diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 0f68b47073..f83824a272 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -145,7 +145,7 @@ dired--no-subst-explain (defun dired--no-subst-ask (char nb-occur details) (let ((hilit-char (propertize (string char) 'face 'warning)) (choices `(?y ?n ?? ,@(when details '(?^))))) - (read-char-from-minibuffer + (read-char-choice (format-message (ngettext "%d occurrence of `%s' will not be substituted. Proceed? (%s) " @@ -1380,7 +1380,7 @@ dired-query (format " [Type yn!q or %s] " (key-description (vector help-char))) " [Type y, n, q or !] "))) - (set sym (setq char (read-char-from-minibuffer prompt char-choices))) + (set sym (setq char (read-char-choice prompt char-choices))) (if (memq char '(?y ?\s ?!)) t))))) diff --git a/lisp/files.el b/lisp/files.el index 70d451cccf..637aaa130a 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2141,7 +2141,7 @@ files--ask-user-about-large-file ("Yes" . ?y) ("No" . ?n) ("Open literally" . ?l))) - (read-char-from-minibuffer + (read-char-choice (concat prompt " (y)es or (n)o or (l)iterally ") '(?y ?Y ?n ?N ?l ?L))))) (cond ((memq choice '(?y ?Y)) nil) @@ -3538,7 +3538,7 @@ hack-local-variables-confirm ", or C-v/M-v to scroll"))) char) (if offer-save (push ?! exit-chars)) - (setq char (read-char-from-minibuffer prompt exit-chars)) + (setq char (read-char-choice prompt exit-chars)) (when (and offer-save (= char ?!) unsafe-vars) (customize-push-and-save 'safe-local-variable-values unsafe-vars)) (prog1 (memq char '(?! ?\s ?y)) diff --git a/lisp/subr.el b/lisp/subr.el index 384dbb25cf..592c633a35 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2626,6 +2626,10 @@ read-number t))) n)) +(defvar read-char-choice-use-read-key nil + "Prefer `read-key' when reading a character by `read-char-choice'. +Otherwise, use the minibuffer.") + (defun read-char-choice (prompt chars &optional inhibit-keyboard-quit) "Read and return one of CHARS, prompting for PROMPT. Any input that is not one of CHARS is ignored. @@ -2636,6 +2640,8 @@ read-char-choice If you bind the variable `help-form' to a non-nil value while calling this function, then pressing `help-char' causes it to evaluate `help-form' and display the result." + (if (not read-char-choice-use-read-key) + (read-char-from-minibuffer prompt chars) (unless (consp chars) (error "Called `read-char-choice' without valid char choices")) (let (char done show-help (helpbuf " *Char Help*")) @@ -2673,7 +2679,7 @@ read-char-choice (keyboard-quit)))))))) ;; Display the question with the answer. But without cursor-in-echo-area. (message "%s%s" prompt (char-to-string char)) - char)) + char))) (defun sit-for (seconds &optional nodisp obsolete) "Redisplay, then wait for SECONDS seconds. Stop when input is available. @@ -2920,6 +2926,10 @@ y-or-n-p-insert-other (minibuffer-message "Please answer y or n") (sit-for 2))) +(defvar y-or-n-p-use-read-key nil + "Prefer `read-key' when answering a \"y or n\" question by `y-or-n-p'. +Otherwise, use the minibuffer.") + (defvar empty-history) (defun y-or-n-p (prompt) @@ -2980,6 +2990,41 @@ y-or-n-p use-dialog-box) (setq prompt (funcall padded prompt t) answer (x-popup-dialog t `(,prompt ("Yes" . act) ("No" . skip))))) + (y-or-n-p-use-read-key + ;; Ħ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. + (setq prompt (funcall padded prompt)) + (while + (let* ((scroll-actions '(recenter scroll-up scroll-down + scroll-other-window scroll-other-window-down)) + (key + (let ((cursor-in-echo-area t)) + (when minibuffer-auto-raise + (raise-frame (window-frame (minibuffer-window)))) + (read-key (propertize (if (memq answer scroll-actions) + prompt + (concat "Please answer y or n. " + prompt)) + 'face 'minibuffer-prompt))))) + (setq answer (lookup-key query-replace-map (vector key) t)) + (cond + ((memq answer '(skip act)) nil) + ((eq answer 'recenter) + (recenter) t) + ((eq answer 'scroll-up) + (ignore-errors (scroll-up-command)) t) + ((eq answer 'scroll-down) + (ignore-errors (scroll-down-command)) t) + ((eq answer 'scroll-other-window) + (ignore-errors (scroll-other-window)) t) + ((eq answer 'scroll-other-window-down) + (ignore-errors (scroll-other-window-down)) t) + ((or (memq answer '(exit-prefix quit)) (eq key ?\e)) + (signal 'quit nil) t) + (t t))) + (ding) + (discard-input))) (t (setq prompt (funcall padded prompt)) (let* ((empty-history '()) diff --git a/lisp/userlock.el b/lisp/userlock.el index ec76322337..249f40e9af 100644 --- a/lisp/userlock.el +++ b/lisp/userlock.el @@ -159,7 +159,7 @@ ask-user-about-supersession-threat (message "%s" prompt) (error "Cannot resolve conflict in batch mode")) (while (null answer) - (setq answer (read-char-from-minibuffer prompt choices)) + (setq answer (read-char-choice prompt choices)) (cond ((memq answer '(?? ?\C-h)) (ask-user-about-supersession-help) (setq answer nil)) diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index 8250316bcc..bb5d26d29e 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -338,7 +338,7 @@ widget-choose '(display-buffer-in-direction (direction . bottom) (window-height . fit-window-to-buffer))) - (setq value (read-char-from-minibuffer + (setq value (read-char-choice (format "%s: " title) (mapcar #'car alist))))) (cdr (assoc value alist)))))) --=-=-=--