Improve evil-collection-describe-all-bindings
Add state information. To do this, change the format of evil-collection--bindings-record so that bindings for each map are stored in a list of the form ((STATE KEY BINDING)). Sort output on state then key.
This commit is contained in:
parent
29abe9692f
commit
8c2c1e96f6
|
@ -182,9 +182,8 @@ This is a list of strings that are suitable for input to `kbd'."
|
||||||
(defvar evil-collection--bindings-record (make-hash-table :test 'eq)
|
(defvar evil-collection--bindings-record (make-hash-table :test 'eq)
|
||||||
"Record of bindings currently made by Evil Collection. This is
|
"Record of bindings currently made by Evil Collection. This is
|
||||||
a hash-table with the package symbol as a key. The associated
|
a hash-table with the package symbol as a key. The associated
|
||||||
values are the package's bindings which are stored as a
|
values are the package's bindings which are stored as a list of
|
||||||
hash-table with key being the key to be bound and value as the
|
the form ((STATE KEY BINDING)).")
|
||||||
binding.")
|
|
||||||
|
|
||||||
(defvar evil-collection-setup-hook nil
|
(defvar evil-collection-setup-hook nil
|
||||||
"Hook run by `evil-collection-init' for each mode that is evilified.
|
"Hook run by `evil-collection-init' for each mode that is evilified.
|
||||||
|
@ -200,23 +199,31 @@ compatibility.")
|
||||||
|
|
||||||
(defun evil-collection-define-key (state map-sym &rest bindings)
|
(defun evil-collection-define-key (state map-sym &rest bindings)
|
||||||
"Wrapper for `evil-define-key*' with additional features.
|
"Wrapper for `evil-define-key*' with additional features.
|
||||||
Filter keys on the basis of `evil-collection-key-whitelist' and
|
Unlike `evil-define-key*' MAP-SYM should be a quoted keymap other
|
||||||
`evil-collection-key-blacklist'. Store bindings in
|
than the unquoted keymap required for `evil-define-key*'. This
|
||||||
|
function adds the ability to filter keys on the basis of
|
||||||
|
`evil-collection-key-whitelist' and
|
||||||
|
`evil-collection-key-blacklist'. It also stores bindings in
|
||||||
`evil-collection--bindings-record'."
|
`evil-collection--bindings-record'."
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
(let* ((whitelist (mapcar 'kbd evil-collection-key-whitelist))
|
(let* ((whitelist (mapcar 'kbd evil-collection-key-whitelist))
|
||||||
(blacklist (mapcar 'kbd evil-collection-key-blacklist))
|
(blacklist (mapcar 'kbd evil-collection-key-blacklist))
|
||||||
(record (gethash map-sym evil-collection--bindings-record
|
(record (gethash map-sym evil-collection--bindings-record))
|
||||||
(make-hash-table :test 'equal)))
|
|
||||||
filtered-bindings)
|
filtered-bindings)
|
||||||
(while bindings
|
(while bindings
|
||||||
(let ((key (pop bindings))
|
(let ((key (pop bindings))
|
||||||
(def (pop bindings)))
|
(def (pop bindings)))
|
||||||
(when (or (and whitelist (member key whitelist))
|
(when (or (and whitelist (member key whitelist))
|
||||||
(not (member key blacklist)))
|
(not (member key blacklist)))
|
||||||
(puthash key def record)
|
(if (consp state)
|
||||||
|
(dolist (st state)
|
||||||
|
(push (list (if st st 'all) (key-description key) def)
|
||||||
|
record))
|
||||||
|
(push (list (if state state 'all) (key-description key) def)
|
||||||
|
record))
|
||||||
(push key filtered-bindings)
|
(push key filtered-bindings)
|
||||||
(push def filtered-bindings))))
|
(push def filtered-bindings))))
|
||||||
|
(puthash map-sym record evil-collection--bindings-record)
|
||||||
(setq filtered-bindings (nreverse filtered-bindings))
|
(setq filtered-bindings (nreverse filtered-bindings))
|
||||||
(cond ((and (boundp map-sym) (keymapp (symbol-value map-sym)))
|
(cond ((and (boundp map-sym) (keymapp (symbol-value map-sym)))
|
||||||
(apply #'evil-define-key*
|
(apply #'evil-define-key*
|
||||||
|
@ -231,8 +238,17 @@ Filter keys on the basis of `evil-collection-key-whitelist' and
|
||||||
(remove-hook 'after-load-functions #',fun)
|
(remove-hook 'after-load-functions #',fun)
|
||||||
(apply #'evil-define-key*
|
(apply #'evil-define-key*
|
||||||
',state ,map-sym ',filtered-bindings))))
|
',state ,map-sym ',filtered-bindings))))
|
||||||
(add-hook 'after-load-functions fun t))))
|
(add-hook 'after-load-functions fun t))))))
|
||||||
(puthash map-sym record evil-collection--bindings-record)))
|
|
||||||
|
(defun evil-collection--binding-lessp (a b)
|
||||||
|
"Comparison function used to sort bindings of the form (state key def)."
|
||||||
|
(let ((a-state (symbol-name (nth 0 a)))
|
||||||
|
(b-state (symbol-name (nth 0 b)))
|
||||||
|
(a-key (nth 1 a))
|
||||||
|
(b-key (nth 1 b)))
|
||||||
|
(if (not (string= a-state b-state))
|
||||||
|
(string-lessp a-state b-state)
|
||||||
|
(string-lessp a-key b-key))))
|
||||||
|
|
||||||
(defun evil-collection-describe-all-bindings ()
|
(defun evil-collection-describe-all-bindings ()
|
||||||
"Print bindings made by Evil Collection to separate buffer."
|
"Print bindings made by Evil Collection to separate buffer."
|
||||||
|
@ -242,24 +258,28 @@ Filter keys on the basis of `evil-collection-key-whitelist' and
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(org-mode)
|
(org-mode)
|
||||||
(maphash
|
(dolist (keymap
|
||||||
(lambda (package bindings)
|
(sort (hash-table-keys evil-collection--bindings-record)
|
||||||
(insert "\n\n* " (symbol-name package) )
|
(lambda (a b)
|
||||||
|
(string-lessp (symbol-name a)
|
||||||
|
(symbol-name b)))))
|
||||||
|
(insert "\n\n* " (symbol-name keymap) "\n")
|
||||||
(insert "
|
(insert "
|
||||||
| Key | Definition |
|
| State | Key | Definition |
|
||||||
|-----|------------|
|
|-------|-----|------------|
|
||||||
")
|
")
|
||||||
(maphash
|
(cl-loop
|
||||||
(lambda (key def)
|
for (state key def) in
|
||||||
;; Don't print nil definitions
|
(sort (gethash keymap evil-collection--bindings-record)
|
||||||
(when def
|
#'evil-collection--binding-lessp)
|
||||||
(insert (format "| %s | %S |\n"
|
do
|
||||||
(replace-regexp-in-string
|
(when (and def (not (eq def 'ignore)))
|
||||||
"|" "¦" (key-description key))
|
(insert (format "| %s | %s | %S |\n"
|
||||||
|
state
|
||||||
|
(replace-regexp-in-string "|" "¦" key)
|
||||||
def))))
|
def))))
|
||||||
bindings)
|
|
||||||
(org-table-align))
|
(org-table-align))
|
||||||
evil-collection--bindings-record))))
|
(goto-char (point-min)))))
|
||||||
|
|
||||||
(defun evil-collection--translate-key (state keymap-symbol
|
(defun evil-collection--translate-key (state keymap-symbol
|
||||||
translations
|
translations
|
||||||
|
|
Loading…
Reference in New Issue