aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjustbur2016-07-05 08:58:40 -0400
committerjustbur2016-07-05 08:58:40 -0400
commitadfcd0e73b6950bccf52d3c2f5b57e4a498fbfc3 (patch)
tree0b6a9e19958a46debaf3dafef3f3d34d3f271954
parent9184b1bcbf316e8d619d72ae140efa48c5e6595d (diff)
downloademacs-adfcd0e73b6950bccf52d3c2f5b57e4a498fbfc3.tar.gz
emacs-adfcd0e73b6950bccf52d3c2f5b57e4a498fbfc3.zip
Add whitelist and blacklist options
which-key-allow-regexps is a list of regexps that allow the popup when one is matched which-key-inhibit-regexps inhibits the popup when one regexp matches The string matched against is the current key sequence as produced by key-description. Fixes #129
-rw-r--r--which-key.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/which-key.el b/which-key.el
index 12c798727b4..324778841a7 100644
--- a/which-key.el
+++ b/which-key.el
@@ -356,6 +356,23 @@ The delay time is effectively added to the normal
356 :group 'which-key 356 :group 'which-key
357 :type '(repeat function)) 357 :type '(repeat function))
358 358
359(defcustom which-key-allow-regexps nil
360 "A list of regexp strings to use to filter key sequences. When
361non-nil, for a key sequence to trigger the which-key popup it
362must match one of the regexps in this list. The format of the key
363sequences is what is produced by `key-description'."
364 :group 'which-key
365 :type '(repeat regexp))
366
367(defcustom which-key-inhibit-regexps nil
368 "Similar to `which-key-allow-regexps', a list of regexp strings
369to use to filter key sequences. When non-nil, for a key sequence
370to trigger the which-key popup it cannot match one of the regexps
371in this list. The format of the key sequences is what is produced
372by `key-description'."
373 :group 'which-key
374 :type '(repeat regexp))
375
359;; Hooks 376;; Hooks
360(defvar which-key-init-buffer-hook '() 377(defvar which-key-init-buffer-hook '()
361 "Hook run when which-key buffer is initialized.") 378 "Hook run when which-key buffer is initialized.")
@@ -1926,6 +1943,14 @@ prefix) if `which-key-use-C-h-commands' is non nil."
1926;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1943;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1927;; Update 1944;; Update
1928 1945
1946(defun which-key--any-match-p (regexps string)
1947 "Non-nil if any of REGEXPS match STRING."
1948 (let (match)
1949 (dolist (regexp regexps)
1950 (when (string-match-p regexp string)
1951 (setq match t)))
1952 match))
1953
1929(defun which-key--try-2-side-windows (keys page-n loc1 loc2 &rest _ignore) 1954(defun which-key--try-2-side-windows (keys page-n loc1 loc2 &rest _ignore)
1930 "Try to show KEYS (PAGE-N) in LOC1 first. Only if no keys fit fallback to LOC2." 1955 "Try to show KEYS (PAGE-N) in LOC1 first. Only if no keys fit fallback to LOC2."
1931 (let (pages1) 1956 (let (pages1)
@@ -2101,6 +2126,13 @@ Finally, show the buffer."
2101 (keymapp (which-key--safe-lookup-key 2126 (keymapp (which-key--safe-lookup-key
2102 function-key-map prefix-keys))) 2127 function-key-map prefix-keys)))
2103 (not which-key-inhibit) 2128 (not which-key-inhibit)
2129 (or (null which-key-allow-regexps)
2130 (which-key--any-match-p
2131 which-key-allow-regexps (key-description prefix-keys)))
2132 (or (null which-key-inhibit-regexps)
2133 (not
2134 (which-key--any-match-p
2135 which-key-allow-regexps (key-description prefix-keys))))
2104 ;; Do not display the popup if a command is currently being 2136 ;; Do not display the popup if a command is currently being
2105 ;; executed 2137 ;; executed
2106 (or (and which-key-allow-evil-operators 2138 (or (and which-key-allow-evil-operators