1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-02-27 02:10:52 -08:00

Add option to show transient maps

Set which-key-show-transient-maps to a non-nil value to use this feature.

When a transient map is active and it is not a hydra, show the keys from the
map.

Fixes #164
This commit is contained in:
Justin Burkett 2017-04-26 20:57:49 -04:00
parent 2e855196c7
commit cd43104579

View file

@ -457,6 +457,15 @@ by `key-description'."
:group 'which-key
:type '(repeat regexp))
(defcustom which-key-show-transient-maps nil
"Show keymaps created by `set-transient-map' when applicable.
More specifically, detect when `overriding-terminal-local-map' is
set (this is the keymap used by `set-transient-map') and display
it."
:group 'which-key
:type 'boolean)
;; Hooks
(defvar which-key-init-buffer-hook '()
"Hook run when which-key buffer is initialized.")
@ -2147,13 +2156,15 @@ is selected interactively by mode in `minor-mode-map-alist'."
(which-key--hide-popup)
(setq unread-command-events (listify-key-sequence key))))))))
(defun which-key--create-buffer-and-show (&optional prefix-keys)
(defun which-key--create-buffer-and-show (&optional prefix-keys from-keymap)
"Fill `which-key--buffer' with key descriptions and reformat.
Finally, show the buffer."
(setq which-key--current-prefix prefix-keys
which-key--last-try-2-loc nil)
(let ((start-time (when which-key--debug (current-time)))
(formatted-keys (which-key--get-formatted-key-bindings))
(formatted-keys (which-key--get-formatted-key-bindings
(when from-keymap
(which-key--get-keymap-bindings from-keymap))))
(prefix-keys (key-description which-key--current-prefix)))
(cond ((= (length formatted-keys) 0)
(message "%s- which-key: There are no keys to show" prefix-keys))
@ -2233,6 +2244,12 @@ Finally, show the buffer."
(when (and which-key-idle-secondary-delay
(not which-key--secondary-timer-active))
(which-key--start-timer which-key-idle-secondary-delay t))))
((and which-key-show-transient-maps
(keymapp overriding-terminal-local-map)
;; basic test for it being a hydra
(not (eq (lookup-key overriding-terminal-local-map "\C-u")
'hydra--universal-argument)))
(which-key--create-buffer-and-show nil overriding-terminal-local-map))
((and which-key-show-operator-state-maps
(bound-and-true-p evil-state)
(eq evil-state 'operator)