unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: master 297c0e0: New variable 'use-short-answers' to use 'y-or-n-p' instead of 'yes-or-no-p'
       [not found] ` <20210225184554.3E85520B2C@vcs0.savannah.gnu.org>
@ 2021-02-25 19:02   ` Stefan Kangas
  2021-02-25 19:29     ` Juri Linkov
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Kangas @ 2021-02-25 19:02 UTC (permalink / raw)
  To: Juri Linkov, emacs-devel

juri@jurta.org (Juri Linkov) writes:

> branch: master
> commit 297c0e0306f111c1e7564b2bb49a7e1a925a55bb
> Author: Juri Linkov <juri@linkov.net>
> Commit: Juri Linkov <juri@linkov.net>
>
>     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 "{ ... }".



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

* Re: master 297c0e0: New variable 'use-short-answers' to use 'y-or-n-p' instead of 'yes-or-no-p'
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Juri Linkov @ 2021-02-25 19:29 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: emacs-devel

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

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

end of thread, other threads:[~2021-02-25 19:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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

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