diff --git a/which-key.el b/which-key.el index 6cc4fd9fc31..16b16c13480 100644 --- a/which-key.el +++ b/which-key.el @@ -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)