aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2020-12-30 11:54:01 +0200
committerJuri Linkov2020-12-30 11:54:01 +0200
commitcd4a51695fddf2a76ae9ed71efa8bfb4a515b32e (patch)
tree0ed215c038a9a0e20232e0944ee58c181f6c281c
parentbaeb82df8bcb8dd7dd783dbfb5561415da4ea3a9 (diff)
downloademacs-cd4a51695fddf2a76ae9ed71efa8bfb4a515b32e.tar.gz
emacs-cd4a51695fddf2a76ae9ed71efa8bfb4a515b32e.zip
Add variables read-char-choice-use-read-key and y-or-n-p-use-read-key
* lisp/subr.el (read-char-choice-use-read-key): New variable. (read-char-choice): Use read-char-from-minibuffer when read-char-choice-use-read-key is nil. (y-or-n-p-use-read-key): New variable. (y-or-n-p): Restore old code that calls read-key to use it when y-or-n-p-use-read-key is non-nil. * lisp/dired-aux.el (dired--no-subst-ask, dired-query): * lisp/files.el (files--ask-user-about-large-file) (hack-local-variables-confirm): * lisp/userlock.el (ask-user-about-supersession-threat): * lisp/wid-edit.el (widget-choose): Revert to use read-char-choice instead of read-char-from-minibuffer. https://lists.gnu.org/archive/html/emacs-devel/2020-12/msg01919.html
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/dired-aux.el4
-rw-r--r--lisp/files.el4
-rw-r--r--lisp/subr.el121
-rw-r--r--lisp/userlock.el2
-rw-r--r--lisp/wid-edit.el2
6 files changed, 94 insertions, 44 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 10a925972f5..765c032dc47 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2020,6 +2020,11 @@ If you bind 'help-form' to a non-nil value while calling these functions,
2020then pressing 'C-h' ('help-char') causes the function to evaluate 'help-form' 2020then pressing 'C-h' ('help-char') causes the function to evaluate 'help-form'
2021and display the result. 2021and display the result.
2022 2022
2023---
2024** New variables 'read-char-choice-use-read-key' and 'y-or-n-p-use-read-key'.
2025When non-nil, then functions 'read-char-choice' and 'y-or-n-p' (respectively)
2026use the function 'read-key' to read a character instead of using the minibuffer.
2027
2023+++ 2028+++
2024** 'set-window-configuration' now takes an optional 'dont-set-frame' 2029** 'set-window-configuration' now takes an optional 'dont-set-frame'
2025parameter which, when non-nil, instructs the function not to select 2030parameter which, when non-nil, instructs the function not to select
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 0f68b470733..f83824a2727 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -145,7 +145,7 @@ substituted, and will be passed through normally to the shell.
145(defun dired--no-subst-ask (char nb-occur details) 145(defun dired--no-subst-ask (char nb-occur details)
146 (let ((hilit-char (propertize (string char) 'face 'warning)) 146 (let ((hilit-char (propertize (string char) 'face 'warning))
147 (choices `(?y ?n ?? ,@(when details '(?^))))) 147 (choices `(?y ?n ?? ,@(when details '(?^)))))
148 (read-char-from-minibuffer 148 (read-char-choice
149 (format-message 149 (format-message
150 (ngettext 150 (ngettext
151 "%d occurrence of `%s' will not be substituted. Proceed? (%s) " 151 "%d occurrence of `%s' will not be substituted. Proceed? (%s) "
@@ -1380,7 +1380,7 @@ return t; if SYM is q or ESC, return nil."
1380 (format " [Type yn!q or %s] " 1380 (format " [Type yn!q or %s] "
1381 (key-description (vector help-char))) 1381 (key-description (vector help-char)))
1382 " [Type y, n, q or !] "))) 1382 " [Type y, n, q or !] ")))
1383 (set sym (setq char (read-char-from-minibuffer prompt char-choices))) 1383 (set sym (setq char (read-char-choice prompt char-choices)))
1384 (if (memq char '(?y ?\s ?!)) t))))) 1384 (if (memq char '(?y ?\s ?!)) t)))))
1385 1385
1386 1386
diff --git a/lisp/files.el b/lisp/files.el
index 70d451cccfa..637aaa130a4 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2141,7 +2141,7 @@ think it does, because \"free\" is pretty hard to define in practice."
2141 ("Yes" . ?y) 2141 ("Yes" . ?y)
2142 ("No" . ?n) 2142 ("No" . ?n)
2143 ("Open literally" . ?l))) 2143 ("Open literally" . ?l)))
2144 (read-char-from-minibuffer 2144 (read-char-choice
2145 (concat prompt " (y)es or (n)o or (l)iterally ") 2145 (concat prompt " (y)es or (n)o or (l)iterally ")
2146 '(?y ?Y ?n ?N ?l ?L))))) 2146 '(?y ?Y ?n ?N ?l ?L)))))
2147 (cond ((memq choice '(?y ?Y)) nil) 2147 (cond ((memq choice '(?y ?Y)) nil)
@@ -3538,7 +3538,7 @@ n -- to ignore the local variables list.")
3538 ", or C-v/M-v to scroll"))) 3538 ", or C-v/M-v to scroll")))
3539 char) 3539 char)
3540 (if offer-save (push ?! exit-chars)) 3540 (if offer-save (push ?! exit-chars))
3541 (setq char (read-char-from-minibuffer prompt exit-chars)) 3541 (setq char (read-char-choice prompt exit-chars))
3542 (when (and offer-save (= char ?!) unsafe-vars) 3542 (when (and offer-save (= char ?!) unsafe-vars)
3543 (customize-push-and-save 'safe-local-variable-values unsafe-vars)) 3543 (customize-push-and-save 'safe-local-variable-values unsafe-vars))
3544 (prog1 (memq char '(?! ?\s ?y)) 3544 (prog1 (memq char '(?! ?\s ?y))
diff --git a/lisp/subr.el b/lisp/subr.el
index 384dbb25cf8..ed0d6978d03 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2626,6 +2626,10 @@ This function is used by the `interactive' code letter `n'."
2626 t))) 2626 t)))
2627 n)) 2627 n))
2628 2628
2629(defvar read-char-choice-use-read-key nil
2630 "Prefer `read-key' when reading a character by `read-char-choice'.
2631Otherwise, use the minibuffer.")
2632
2629(defun read-char-choice (prompt chars &optional inhibit-keyboard-quit) 2633(defun read-char-choice (prompt chars &optional inhibit-keyboard-quit)
2630 "Read and return one of CHARS, prompting for PROMPT. 2634 "Read and return one of CHARS, prompting for PROMPT.
2631Any input that is not one of CHARS is ignored. 2635Any input that is not one of CHARS is ignored.
@@ -2636,44 +2640,46 @@ keyboard-quit events while waiting for a valid input.
2636If you bind the variable `help-form' to a non-nil value 2640If you bind the variable `help-form' to a non-nil value
2637while calling this function, then pressing `help-char' 2641while calling this function, then pressing `help-char'
2638causes it to evaluate `help-form' and display the result." 2642causes it to evaluate `help-form' and display the result."
2639 (unless (consp chars) 2643 (if (not read-char-choice-use-read-key)
2640 (error "Called `read-char-choice' without valid char choices")) 2644 (read-char-from-minibuffer prompt chars)
2641 (let (char done show-help (helpbuf " *Char Help*")) 2645 (unless (consp chars)
2642 (let ((cursor-in-echo-area t) 2646 (error "Called `read-char-choice' without valid char choices"))
2643 (executing-kbd-macro executing-kbd-macro) 2647 (let (char done show-help (helpbuf " *Char Help*"))
2644 (esc-flag nil)) 2648 (let ((cursor-in-echo-area t)
2645 (save-window-excursion ; in case we call help-form-show 2649 (executing-kbd-macro executing-kbd-macro)
2646 (while (not done) 2650 (esc-flag nil))
2647 (unless (get-text-property 0 'face prompt) 2651 (save-window-excursion ; in case we call help-form-show
2648 (setq prompt (propertize prompt 'face 'minibuffer-prompt))) 2652 (while (not done)
2649 (setq char (let ((inhibit-quit inhibit-keyboard-quit)) 2653 (unless (get-text-property 0 'face prompt)
2650 (read-key prompt))) 2654 (setq prompt (propertize prompt 'face 'minibuffer-prompt)))
2651 (and show-help (buffer-live-p (get-buffer helpbuf)) 2655 (setq char (let ((inhibit-quit inhibit-keyboard-quit))
2652 (kill-buffer helpbuf)) 2656 (read-key prompt)))
2653 (cond 2657 (and show-help (buffer-live-p (get-buffer helpbuf))
2654 ((not (numberp char))) 2658 (kill-buffer helpbuf))
2655 ;; If caller has set help-form, that's enough. 2659 (cond
2656 ;; They don't explicitly have to add help-char to chars. 2660 ((not (numberp char)))
2657 ((and help-form 2661 ;; If caller has set help-form, that's enough.
2658 (eq char help-char) 2662 ;; They don't explicitly have to add help-char to chars.
2659 (setq show-help t) 2663 ((and help-form
2660 (help-form-show))) 2664 (eq char help-char)
2661 ((memq char chars) 2665 (setq show-help t)
2662 (setq done t)) 2666 (help-form-show)))
2663 ((and executing-kbd-macro (= char -1)) 2667 ((memq char chars)
2664 ;; read-event returns -1 if we are in a kbd macro and 2668 (setq done t))
2665 ;; there are no more events in the macro. Attempt to 2669 ((and executing-kbd-macro (= char -1))
2666 ;; get an event interactively. 2670 ;; read-event returns -1 if we are in a kbd macro and
2667 (setq executing-kbd-macro nil)) 2671 ;; there are no more events in the macro. Attempt to
2668 ((not inhibit-keyboard-quit) 2672 ;; get an event interactively.
2669 (cond 2673 (setq executing-kbd-macro nil))
2670 ((and (null esc-flag) (eq char ?\e)) 2674 ((not inhibit-keyboard-quit)
2671 (setq esc-flag t)) 2675 (cond
2672 ((memq char '(?\C-g ?\e)) 2676 ((and (null esc-flag) (eq char ?\e))
2673 (keyboard-quit)))))))) 2677 (setq esc-flag t))
2674 ;; Display the question with the answer. But without cursor-in-echo-area. 2678 ((memq char '(?\C-g ?\e))
2675 (message "%s%s" prompt (char-to-string char)) 2679 (keyboard-quit))))))))
2676 char)) 2680 ;; Display the question with the answer. But without cursor-in-echo-area.
2681 (message "%s%s" prompt (char-to-string char))
2682 char)))
2677 2683
2678(defun sit-for (seconds &optional nodisp obsolete) 2684(defun sit-for (seconds &optional nodisp obsolete)
2679 "Redisplay, then wait for SECONDS seconds. Stop when input is available. 2685 "Redisplay, then wait for SECONDS seconds. Stop when input is available.
@@ -2920,6 +2926,10 @@ Also discard all previous input in the minibuffer."
2920 (minibuffer-message "Please answer y or n") 2926 (minibuffer-message "Please answer y or n")
2921 (sit-for 2))) 2927 (sit-for 2)))
2922 2928
2929(defvar y-or-n-p-use-read-key nil
2930 "Prefer `read-key' when answering a \"y or n\" question by `y-or-n-p'.
2931Otherwise, use the minibuffer.")
2932
2923(defvar empty-history) 2933(defvar empty-history)
2924 2934
2925(defun y-or-n-p (prompt) 2935(defun y-or-n-p (prompt)
@@ -2980,6 +2990,41 @@ is nil and `use-dialog-box' is non-nil."
2980 use-dialog-box) 2990 use-dialog-box)
2981 (setq prompt (funcall padded prompt t) 2991 (setq prompt (funcall padded prompt t)
2982 answer (x-popup-dialog t `(,prompt ("Yes" . act) ("No" . skip))))) 2992 answer (x-popup-dialog t `(,prompt ("Yes" . act) ("No" . skip)))))
2993 (y-or-n-p-use-read-key
2994 ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state
2995 ;; where all the keys were unbound (i.e. it somehow got triggered
2996 ;; within read-key, apparently). I had to kill it.
2997 (setq prompt (funcall padded prompt))
2998 (while
2999 (let* ((scroll-actions '(recenter scroll-up scroll-down
3000 scroll-other-window scroll-other-window-down))
3001 (key
3002 (let ((cursor-in-echo-area t))
3003 (when minibuffer-auto-raise
3004 (raise-frame (window-frame (minibuffer-window))))
3005 (read-key (propertize (if (memq answer scroll-actions)
3006 prompt
3007 (concat "Please answer y or n. "
3008 prompt))
3009 'face 'minibuffer-prompt)))))
3010 (setq answer (lookup-key query-replace-map (vector key) t))
3011 (cond
3012 ((memq answer '(skip act)) nil)
3013 ((eq answer 'recenter)
3014 (recenter) t)
3015 ((eq answer 'scroll-up)
3016 (ignore-errors (scroll-up-command)) t)
3017 ((eq answer 'scroll-down)
3018 (ignore-errors (scroll-down-command)) t)
3019 ((eq answer 'scroll-other-window)
3020 (ignore-errors (scroll-other-window)) t)
3021 ((eq answer 'scroll-other-window-down)
3022 (ignore-errors (scroll-other-window-down)) t)
3023 ((or (memq answer '(exit-prefix quit)) (eq key ?\e))
3024 (signal 'quit nil) t)
3025 (t t)))
3026 (ding)
3027 (discard-input)))
2983 (t 3028 (t
2984 (setq prompt (funcall padded prompt)) 3029 (setq prompt (funcall padded prompt))
2985 (let* ((empty-history '()) 3030 (let* ((empty-history '())
diff --git a/lisp/userlock.el b/lisp/userlock.el
index ec763223379..249f40e9af9 100644
--- a/lisp/userlock.el
+++ b/lisp/userlock.el
@@ -159,7 +159,7 @@ really edit the buffer? (y, n, r or C-h) "
159 (message "%s" prompt) 159 (message "%s" prompt)
160 (error "Cannot resolve conflict in batch mode")) 160 (error "Cannot resolve conflict in batch mode"))
161 (while (null answer) 161 (while (null answer)
162 (setq answer (read-char-from-minibuffer prompt choices)) 162 (setq answer (read-char-choice prompt choices))
163 (cond ((memq answer '(?? ?\C-h)) 163 (cond ((memq answer '(?? ?\C-h))
164 (ask-user-about-supersession-help) 164 (ask-user-about-supersession-help)
165 (setq answer nil)) 165 (setq answer nil))
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 8250316bcc7..bb5d26d29e9 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -338,7 +338,7 @@ in the key vector, as in the argument of `define-key'."
338 '(display-buffer-in-direction 338 '(display-buffer-in-direction
339 (direction . bottom) 339 (direction . bottom)
340 (window-height . fit-window-to-buffer))) 340 (window-height . fit-window-to-buffer)))
341 (setq value (read-char-from-minibuffer 341 (setq value (read-char-choice
342 (format "%s: " title) 342 (format "%s: " title)
343 (mapcar #'car alist))))) 343 (mapcar #'car alist)))))
344 (cdr (assoc value alist)))))) 344 (cdr (assoc value alist))))))