[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 506c348 10/39: Add which-key-show-full-keymap
From: |
Justin Burkett |
Subject: |
[elpa] master 506c348 10/39: Add which-key-show-full-keymap |
Date: |
Thu, 21 Jun 2018 15:48:13 -0400 (EDT) |
branch: master
commit 506c34829c6c2211046693c7482d4caa8b1a227f
Author: Justin Burkett <address@hidden>
Commit: Justin Burkett <address@hidden>
Add which-key-show-full-keymap
Command to show all bindings in a keymap recursively.
Add test for new which-key--get-keymap-bindings functionality.
---
which-key-tests.el | 23 +++++++++++++++++++++++
which-key.el | 45 +++++++++++++++++++++++++++++++--------------
2 files changed, 54 insertions(+), 14 deletions(-)
diff --git a/which-key-tests.el b/which-key-tests.el
index 5c17ab7..3e75d6f 100644
--- a/which-key-tests.el
+++ b/which-key-tests.el
@@ -122,5 +122,28 @@
(should (equal (which-key--extract-key "<left> a .. c") "a .. c"))
(should (equal (which-key--extract-key "M-a a .. c") "a .. c")))
+(ert-deftest which-key-test--get-keymap-bindings ()
+ (let ((map (make-sparse-keymap))
+ which-key-replacement-alist)
+ (define-key map [which-key-a] '(which-key "blah"))
+ (define-key map "b" 'ignore)
+ (define-key map "c" "c")
+ (define-key map "dd" "dd")
+ (define-key map "eee" "eee")
+ (should (equal
+ (sort (which-key--get-keymap-bindings map)
+ (lambda (a b) (string-lessp (car a) (car b))))
+ '(("b" . "ignore")
+ ("c" . "c")
+ ("d" . "Prefix Command")
+ ("e" . "Prefix Command"))))
+ (should (equal
+ (sort (which-key--get-keymap-bindings map t)
+ (lambda (a b) (string-lessp (car a) (car b))))
+ '(("b" . "ignore")
+ ("c" . "c")
+ ("d d" . "dd")
+ ("e e e" . "eee"))))))
+
(provide 'which-key-tests)
;;; which-key-tests.el ends here
diff --git a/which-key.el b/which-key.el
index 68c5d0e..ab25ac9 100644
--- a/which-key.el
+++ b/which-key.el
@@ -1615,7 +1615,7 @@ return the docstring."
(t
(format "%s %s" current docstring)))))
-(defun which-key--format-and-replace (unformatted)
+(defun which-key--format-and-replace (unformatted &optional preserve-full-key)
"Take a list of (key . desc) cons cells in UNFORMATTED, add
faces and perform replacements according to the three replacement
alists. Returns a list (key separator description)."
@@ -1645,24 +1645,34 @@ alists. Returns a list (key separator description)."
(when (consp key-binding)
(push
(list (which-key--propertize-key
- (which-key--extract-key (car key-binding)))
+ (if preserve-full-key
+ (car key-binding)
+ (which-key--extract-key (car key-binding))))
sep-w-face
final-desc)
new-list))))
(nreverse new-list)))
-(defun which-key--get-keymap-bindings (keymap)
+(defun which-key--get-keymap-bindings (keymap &optional all prefix)
"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)))))
+ (let ((key (if prefix
+ (concat prefix " " (key-description (list ev)))
+ (key-description (list ev)))))
+ (unless (string-match-p which-key--ignore-keys-regexp key)
+ (if (and all (keymapp def))
+ (setq bindings
+ (append bindings (which-key--get-keymap-bindings def t
key)))
+ (cl-pushnew
+ (cons key
+ (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))
@@ -1748,7 +1758,7 @@ Requires `which-key-compute-remaps' to be non-nil"
(forward-line))
(nreverse bindings)))))
-(defun which-key--get-formatted-key-bindings (&optional bindings filter)
+(defun which-key--get-formatted-key-bindings (&optional bindings filter
preserve-full-key)
"Uses `describe-buffer-bindings' to collect the key bindings in
BUFFER that follow the key sequence KEY-SEQ."
(let* ((unformatted (if bindings bindings
(which-key--get-current-bindings))))
@@ -1757,7 +1767,7 @@ BUFFER that follow the key sequence KEY-SEQ."
(when which-key-sort-order
(setq unformatted
(sort unformatted which-key-sort-order)))
- (which-key--format-and-replace unformatted)))
+ (which-key--format-and-replace unformatted preserve-full-key)))
;;; Functions for laying out which-key buffer pages
@@ -2296,6 +2306,12 @@ is selected interactively from all available keymaps."
(interactive)
(which-key-show-keymap-1))
+(defun which-key-show-full-keymap ()
+ "Show all bindings in KEYMAP using which-key. KEYMAP is
+selected interactively from all available keymaps."
+ (interactive)
+ (which-key-show-keymap-1 t))
+
(defun which-key-show-minor-mode-keymap ()
"Show the top-level bindings in KEYMAP using which-key. KEYMAP
is selected interactively by mode in `minor-mode-map-alist'."
@@ -2314,14 +2330,15 @@ is selected interactively by mode in
`minor-mode-map-alist'."
(which-key--show-keymap (symbol-name mode-sym)
(cdr (assq mode-sym minor-mode-map-alist)))))
-(defun which-key--show-keymap (keymap-name keymap &optional prior-args)
+(defun which-key--show-keymap (keymap-name keymap &optional prior-args all)
(setq which-key--current-prefix nil
which-key--current-show-keymap-name keymap-name
which-key--using-show-keymap t)
(when prior-args (push prior-args which-key--prior-show-keymap-args))
(when (keymapp keymap)
(let ((formatted-keys (which-key--get-formatted-key-bindings
- (which-key--get-keymap-bindings keymap))))
+ (which-key--get-keymap-bindings keymap all)
+ nil all)))
(cond ((= (length formatted-keys) 0)
(message "which-key: Keymap empty"))
((listp which-key-side-window-location)
- [elpa] master ca991b0 11/39: Autoload the show keymap functions, (continued)
- [elpa] master ca991b0 11/39: Autoload the show keymap functions, Justin Burkett, 2018/06/21
- [elpa] master fd714bc 13/39: Fix docstring of which-key--get-keymap-bindings, Justin Burkett, 2018/06/21
- [elpa] master b5f7063 15/39: Detect menu-items in which-key--get-keymap-bindings, Justin Burkett, 2018/06/21
- [elpa] master 5493d22 05/39: Fix description truncation when showing docstrings, Justin Burkett, 2018/06/21
- [elpa] master 2e53187 14/39: Fix typo in previous commit, Justin Burkett, 2018/06/21
- [elpa] master 7da9f8c 16/39: Fix which-key--show-keymap when no bidnings found, Justin Burkett, 2018/06/21
- [elpa] master 3c05294 26/39: Fix which-key--create-pages, Justin Burkett, 2018/06/21
- [elpa] master adc0d66 06/39: Use safe version of propertize, Justin Burkett, 2018/06/21
- [elpa] master 0f80d0f 17/39: Use symbol at point in whow keymap functions, Justin Burkett, 2018/06/21
- [elpa] master 61e399f 22/39: Add and use which-key--automatic-display, Justin Burkett, 2018/06/21
- [elpa] master 506c348 10/39: Add which-key-show-full-keymap,
Justin Burkett <=
- [elpa] master d19fe4e 30/39: Fix switching to top-level from which-key-undo-key, Justin Burkett, 2018/06/21
- [elpa] master 9dc8d32 20/39: Add which-key-toggle-docstrings, Justin Burkett, 2018/06/21
- [elpa] master 206be7a 33/39: Fix behavior of f and t in evil operator map, Justin Burkett, 2018/06/21
- [elpa] master e97253b 24/39: Add prefix arg to which-key--get-current-bindings and .., Justin Burkett, 2018/06/21
- [elpa] master ded908e 25/39: Remove which-key--current-prefix, Justin Burkett, 2018/06/21
- [elpa] master 013681a 28/39: Fixes related to removal of which-key--current-prefix, Justin Burkett, 2018/06/21
- [elpa] master ff79dff 38/39: Version 3.3.0, Justin Burkett, 2018/06/21
- [elpa] master 4042f06 34/39: Fix prefix bindings in which-key-show-major-mode, Justin Burkett, 2018/06/21
- [elpa] master 0dc4e84 36/39: Use window-size-change-functions for detecting size changes, Justin Burkett, 2018/06/21
- [elpa] master ab60391 21/39: Use cl-struct to hold which-key pages, Justin Burkett, 2018/06/21