1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-02-26 09:51:31 -08:00

Improve previous commit

Filter out keys with :suppress-keymap property, which seem to be the
primary ones ignored in operator state
This commit is contained in:
justbur 2016-01-28 15:39:47 -05:00
parent 456053cd70
commit d9bb55cd00

View file

@ -1336,18 +1336,19 @@ alists. Returns a list (key separator description)."
(list key-w-face sep-w-face desc-w-face)))
unformatted)))
(defun which-key--get-keymap-bindings (keymap)
(defun which-key--get-keymap-bindings (keymap &optional filter)
"Retrieve top-level bindings from KEYMAP."
(let (bindings)
(map-keymap
(lambda (ev def)
(cl-pushnew
(cons (key-description (list ev))
(cond ((keymapp def) "Prefix Command")
((symbolp def) (copy-sequence (symbol-name def)))
((eq 'lambda (car-safe def)) "lambda")
(t (format "%s" def))))
bindings :test (lambda (a b) (string= (car a) (car b)))))
(unless (and (functionp filter) (funcall filter ev def))
(cl-pushnew
(cons (key-description (list ev))
(cond ((keymapp def) "Prefix Command")
((symbolp def) (copy-sequence (symbol-name def)))
((eq 'lambda (car-safe def)) "lambda")
(t (format "%s" def))))
bindings :test (lambda (a b) (string= (car a) (car b))))))
keymap)
bindings))
@ -1918,26 +1919,36 @@ is selected interactively by mode in `minor-mode-map-alist'."
(cons keymap-name keymap)))
(t (which-key--hide-popup)))))
(defun which-key--show-keymap-no-intercept (keymap-name keymap)
(setq which-key--current-prefix nil
which-key--current-show-keymap-name keymap-name)
(when (keymapp keymap)
(let ((formatted-keys (which-key--get-formatted-key-bindings
(which-key--get-keymap-bindings keymap))))
(cond ((= (length formatted-keys) 0)
(message "which-key: Keymap empty"))
((listp which-key-side-window-location)
(setq which-key--last-try-2-loc
(apply #'which-key--try-2-side-windows
formatted-keys 0 which-key-side-window-location)))
(t (setq which-key--pages-plist
(which-key--create-pages formatted-keys (window-width)))
(which-key--show-page 0)))))
(let* ((key (key-description (list (read-key)))))
(cond ((and which-key-use-C-h-commands (string= "C-h" key))
(which-key-C-h-dispatch))
(t (setq unread-command-events (listify-key-sequence key))
(which-key--hide-popup)))))
(defun which-key--evil-operator-filter (_ev def)
(and (functionp def)
(evil-get-command-property def :suppress-operator)))
(defun which-key--show-evil-operator-keymap ()
(let ((keymap-name "evil operator state keys + motion keys")
(keymap
(make-composed-keymap (list evil-operator-shortcut-map
evil-operator-state-map
evil-motion-state-map))))
(setq which-key--current-prefix nil
which-key--current-show-keymap-name keymap-name)
(when (keymapp keymap)
(let ((formatted-keys (which-key--get-formatted-key-bindings
(which-key--get-keymap-bindings
keymap 'which-key--evil-operator-filter))))
(cond ((= (length formatted-keys) 0)
(message "which-key: Keymap empty"))
((listp which-key-side-window-location)
(setq which-key--last-try-2-loc
(apply #'which-key--try-2-side-windows
formatted-keys 0 which-key-side-window-location)))
(t (setq which-key--pages-plist
(which-key--create-pages formatted-keys (window-width)))
(which-key--show-page 0)))))
(let* ((key (key-description (list (read-key)))))
(cond ((and which-key-use-C-h-commands (string= "C-h" key))
(which-key-C-h-dispatch))
(t (setq unread-command-events (listify-key-sequence key))
(which-key--hide-popup))))))
(defun which-key--create-buffer-and-show (&optional prefix-keys)
"Fill `which-key--buffer' with key descriptions and reformat.
@ -1983,11 +1994,7 @@ Finally, show the buffer."
((and which-key-show-operator-state-maps
(bound-and-true-p evil-state)
(eq evil-state 'operator))
(which-key--show-keymap-no-intercept
"evil operator state keys + motion keys"
(make-composed-keymap (list evil-operator-shortcut-map
evil-operator-state-map
evil-motion-state-map))))
(which-key--show-evil-operator-keymap))
((and which-key--current-page-n
(not which-key--using-top-level)
(not which-key--current-show-keymap-name))