Enhance describe bindings functionality.

Rename evil-collection-describe-all-bindings to
evil-collection-describe-bindings. By default the function prints all known
evil-collection bindings. With a non-nil interactive argument, print only the
bindings corresponding to active modes in the current buffer.
This commit is contained in:
Justin Burkett 2018-06-12 21:57:16 -04:00 committed by James N
parent 81311f26bf
commit df269baf95
1 changed files with 39 additions and 19 deletions

View File

@ -255,12 +255,29 @@ function adds the ability to filter keys on the basis of
(string-lessp a-state b-state) (string-lessp a-state b-state)
(string-lessp a-key b-key)))) (string-lessp a-key b-key))))
(defun evil-collection-describe-all-bindings () (defun evil-collection--map-active-p (map-name)
"Print bindings made by Evil Collection to separate buffer." "Does MAP-NAME correspond to an active major or minor mode?
(interactive)
(let ((buf (get-buffer-create evil-collection-describe-buffer))) This is a guess based on the convention that xyz-mode typically
(switch-to-buffer-other-window buf) is associated with the map xyz-mode-map."
(with-current-buffer buf (save-match-data
(when (string-match "\\(.+-mode\\)-map" map-name)
(let ((mode (intern (match-string 1 map-name))))
(or (eq major-mode mode)
(and (boundp mode)
(assoc mode minor-mode-alist)
(symbol-value mode)))))))
(defun evil-collection-describe-bindings (&optional arg)
"Print bindings made by Evil Collection to separate buffer.
With non-nil ARG, restrict to bindings corresponding to active
modes in the current buffer."
(interactive "P")
(let ((orig-buf (current-buffer))
(desc-buf (get-buffer-create evil-collection-describe-buffer)))
(switch-to-buffer-other-window desc-buf)
(with-current-buffer desc-buf
(erase-buffer) (erase-buffer)
(org-mode) (org-mode)
(dolist (keymap (dolist (keymap
@ -268,22 +285,25 @@ function adds the ability to filter keys on the basis of
(lambda (a b) (lambda (a b)
(string-lessp (symbol-name a) (string-lessp (symbol-name a)
(symbol-name b))))) (symbol-name b)))))
(insert "\n\n* " (symbol-name keymap) "\n") (when (or (null arg)
(insert " (with-current-buffer orig-buf
(evil-collection--map-active-p (symbol-name keymap))))
(insert "\n\n* " (symbol-name keymap) "\n")
(insert "
| State | Key | Definition | | State | Key | Definition |
|-------|-----|------------| |-------|-----|------------|
") ")
(cl-loop (cl-loop
for (state key def) in for (state key def) in
(sort (gethash keymap evil-collection--bindings-record) (sort (gethash keymap evil-collection--bindings-record)
#'evil-collection--binding-lessp) #'evil-collection--binding-lessp)
do do
(when (and def (not (eq def 'ignore))) (when (and def (not (eq def 'ignore)))
(insert (format "| %s | %s | %S |\n" (insert (format "| %s | %s | %S |\n"
state state
(replace-regexp-in-string "|" "¦" key) (replace-regexp-in-string "|" "¦" key)
def)))) def))))
(org-table-align)) (org-table-align)))
(goto-char (point-min))))) (goto-char (point-min)))))
(defun evil-collection--translate-key (state keymap-symbol (defun evil-collection--translate-key (state keymap-symbol