From d9bb55cd0001b2dff34e766bee26db32dbe6e631 Mon Sep 17 00:00:00 2001 From: justbur Date: Thu, 28 Jan 2016 15:39:47 -0500 Subject: [PATCH] Improve previous commit Filter out keys with :suppress-keymap property, which seem to be the primary ones ignored in operator state --- which-key.el | 73 ++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/which-key.el b/which-key.el index 09ab770bdc1..3b8927d05c2 100644 --- a/which-key.el +++ b/which-key.el @@ -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))