all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: master 297c0e0: New variable 'use-short-answers' to use 'y-or-n-p' instead of 'yes-or-no-p'
Date: Thu, 25 Feb 2021 21:29:44 +0200	[thread overview]
Message-ID: <87k0qwaqtz.fsf@mail.linkov.net> (raw)
In-Reply-To: <CADwFkm=zxiH5b=ScmpLuLx+GQi+J2Mt-yrO6JYO_E1-Am7xSNA@mail.gmail.com> (Stefan Kangas's message of "Thu, 25 Feb 2021 13:02:29 -0600")

[-- Attachment #1: Type: text/plain, Size: 512 bytes --]

>>     New variable 'use-short-answers' to use 'y-or-n-p' instead of 'yes-or-no-p'
>
> Good idea, thanks.
>
>> +  if (use_short_answers)
>> +    {
>> +      return call1 (intern ("y-or-n-p"), prompt);
>> +    }
>> +
>
> Just a nit: you don't need to wrap single statements in "{ ... }".

Thanks for noticing these extra braces added out of habit of adding parens
in Lisp.  Eli already fixed this mistake immediately.

BTW, what do you think about such purely cosmetic patch?
Are there any aesthetic objections?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: read-char-choice-with-read-key.patch --]
[-- Type: text/x-diff, Size: 4355 bytes --]

diff --git a/lisp/subr.el b/lisp/subr.el
index cc8b85b1d3..4c27b2c685 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2832,6 +2832,11 @@ read-char-choice-use-read-key
 Otherwise, use the minibuffer.")
 
 (defun read-char-choice (prompt chars &optional inhibit-keyboard-quit)
+  (if (not read-char-choice-use-read-key)
+      (read-char-from-minibuffer prompt chars)
+    (read-char-choice-with-read-key prompt chars inhibit-keyboard-quit)))
+
+(defun read-char-choice-with-read-key (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.
 
@@ -2841,46 +2846,44 @@ 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*"))
-      (let ((cursor-in-echo-area t)
-            (executing-kbd-macro executing-kbd-macro)
-            (esc-flag nil))
-        (save-window-excursion        ; in case we call help-form-show
-          (while (not done)
-            (unless (get-text-property 0 'face prompt)
-              (setq prompt (propertize prompt 'face 'minibuffer-prompt)))
-            (setq char (let ((inhibit-quit inhibit-keyboard-quit))
-                         (read-key prompt)))
-            (and show-help (buffer-live-p (get-buffer helpbuf))
-                 (kill-buffer helpbuf))
-            (cond
-             ((not (numberp char)))
-             ;; If caller has set help-form, that's enough.
-             ;; They don't explicitly have to add help-char to chars.
-             ((and help-form
-                   (eq char help-char)
-                   (setq show-help t)
-                   (help-form-show)))
-             ((memq char chars)
-              (setq done t))
-             ((and executing-kbd-macro (= char -1))
-              ;; read-event returns -1 if we are in a kbd macro and
-              ;; there are no more events in the macro.  Attempt to
-              ;; get an event interactively.
-              (setq executing-kbd-macro nil))
-             ((not inhibit-keyboard-quit)
-              (cond
-               ((and (null esc-flag) (eq char ?\e))
-                (setq esc-flag t))
-               ((memq char '(?\C-g ?\e))
-                (keyboard-quit))))))))
-      ;; Display the question with the answer.  But without cursor-in-echo-area.
-      (message "%s%s" prompt (char-to-string char))
-      char)))
+  (unless (consp chars)
+    (error "Called `read-char-choice' without valid char choices"))
+  (let (char done show-help (helpbuf " *Char Help*"))
+    (let ((cursor-in-echo-area t)
+          (executing-kbd-macro executing-kbd-macro)
+	  (esc-flag nil))
+      (save-window-excursion	      ; in case we call help-form-show
+	(while (not done)
+	  (unless (get-text-property 0 'face prompt)
+	    (setq prompt (propertize prompt 'face 'minibuffer-prompt)))
+	  (setq char (let ((inhibit-quit inhibit-keyboard-quit))
+		       (read-key prompt)))
+	  (and show-help (buffer-live-p (get-buffer helpbuf))
+	       (kill-buffer helpbuf))
+	  (cond
+	   ((not (numberp char)))
+	   ;; If caller has set help-form, that's enough.
+	   ;; They don't explicitly have to add help-char to chars.
+	   ((and help-form
+		 (eq char help-char)
+		 (setq show-help t)
+		 (help-form-show)))
+	   ((memq char chars)
+	    (setq done t))
+	   ((and executing-kbd-macro (= char -1))
+	    ;; read-event returns -1 if we are in a kbd macro and
+	    ;; there are no more events in the macro.  Attempt to
+	    ;; get an event interactively.
+	    (setq executing-kbd-macro nil))
+	   ((not inhibit-keyboard-quit)
+	    (cond
+	     ((and (null esc-flag) (eq char ?\e))
+	      (setq esc-flag t))
+	     ((memq char '(?\C-g ?\e))
+	      (keyboard-quit))))))))
+    ;; Display the question with the answer.  But without cursor-in-echo-area.
+    (message "%s%s" prompt (char-to-string char))
+    char))
 
 (defun sit-for (seconds &optional nodisp obsolete)
   "Redisplay, then wait for SECONDS seconds.  Stop when input is available.

      reply	other threads:[~2021-02-25 19:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210225184552.25949.56399@vcs0.savannah.gnu.org>
     [not found] ` <20210225184554.3E85520B2C@vcs0.savannah.gnu.org>
2021-02-25 19:02   ` master 297c0e0: New variable 'use-short-answers' to use 'y-or-n-p' instead of 'yes-or-no-p' Stefan Kangas
2021-02-25 19:29     ` Juri Linkov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k0qwaqtz.fsf@mail.linkov.net \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.