aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Burkett2019-12-21 13:47:54 -0500
committerJustin Burkett2019-12-21 13:47:54 -0500
commit8554a9f171d565d13ff5c18d594ae055adcd53f1 (patch)
treecffd463c5c361899cadc7a19e1f2329e31ec344a
parentdcb9820c2decd326465ec3dfc792d30429cec564 (diff)
downloademacs-8554a9f171d565d13ff5c18d594ae055adcd53f1.tar.gz
emacs-8554a9f171d565d13ff5c18d594ae055adcd53f1.zip
Generalize C-h commands to use help-char
help-char defaults to C-h. This removes the assumption that help-char is set to C-h. See #228
-rw-r--r--which-key.el52
1 files changed, 30 insertions, 22 deletions
diff --git a/which-key.el b/which-key.el
index 1a0f5c68f65..f3334e128d9 100644
--- a/which-key.el
+++ b/which-key.el
@@ -407,18 +407,20 @@ prefixes in `which-key-paging-prefixes'"
407;; :type '(repeat symbol)) 407;; :type '(repeat symbol))
408 408
409(defcustom which-key-use-C-h-commands t 409(defcustom which-key-use-C-h-commands t
410 "Use C-h for paging if non-nil. Normally C-h after a prefix 410 "Use C-h (or whatever `help-char' is set to) for paging if
411 calls `describe-prefix-bindings'. This changes that command to 411non-nil. Normally C-h after a prefix calls
412 a which-key paging command when which-key-mode is active." 412`describe-prefix-bindings'. This changes that command to a
413which-key paging command when which-key-mode is active."
413 :group 'which-key 414 :group 'which-key
414 :type 'boolean) 415 :type 'boolean)
415 416
416(defcustom which-key-show-early-on-C-h nil 417(defcustom which-key-show-early-on-C-h nil
417 "Show the which-key buffer before if C-h is pressed in the 418 "Show the which-key buffer before if C-h (or whatever
418middle of a prefix before the which-key buffer would normally be 419`help-char' is set to) is pressed in the middle of a prefix
419triggered through the idle delay. If combined with the following 420before the which-key buffer would normally be triggered through
420settings, which-key will effectively only show when triggered 421the idle delay. If combined with the following settings,
421\"manually\" using C-h. 422which-key will effectively only show when triggered \"manually\"
423using C-h.
422 424
423\(setq `which-key-idle-delay' 10000) 425\(setq `which-key-idle-delay' 10000)
424\(setq `which-key-idle-secondary-delay' 0.05) 426\(setq `which-key-idle-secondary-delay' 0.05)
@@ -435,11 +437,11 @@ Note that `which-key-idle-delay' should be set before turning on
435 437
436(defvar which-key-C-h-map 438(defvar which-key-C-h-map
437 (let ((map (make-sparse-keymap))) 439 (let ((map (make-sparse-keymap)))
438 (dolist (bind '(("\C-a" . which-key-abort) 440 (dolist (bind `(("\C-a" . which-key-abort)
439 ("a" . which-key-abort) 441 ("a" . which-key-abort)
440 ("\C-d" . which-key-toggle-docstrings) 442 ("\C-d" . which-key-toggle-docstrings)
441 ("d" . which-key-toggle-docstrings) 443 ("d" . which-key-toggle-docstrings)
442 ("\C-h" . which-key-show-standard-help) 444 (,(vector help-char) . which-key-show-standard-help)
443 ("h" . which-key-show-standard-help) 445 ("h" . which-key-show-standard-help)
444 ("\C-n" . which-key-show-next-page-cycle) 446 ("\C-n" . which-key-show-next-page-cycle)
445 ("n" . which-key-show-next-page-cycle) 447 ("n" . which-key-show-next-page-cycle)
@@ -2047,7 +2049,9 @@ max-lines max-width avl-lines avl-width (which-key--pages-height result))
2047 (let* ((paging-key (concat prefix-keys " " which-key-paging-key)) 2049 (let* ((paging-key (concat prefix-keys " " which-key-paging-key))
2048 (paging-key-bound (eq 'which-key-C-h-dispatch 2050 (paging-key-bound (eq 'which-key-C-h-dispatch
2049 (key-binding (kbd paging-key)))) 2051 (key-binding (kbd paging-key))))
2050 (key (if paging-key-bound which-key-paging-key "C-h"))) 2052 (key (if paging-key-bound
2053 which-key-paging-key
2054 (key-description (vector help-char)))))
2051 (when which-key-use-C-h-commands 2055 (when which-key-use-C-h-commands
2052 (which-key--propertize (format "[%s paging/help]" key) 2056 (which-key--propertize (format "[%s paging/help]" key)
2053 'face 'which-key-note-face)))) 2057 'face 'which-key-note-face))))
@@ -2094,7 +2098,7 @@ including prefix arguments."
2094 (define-key map (kbd which-key-paging-key) #'which-key-C-h-dispatch) 2098 (define-key map (kbd which-key-paging-key) #'which-key-C-h-dispatch)
2095 (when which-key-use-C-h-commands 2099 (when which-key-use-C-h-commands
2096 ;; Show next page even when C-h is pressed 2100 ;; Show next page even when C-h is pressed
2097 (define-key map (kbd "C-h") #'which-key-C-h-dispatch)) 2101 (define-key map (vector help-char) #'which-key-C-h-dispatch))
2098 map))) 2102 map)))
2099 2103
2100(defun which-key--process-page (pages-obj) 2104(defun which-key--process-page (pages-obj)
@@ -2513,14 +2517,18 @@ is selected interactively by mode in `minor-mode-map-alist'."
2513 (which-key--create-pages bindings nil keymap-name)) 2517 (which-key--create-pages bindings nil keymap-name))
2514 (which-key--show-page))) 2518 (which-key--show-page)))
2515 (unless no-paging 2519 (unless no-paging
2516 (let* ((key (key-description (list (read-key)))) 2520 (let* ((key (read-key))
2517 (next-def (lookup-key keymap (kbd key)))) 2521 (key-desc (key-description (list key)))
2518 (cond ((and which-key-use-C-h-commands (string= "C-h" key)) 2522 (next-def (lookup-key keymap (vector key))))
2523 (cond ((and which-key-use-C-h-commands
2524 (numberp key) (= key help-char))
2519 (which-key-C-h-dispatch)) 2525 (which-key-C-h-dispatch))
2520 ((keymapp next-def) 2526 ((keymapp next-def)
2521 (which-key--hide-popup-ignore-command) 2527 (which-key--hide-popup-ignore-command)
2522 (which-key--show-keymap (concat keymap-name " " key) next-def 2528 (which-key--show-keymap
2523 (cons keymap-name keymap))) 2529 (concat keymap-name " " key-desc)
2530 next-def
2531 (cons keymap-name keymap)))
2524 (t (which-key--hide-popup)))))))) 2532 (t (which-key--hide-popup))))))))
2525 2533
2526(defun which-key--evil-operator-filter (binding) 2534(defun which-key--evil-operator-filter (binding)
@@ -2551,18 +2559,18 @@ is selected interactively by mode in `minor-mode-map-alist'."
2551 formatted-keys 2559 formatted-keys
2552 nil "evil operator/motion keys")) 2560 nil "evil operator/motion keys"))
2553 (which-key--show-page))))) 2561 (which-key--show-page)))))
2554 (let* ((key (key-description (list (read-key))))) 2562 (let* ((key (read-key)))
2555 (when (member key '("f" "F" "t" "T" "`")) 2563 (when (member key '(?f ?F ?t ?T ?`))
2556 ;; these keys trigger commands that read the next char manually 2564 ;; these keys trigger commands that read the next char manually
2557 (setq which-key--inhibit-next-operator-popup t)) 2565 (setq which-key--inhibit-next-operator-popup t))
2558 (cond ((and which-key-use-C-h-commands (string= "C-h" key)) 2566 (cond ((and which-key-use-C-h-commands (numberp key) (= key help-char))
2559 (which-key-C-h-dispatch)) 2567 (which-key-C-h-dispatch))
2560 ((string= key "ESC") 2568 ((and (numberp key) (= key ?\C-\[))
2561 (which-key--hide-popup) 2569 (which-key--hide-popup)
2562 (keyboard-quit)) 2570 (keyboard-quit))
2563 (t 2571 (t
2564 (which-key--hide-popup) 2572 (which-key--hide-popup)
2565 (setq unread-command-events (listify-key-sequence key)))))))) 2573 (setq unread-command-events (vector key))))))))
2566 2574
2567(defun which-key--create-buffer-and-show 2575(defun which-key--create-buffer-and-show
2568 (&optional prefix-keys from-keymap filter prefix-title) 2576 (&optional prefix-keys from-keymap filter prefix-title)