emacs-diffs
[Top][All Lists]
Advanced

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

master 17894ef: In dired-query use read-char-from-minibuffer with bound


From: Juri Linkov
Subject: master 17894ef: In dired-query use read-char-from-minibuffer with bound help-char (bug#42708)
Date: Wed, 11 Nov 2020 14:22:35 -0500 (EST)

branch: master
commit 17894ef565214c17d19304d9ce6a976c2588fd53
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    In dired-query use read-char-from-minibuffer with bound help-char 
(bug#42708)
    
    * lisp/dired-aux.el (dired-query): Replace read-char-choice call
    with read-char-from-minibuffer.
    
    * lisp/subr.el (read-char-choice): Restore the previous version
    that uses read-key.
    (read-char-from-minibuffer): Bind help-char to help-form-show
    when help-form is non-nil.
---
 etc/NEWS          |  5 +++++
 lisp/dired-aux.el |  2 +-
 lisp/subr.el      | 50 +++++++++++++++++++++++++++++---------------------
 3 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index eb532ce..f21c4cb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1322,6 +1322,11 @@ If 'tab-always-indent' is 'complete', this new user 
option can be used to
 further tweak whether to complete or indent.
 
 ---
+*** 'dired-query' now uses 'read-char-from-minibuffer'.
+Using it instead of 'read-char-choice' allows using 'C-x o'
+to switch to the help window displayed after typing 'C-h'.
+
+---
 *** 'zap-up-to-char' now uses 'read-char-from-minibuffer'.
 This allows navigating through the history of characters that have
 been input.  This is mostly useful for characters that have complex
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 6034d12..94a2bbf 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1380,7 +1380,7 @@ return t; if SYM is q or ESC, return nil."
                             (format " [Type yn!q or %s] "
                                     (key-description (vector help-char)))
                           " [Type y, n, q or !] ")))
-          (set sym (setq char (read-char-choice prompt char-choices)))
+          (set sym (setq char (read-char-from-minibuffer prompt char-choices)))
           (if (memq char '(?y ?\s ?!)) t)))))
 
 
diff --git a/lisp/subr.el b/lisp/subr.el
index 924526d..3e17ef8 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2618,15 +2618,7 @@ keyboard-quit events while waiting for a valid input."
          (unless (get-text-property 0 'face prompt)
            (setq prompt (propertize prompt 'face 'minibuffer-prompt)))
          (setq char (let ((inhibit-quit inhibit-keyboard-quit))
-                      (read-char-from-minibuffer
-                        prompt
-                        ;; If we have a dynamically bound `help-form'
-                        ;; here, then the `C-h' (i.e., `help-char')
-                        ;; character should output that instead of
-                        ;; being a command char.
-                        (if help-form
-                            (cons help-char chars)
-                          chars))))
+                      (read-key prompt)))
          (and show-help (buffer-live-p (get-buffer helpbuf))
               (kill-buffer helpbuf))
          (cond
@@ -2774,20 +2766,36 @@ the function will ignore any input that is not one of 
CHARS.
 Optional argument HISTORY, if non-nil, should be a symbol that
 specifies the history list variable to use for navigating in input
 history using `M-p' and `M-n', with `RET' to select a character from
-history."
+history.
+If the caller has set `help-form', there is no need to explicitly add
+`help-char' to chars.  It's bound automatically to `help-form-show'."
   (let* ((empty-history '())
          (map (if (consp chars)
-                  (or (gethash chars read-char-from-minibuffer-map-hash)
-                      (puthash chars
-                               (let ((map (make-sparse-keymap)))
-                                 (set-keymap-parent map 
read-char-from-minibuffer-map)
-                                 (dolist (char chars)
-                                   (define-key map (vector char)
-                                     'read-char-from-minibuffer-insert-char))
-                                 (define-key map [remap self-insert-command]
-                                   'read-char-from-minibuffer-insert-other)
-                                 map)
-                               read-char-from-minibuffer-map-hash))
+                  (or (and (gethash chars read-char-from-minibuffer-map-hash)
+                           ;; Don't use cached keymap with `help-char'.
+                           (not help-form))
+                      (let ((map (make-sparse-keymap))
+                            (msg help-form))
+                        (set-keymap-parent map read-char-from-minibuffer-map)
+                        ;; If we have a dynamically bound `help-form'
+                        ;; here, then the `C-h' (i.e., `help-char')
+                        ;; character should output that instead of
+                        ;; being a command char.
+                        (when help-form
+                          (define-key map (vector help-char)
+                            (lambda ()
+                              (interactive)
+                              (let ((help-form msg)) ; lexically bound msg
+                                (help-form-show)))))
+                        (dolist (char chars)
+                          (define-key map (vector char)
+                            'read-char-from-minibuffer-insert-char))
+                        (define-key map [remap self-insert-command]
+                          'read-char-from-minibuffer-insert-other)
+                        (unless help-form
+                          ;; Don't cache keymap with `help-char'.
+                          (puthash chars map 
read-char-from-minibuffer-map-hash))
+                        map))
                 read-char-from-minibuffer-map))
          (result
           (read-from-minibuffer prompt nil map nil



reply via email to

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