Make requested changes to prior two commits

See #143
This commit is contained in:
Justin Burkett 2018-06-05 21:12:06 -04:00 committed by James N
parent e60988f625
commit 0a913f9df6
1 changed files with 30 additions and 26 deletions

View File

@ -167,22 +167,23 @@ this confusing. It will be included if
:group 'evil-collection) :group 'evil-collection)
(defcustom evil-collection-key-whitelist '() (defcustom evil-collection-key-whitelist '()
"List of keys that may be used by evil-collection. "List of keys that may be used by Evil Collection.
This is a list of strings that are suitable for input to This is a list of strings that are suitable for input to
`kbd'. If there are no keys in the list, the whitelist will be ignored." `kbd'. If there are no keys in the list, the whitelist will be ignored."
:type '(repeat string) :type '(repeat string)
:group 'evil-collection) :group 'evil-collection)
(defcustom evil-collection-key-blacklist '() (defcustom evil-collection-key-blacklist '()
"List of keys that may not be used by evil-collection. "List of keys that may not be used by Evil Collection.
This is a list of strings that are suitable for input to `kbd'." This is a list of strings that are suitable for input to `kbd'."
:type '(repeat string) :type '(repeat string)
:group 'evil-collection) :group 'evil-collection)
(defvar evil-collection-bindings-record '() (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
an alist of the form ((PACKAGE . BINDINGS)), where bindings is an a hash-table with the package symbol as a key. The associated
alist of the form ((KEY . FUNCTION)).") values are the package's bindings which are stored as a hash-table with key
being the key to be bound and value as the 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.
@ -193,6 +194,9 @@ Evil Collection for that mode. More arguments may be added in the future, so
functions added to this hook should include a \"&rest _rest\" for forward functions added to this hook should include a \"&rest _rest\" for forward
compatibility.") compatibility.")
(defvar evil-collection-describe-buffer "*evil-collection*"
"Name for Evil Collection buffer used to describe bindings.")
(defun evil-collection-define-key (state package map-sym &rest bindings) (defun evil-collection-define-key (state package 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 Filter keys on the basis of `evil-collection-key-whitelist' and
@ -201,46 +205,46 @@ Filter keys on the basis of `evil-collection-key-whitelist' and
(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 (cdr-safe (assoc package evil-collection-bindings-record)))) (record (gethash package evil-collection-bindings-record
(make-hash-table :test 'equal))))
(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)))
(push (cons key def) record) (puthash key def record)
(eval-after-load package (eval-after-load package
`(condition-case err `(condition-case err
(evil-define-key* ',state ,map-sym ,key ',def) (evil-define-key* ',state ,map-sym ,key ',def)
(error (error
(message "evil-collection: Bad binding %s" (message "evil-collection: Bad binding %s"
'(evil-define-key* ',state ,map-sym ,key ',def)))))))) '(evil-define-key* ',state ,map-sym ,key ',def))))))))
(setq record (nreverse record)) (puthash package record evil-collection-bindings-record)))
(if (assoc package evil-collection-bindings-record)
(setcdr (assoc package evil-collection-bindings-record) record)
(push (cons package record) evil-collection-bindings-record))
nil))
(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."
(interactive) (interactive)
(let ((buf (get-buffer-create "*evil-collection*"))) (let ((buf (get-buffer-create evil-collection-describe-buffer)))
(switch-to-buffer-other-window buf) (switch-to-buffer-other-window buf)
(with-current-buffer buf (with-current-buffer buf
(erase-buffer) (erase-buffer)
(org-mode) (org-mode)
(dolist (package evil-collection-bindings-record) (maphash
(insert "\n\n* " (symbol-name (car package)) ) (lambda (package bindings)
(insert " (insert "\n\n* " (symbol-name package) )
(insert "
| Key | Definition | | Key | Definition |
|-----|------------| |-----|------------|
") ")
(dolist (binding (cdr package)) (maphash
;; Don't print nil definitions (lambda (key def)
(when (cdr binding) ;; Don't print nil definitions
;; FIXME: Handle keys with | in them (when def
(insert (format "| %s | %S |\n" ;; FIXME: Handle keys with | in them
(key-description (car binding)) (cdr binding))))) (insert (format "| %s | %S |\n" (key-description key) def))))
(org-table-align))))) bindings)
(org-table-align))
evil-collection-bindings-record))))
(defun evil-collection--translate-key (state keymap-symbol (defun evil-collection--translate-key (state keymap-symbol
translations translations