[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 70d63a8 02/21: Add which-key-show-major-mode
From: |
Justin Burkett |
Subject: |
[elpa] master 70d63a8 02/21: Add which-key-show-major-mode |
Date: |
Mon, 8 Jan 2018 22:46:54 -0500 (EST) |
branch: master
commit 70d63a8babcc783cf0083b0094405d45303ec401
Author: Justin Burkett <address@hidden>
Commit: Justin Burkett <address@hidden>
Add which-key-show-major-mode
This is a new function to discover bindings, including evil ones, in the
keymap
of the current major mode. It should be considered experimental at the
moment.
---
which-key.el | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/which-key.el b/which-key.el
index 0e2c6da..0f5b7d4 100644
--- a/which-key.el
+++ b/which-key.el
@@ -1363,6 +1363,18 @@ which are strings. KEY is of the form produced by
`key-binding'."
(current-local-map) (kbd (which-key--current-key-string (car keydesc))))
(intern (cdr keydesc))))
+(defun which-key--map-binding-p (map keydesc)
+ (or
+ (when (bound-and-true-p evil-state)
+ (eq (which-key--safe-lookup-key
+ map
+ (kbd (which-key--current-key-string
+ (format "<%s-state> %s" evil-state (car keydesc)))))
+ (intern (cdr keydesc))))
+ (eq (which-key--safe-lookup-key
+ map (kbd (which-key--current-key-string (car keydesc))))
+ (intern (cdr keydesc)))))
+
(defun which-key--maybe-get-prefix-title (keys)
"KEYS is a string produced by `key-description'.
A title is possibly returned using
@@ -1615,10 +1627,12 @@ Requires `which-key-compute-remaps' to be non-nil"
(forward-line))
(nreverse bindings)))))
-(defun which-key--get-formatted-key-bindings (&optional bindings)
+(defun which-key--get-formatted-key-bindings (&optional bindings filter)
"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))))
+ (when filter
+ (setq unformatted (cl-remove-if-not filter unformatted)))
(when which-key-sort-order
(setq unformatted
(sort unformatted which-key-sort-order)))
@@ -2023,6 +2037,21 @@ after first page."
(which-key--create-buffer-and-show nil))
;;;###autoload
+(defun which-key-show-major-mode ()
+ "Show top-level bindings in the map of the current major mode.
+
+This function will also detect evil bindings made using
+`evil-define-key' in this map. These bindings will depend on the
+current evil state. "
+ (interactive)
+ (setq which-key--using-top-level t)
+ (let ((map-sym (intern (format "%s-map" major-mode))))
+ (if (and (boundp map-sym) (keymapp (symbol-value map-sym)))
+ (which-key--create-buffer-and-show
+ nil nil (apply-partially #'which-key--map-binding-p (symbol-value
map-sym)))
+ (message "which-key: No map named %s" map-sym))))
+
+;;;###autoload
(defun which-key-undo-key ()
"Undo last keypress and force which-key update."
(interactive)
@@ -2215,7 +2244,7 @@ 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 from-keymap)
+(defun which-key--create-buffer-and-show (&optional prefix-keys from-keymap
filter)
"Fill `which-key--buffer' with key descriptions and reformat.
Finally, show the buffer."
(setq which-key--current-prefix prefix-keys
@@ -2223,7 +2252,8 @@ Finally, show the buffer."
(let ((start-time (when which-key--debug (current-time)))
(formatted-keys (which-key--get-formatted-key-bindings
(when from-keymap
- (which-key--get-keymap-bindings from-keymap))))
+ (which-key--get-keymap-bindings from-keymap))
+ filter))
(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))
- [elpa] master updated (a86cf29 -> 56b0fc8), Justin Burkett, 2018/01/08
- [elpa] master 917d2ba 03/21: Improve echo area note for which-key-show-major-mode, Justin Burkett, 2018/01/08
- [elpa] master 70d63a8 02/21: Add which-key-show-major-mode,
Justin Burkett <=
- [elpa] master 6d2e17c 01/21: Update which-key version for GNU ELPA, Justin Burkett, 2018/01/08
- [elpa] master 6e8df96 04/21: Consolidate use of binding filters, Justin Burkett, 2018/01/08
- [elpa] master 2934852 05/21: Mention which-key-show-major-mode in README, Justin Burkett, 2018/01/08
- [elpa] master 78a2943 08/21: Fix ordering of default replacement-alist, Justin Burkett, 2018/01/08
- [elpa] master 159f0f9 07/21: Add notes about paging commands not working with minibuffer, Justin Burkett, 2018/01/08
- [elpa] master f516b84 09/21: Add which-key-enable-extended-define-key customization option, Justin Burkett, 2018/01/08
- [elpa] master 3ff8f48 10/21: Allow null DEF in which-key--process-define-key-args, Justin Burkett, 2018/01/08
- [elpa] master 555c5c1 13/21: Demote errors in which-key--process-define-key-args, Justin Burkett, 2018/01/08
- [elpa] master 0a212c7 11/21: Fix travis build, Justin Burkett, 2018/01/08
- [elpa] master c7e5f76 18/21: Merge pull request #183 from tarsiiformes/silencio, Justin Burkett, 2018/01/08