emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 53f6218: * lisp/subr.el (read-char-choice-with-read-key): New fun


From: Juri Linkov
Subject: master 53f6218: * lisp/subr.el (read-char-choice-with-read-key): New function.
Date: Sat, 27 Feb 2021 15:01:18 -0500 (EST)

branch: master
commit 53f6218cdc677cda38d23b9049c80ab84e7b4f31
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/subr.el (read-char-choice-with-read-key): New function.
    
    * lisp/subr.el (read-char-choice): Move most of the function body to
    'read-char-choice-with-read-key'.
    (read-char-choice-with-read-key): New function with body from
    'read-char-choice'.
---
 lisp/subr.el | 83 +++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 43 insertions(+), 40 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 2323e5d..0c97c60 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2832,6 +2832,11 @@ This function is used by the `interactive' code letter 
`n'."
 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 @@ keyboard-quit events while waiting for a valid input.
 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 via email to

[Prev in Thread] Current Thread [Next in Thread]