From 1853b53a8daf908244e83b8437aa2a0fb744a681 Mon Sep 17 00:00:00 2001 From: noctuid Date: Sun, 17 Dec 2017 22:26:31 -0500 Subject: [PATCH] Add key translation functionality Also add evil-collection-setup-hook. Fixes #5 and #98. --- evil-collection-ag.el | 2 + evil-collection-alchemist.el | 11 +++ evil-collection-anaconda-mode.el | 3 + evil-collection-arc-mode.el | 2 + evil-collection-bookmark.el | 2 + evil-collection-buff-menu.el | 2 + evil-collection-calc.el | 2 + evil-collection-calendar.el | 2 + evil-collection-cider.el | 6 ++ evil-collection-comint.el | 2 + evil-collection-company.el | 2 + evil-collection-compile.el | 2 + evil-collection-cus-theme.el | 3 + evil-collection-custom.el | 2 + evil-collection-daemons.el | 3 + evil-collection-debbugs.el | 2 + evil-collection-debug.el | 2 + evil-collection-diff-mode.el | 2 + evil-collection-dired.el | 2 + evil-collection-doc-view.el | 2 + evil-collection-edebug.el | 5 ++ evil-collection-elfeed.el | 3 + evil-collection-elisp-mode.el | 2 + evil-collection-elisp-refs.el | 2 + evil-collection-emms.el | 3 + evil-collection-epa.el | 4 ++ evil-collection-eshell.el | 2 + evil-collection-eval-sexp-fu.el | 2 + evil-collection-eww.el | 5 ++ evil-collection-flycheck.el | 2 + evil-collection-free-keys.el | 2 + evil-collection-geiser.el | 5 ++ evil-collection-ggtags.el | 5 ++ evil-collection-go-mode.el | 8 ++- evil-collection-helm.el | 9 +++ evil-collection-help.el | 2 + evil-collection-ibuffer.el | 2 + evil-collection-image+.el | 2 + evil-collection-image.el | 2 + evil-collection-indium.el | 9 ++- evil-collection-info.el | 2 + evil-collection-ivy.el | 4 ++ evil-collection-kotlin-mode.el | 2 + evil-collection-log-view.el | 7 +- evil-collection-lua-mode.el | 2 + evil-collection-macrostep.el | 2 + evil-collection-man.el | 2 + evil-collection-minibuffer.el | 7 ++ evil-collection-neotree.el | 2 + evil-collection-notmuch.el | 7 ++ evil-collection-nov.el | 3 + evil-collection-occur.el | 3 + evil-collection-outline.el | 2 + evil-collection-p4.el | 2 + evil-collection-package-menu.el | 2 + evil-collection-pass.el | 2 + evil-collection-pdf.el | 4 ++ evil-collection-popup.el | 7 +- evil-collection-proced.el | 2 + evil-collection-prodigy.el | 3 + evil-collection-profiler.el | 2 + evil-collection-python.el | 2 + evil-collection-quickrun.el | 7 +- evil-collection-racer.el | 5 +- evil-collection-realgud.el | 7 +- evil-collection-reftex.el | 3 + evil-collection-rjsx-mode.el | 2 + evil-collection-robe.el | 2 + evil-collection-rtags.el | 5 ++ evil-collection-ruby-mode.el | 2 + evil-collection-simple.el | 6 +- evil-collection-slime.el | 7 ++ evil-collection-term.el | 3 + evil-collection-tide.el | 4 ++ evil-collection-transmission.el | 5 ++ evil-collection-vc-annotate.el | 7 +- evil-collection-view.el | 4 +- evil-collection-vlf.el | 2 + evil-collection-which-key.el | 2 + evil-collection-woman.el | 2 + evil-collection-xref.el | 2 + evil-collection-ztree.el | 2 + evil-collection.el | 105 +++++++++++++++++++++++++++- readme.org | 116 +++++++++++++++++++++++++++++++ 84 files changed, 483 insertions(+), 20 deletions(-) diff --git a/evil-collection-ag.el b/evil-collection-ag.el index 73dc5e0..e8599ed 100644 --- a/evil-collection-ag.el +++ b/evil-collection-ag.el @@ -31,6 +31,8 @@ (require 'evil) (require 'evil-collection-evil-search) +(defconst evil-collection-ag-maps '(ag-mode-map)) + (defun evil-collection-ag-setup () "Set up `evil' bindings for `ag'." (evil-define-key '(normal visual) ag-mode-map diff --git a/evil-collection-alchemist.el b/evil-collection-alchemist.el index 86afa83..30c51b6 100644 --- a/evil-collection-alchemist.el +++ b/evil-collection-alchemist.el @@ -30,6 +30,17 @@ (require 'evil) (require 'alchemist nil t) +(defconst evil-collection-alchemist-maps '(alchemist-compile-mode-map + alchemist-eval-mode-map + alchemist-execute-mode-map + alchemist-message-mode-map + alchemist-help-minor-mode-map + alchemist-macroexpand-mode-map + alchemist-mix-mode-map + alchemist-test-report-mode-map + alchemist-mode-map)) + + (defun evil-collection-alchemist-setup () "Set up `evil' bindings for `alchemist'." (evil-set-initial-state 'alchemist-compile-mode 'normal) diff --git a/evil-collection-anaconda-mode.el b/evil-collection-anaconda-mode.el index 9ea709c..f642d3b 100644 --- a/evil-collection-anaconda-mode.el +++ b/evil-collection-anaconda-mode.el @@ -29,6 +29,9 @@ (require 'anaconda-mode nil t) (require 'evil) +(defconst evil-collection-anaconda-mode-maps '(anaconda-mode-view-mode-map + anaconda-mode-map)) + (defun evil-collection-anaconda-mode-setup () "Set up `evil' bindings for `anaconda-mode'." ;; Bindings don't seem to be set the first time. diff --git a/evil-collection-arc-mode.el b/evil-collection-arc-mode.el index fab4f57..4d17187 100644 --- a/evil-collection-arc-mode.el +++ b/evil-collection-arc-mode.el @@ -30,6 +30,8 @@ (require 'arc-mode) (require 'evil) +(defconst evil-collection-arc-mode-maps '(archive-mode-map)) + (defun evil-collection-arc-mode-setup () "Set up `evil' bindings for `arc-mode'." (evil-set-initial-state 'arc-mode 'normal) diff --git a/evil-collection-bookmark.el b/evil-collection-bookmark.el index 5f76285..bf61878 100644 --- a/evil-collection-bookmark.el +++ b/evil-collection-bookmark.el @@ -29,6 +29,8 @@ ;;; Code: (require 'bookmark) +(defconst evil-collection-bookmark-maps '(bookmark-bmenu-mode-map)) + (defun evil-collection-bookmark-setup () "Set up `evil' bindings for `bookmark'." (evil-set-initial-state 'bookmark-bmenu-mode 'normal) diff --git a/evil-collection-buff-menu.el b/evil-collection-buff-menu.el index 9172b3a..ba47aef 100644 --- a/evil-collection-buff-menu.el +++ b/evil-collection-buff-menu.el @@ -34,6 +34,8 @@ (require 'evil) (require 'tabulated-list) +(defconst evil-collection-buff-menu-maps '(Buffer-menu-mode-map)) + ;; This is for `evil-collection-Buffer-menu-unmark-all-buffers.' (defsubst evil-collection-buff-menu-tabulated-list-header-overlay-p (&optional pos) "Return non-nil if there is a fake header. diff --git a/evil-collection-calc.el b/evil-collection-calc.el index d0aed7b..285fc82 100644 --- a/evil-collection-calc.el +++ b/evil-collection-calc.el @@ -29,6 +29,8 @@ (require 'evil-collection-util) (require 'calc) +(defconst evil-collection-calc-maps '(calc-mode-map)) + (defun evil-collection-calc-ext-setup () "Set up `evil' bindings for `calc'. Since calc bindings are set on-demand when calc-ext is load, we diff --git a/evil-collection-calendar.el b/evil-collection-calendar.el index 869d112..4ae22d0 100644 --- a/evil-collection-calendar.el +++ b/evil-collection-calendar.el @@ -30,6 +30,8 @@ (require 'calendar) (require 'evil) +(defconst evil-collection-calendar-maps '(calendar-mode-map)) + (defun evil-collection-calendar-setup () "Set up `evil' bindings for `calendar'." (evil-set-initial-state 'calendar-mode 'normal) diff --git a/evil-collection-cider.el b/evil-collection-cider.el index 5d900de..065385e 100644 --- a/evil-collection-cider.el +++ b/evil-collection-cider.el @@ -34,6 +34,12 @@ (declare-function cider-debug-mode-send-reply "cider-debug") +(defconst evil-collection-cider-maps '(cider-mode-map + cider-repl-mode-map + cider-test-report-mode-map + cider-macroexpansion-mode-map + cider-connections-buffer-mode-map)) + (defun evil-collection-cider-last-sexp (command &rest args) "In normal-state or motion-state, last sexp ends at point." (if (and (not evil-move-beyond-eol) diff --git a/evil-collection-comint.el b/evil-collection-comint.el index e6b4524..bbcc5f8 100644 --- a/evil-collection-comint.el +++ b/evil-collection-comint.el @@ -30,6 +30,8 @@ (require 'comint) (require 'evil) +(defconst evil-collection-comint-maps '(comint-mode-map)) + (defun evil-collection-comint-setup () "Set up `evil' bindings for `comint'." (when evil-want-C-d-scroll diff --git a/evil-collection-company.el b/evil-collection-company.el index ea80138..f6d09bd 100644 --- a/evil-collection-company.el +++ b/evil-collection-company.el @@ -50,6 +50,8 @@ be set through custom or before evil-collection loads." (defvar company-active-map) (defvar company-search-map) +(defconst evil-collection-company-maps '(company-active-map company-search-map)) + (defun evil-collection-company-setup () "Set up `evil' bindings for `company'." (define-key company-active-map (kbd "C-n") 'company-select-next-or-abort) diff --git a/evil-collection-compile.el b/evil-collection-compile.el index 43c3c55..221da73 100644 --- a/evil-collection-compile.el +++ b/evil-collection-compile.el @@ -31,6 +31,8 @@ (require 'compile) (require 'evil-collection-evil-search) +(defconst evil-collection-compile-maps '(compilation-mode-map)) + (defun evil-collection-compile-setup () "Set up `evil' bindings for `compile'." (evil-set-initial-state 'compilation-mode 'normal) diff --git a/evil-collection-cus-theme.el b/evil-collection-cus-theme.el index cc44af4..d5a7386 100644 --- a/evil-collection-cus-theme.el +++ b/evil-collection-cus-theme.el @@ -30,6 +30,9 @@ (require 'cus-theme) (require 'evil) +(defconst evil-collection-cus-theme-maps '(custom-theme-choose-mode-map + custom-new-theme-mode-map)) + (defun evil-collection-cus-theme-setup () "Set up `evil' bindings for `cus-theme'." (evil-set-initial-state 'custom-new-theme-mode 'normal) diff --git a/evil-collection-custom.el b/evil-collection-custom.el index 98d8a18..25485eb 100644 --- a/evil-collection-custom.el +++ b/evil-collection-custom.el @@ -30,6 +30,8 @@ (require 'cus-edit) (require 'evil) +(defconst evil-collection-custom-maps '(custom-mode-map)) + (defun evil-collection-custom-setup () "Set up `evil' bindings for `Custom-mode'." (evil-set-initial-state 'Custom-mode 'normal) diff --git a/evil-collection-daemons.el b/evil-collection-daemons.el index 5a81bb0..cc9d54d 100644 --- a/evil-collection-daemons.el +++ b/evil-collection-daemons.el @@ -30,6 +30,9 @@ (require 'daemons nil t) (require 'evil) +(defconst evil-collection-daemons-maps '(daemons-mode-map + daemons-output-mode-map)) + (defun evil-collection-daemons-setup () "Set up `evil' bindings for `daemons'." (evil-define-key '(normal visual) daemons-mode-map diff --git a/evil-collection-debbugs.el b/evil-collection-debbugs.el index a7bc679..0c9fcea 100644 --- a/evil-collection-debbugs.el +++ b/evil-collection-debbugs.el @@ -30,6 +30,8 @@ (require 'debbugs nil t) (require 'evil) +(defconst evil-collection-debbugs-maps '(debbugs-gnu-mode-map)) + (defun evil-collection-debbugs-setup () "Set up `evil' bindings for `debbugs-gnu-mode'." (evil-set-initial-state 'debbugs-gnu-mode 'normal) diff --git a/evil-collection-debug.el b/evil-collection-debug.el index 4723438..d9542b2 100644 --- a/evil-collection-debug.el +++ b/evil-collection-debug.el @@ -31,6 +31,8 @@ (require 'evil) (require 'debug) +(defconst evil-collection-debug-maps '(debugger-mode-map)) + (defun evil-collection-debug-setup () "Set up `evil' bindings for `debug'." (evil-set-initial-state 'debugger-mode 'normal) diff --git a/evil-collection-diff-mode.el b/evil-collection-diff-mode.el index b3a00fb..edeec59 100644 --- a/evil-collection-diff-mode.el +++ b/evil-collection-diff-mode.el @@ -38,6 +38,8 @@ (require 'evil) (require 'diff-mode) +(defconst evil-collection-diff-mode-maps '(diff-mode-map)) + (defun evil-collection-diff-read-only-state-switch () "Make read-only in motion state, writable in normal state." (if buffer-read-only diff --git a/evil-collection-dired.el b/evil-collection-dired.el index ae9c2e8..4721347 100644 --- a/evil-collection-dired.el +++ b/evil-collection-dired.el @@ -30,6 +30,8 @@ (require 'dired) (require 'evil) +(defconst evil-collection-dired-maps '(dired-mode-map)) + (defun evil-collection-dired-setup () "Set up `evil' bindings for `dired'." (evil-define-key 'normal dired-mode-map diff --git a/evil-collection-doc-view.el b/evil-collection-doc-view.el index b662b57..bbfca40 100644 --- a/evil-collection-doc-view.el +++ b/evil-collection-doc-view.el @@ -30,6 +30,8 @@ (require 'evil) (require 'doc-view) +(defconst evil-collection-doc-view-maps '(doc-view-mode-map)) + (defun evil-collection-doc-view-setup () "Set up `evil' bindings for `doc-view'." (evil-set-initial-state 'doc-view-mode 'normal) diff --git a/evil-collection-edebug.el b/evil-collection-edebug.el index d8e4a75..575c195 100644 --- a/evil-collection-edebug.el +++ b/evil-collection-edebug.el @@ -30,6 +30,11 @@ (require 'edebug) (require 'evil) +(defconst evil-collection-edebug-maps + '(edebug-mode-map + edebug-x-instrumented-function-list-mode-map + edebug-x-breakpoint-list-mode-map)) + (defun evil-collection-edebug-setup () "Set up `evil' bindings for `edebug'." (evil-set-initial-state 'edebug-mode 'normal) diff --git a/evil-collection-elfeed.el b/evil-collection-elfeed.el index 989b810..c9e7226 100644 --- a/evil-collection-elfeed.el +++ b/evil-collection-elfeed.el @@ -33,6 +33,9 @@ (defvar elfeed-search-mode-map) (defvar elfeed-show-mode-map) +(defconst evil-collection-elfeed-maps '(elfeed-search-mode-map + elfeed-show-mode-map)) + (defun evil-collection-elfeed-setup () "Set up `evil' bindings for `elfeed'." diff --git a/evil-collection-elisp-mode.el b/evil-collection-elisp-mode.el index bcc481d..c0b23df 100644 --- a/evil-collection-elisp-mode.el +++ b/evil-collection-elisp-mode.el @@ -30,6 +30,8 @@ (require 'elisp-mode) (require 'evil) +(defconst evil-collection-elisp-mode-maps nil) + (defun evil-collection-elisp-mode-last-sexp-setup-props (beg end value alt1 alt2) "Set up text properties for the output of `elisp--eval-last-sexp'. BEG and END are the start and end of the output in current-buffer. diff --git a/evil-collection-elisp-refs.el b/evil-collection-elisp-refs.el index d4ab274..ed56ea3 100644 --- a/evil-collection-elisp-refs.el +++ b/evil-collection-elisp-refs.el @@ -31,6 +31,8 @@ (require 'evil) (require 'elisp-refs nil t) +(defconst evil-collection-elisp-refs-maps '(elisp-refs-mode-map)) + (defun evil-collection-elisp-refs-setup () "Set up `evil' bindings for `elisp-refs'." (evil-define-key 'normal elisp-refs-mode-map diff --git a/evil-collection-emms.el b/evil-collection-emms.el index acb6f83..7bdd2d0 100644 --- a/evil-collection-emms.el +++ b/evil-collection-emms.el @@ -36,6 +36,9 @@ (defvar emms-browser-mode-map) (defvar emms-playlist-mode-map) +(defconst evil-collection-emms-maps '(emms-browser-mode-map + emms-playlist-mode-map)) + (defun evil-collection-emms-playlist-mode-insert-newline-above () "Insert a newline above point." (interactive) diff --git a/evil-collection-epa.el b/evil-collection-epa.el index 5c9f057..ed47920 100644 --- a/evil-collection-epa.el +++ b/evil-collection-epa.el @@ -31,6 +31,10 @@ (require 'evil) (require 'epa nil t) +(defconst evil-collection-epa-maps '(epa-key-list-mode-map + epa-key-mode-map + epa-info-mode-map)) + (defun evil-collection-epa-setup () (evil-define-key 'normal epa-key-list-mode-map (kbd "") 'widget-forward diff --git a/evil-collection-eshell.el b/evil-collection-eshell.el index 5fa2258..da50f58 100644 --- a/evil-collection-eshell.el +++ b/evil-collection-eshell.el @@ -31,6 +31,8 @@ (require 'eshell) (require 'evil) +(defconst evil-collection-eshell-maps '(eshell-mode-map)) + (defun evil-collection-eshell-next-prompt () "`evil' wrapper around `eshell-next-prompt'." (when (get-text-property (point) 'read-only) diff --git a/evil-collection-eval-sexp-fu.el b/evil-collection-eval-sexp-fu.el index 0375d6d..da06219 100644 --- a/evil-collection-eval-sexp-fu.el +++ b/evil-collection-eval-sexp-fu.el @@ -30,6 +30,8 @@ (require 'evil) (require 'eval-sexp-fu nil t) +(defconst evil-collection-eval-sexp-fu-maps nil) + (defun evil-collection-eval-sexp-fu-bounds-of-thing-at-point-sexp (command &rest args) "In normal-state or motion-state, last sexp ends at point." (if (and (eq (nth 0 args) 'sexp) diff --git a/evil-collection-eww.el b/evil-collection-eww.el index d5b826d..17307f2 100644 --- a/evil-collection-eww.el +++ b/evil-collection-eww.el @@ -30,6 +30,11 @@ (require 'eww) (require 'evil-collection-util) +(defvar evil-collection-eww-maps '(eww-mode-map + eww-history-mode-map + eww-buffers-mode-map + eww-bookmark-mode-map)) + (defun evil-collection-eww-setup () "Set up `evil' bindings for `eww'." diff --git a/evil-collection-flycheck.el b/evil-collection-flycheck.el index 101bcd7..f95a877 100644 --- a/evil-collection-flycheck.el +++ b/evil-collection-flycheck.el @@ -32,6 +32,8 @@ (defvar flycheck-error-list-mode-map) +(defconst evil-collection-flycheck-maps '(flycheck-error-list-mode-map)) + (defun evil-collection-flycheck-setup () "Set up `evil' bindings for `flycheck'." (evil-set-initial-state 'flycheck-error-list-mode 'normal) diff --git a/evil-collection-free-keys.el b/evil-collection-free-keys.el index 53e4186..4554864 100644 --- a/evil-collection-free-keys.el +++ b/evil-collection-free-keys.el @@ -31,6 +31,8 @@ ;;; Code: (defvar free-keys-mode-map) +(defconst evil-collection-free-keys-maps '(free-keys-mode-map)) + (defun evil-collection-free-keys-set-header-line-format () "Tweak `header-line-format' locally for `free-keys'." (setq-local header-line-format diff --git a/evil-collection-geiser.el b/evil-collection-geiser.el index 0c91832..6d29859 100644 --- a/evil-collection-geiser.el +++ b/evil-collection-geiser.el @@ -33,6 +33,11 @@ (defvar geiser-debug-mode-map) (defvar geiser-doc-mode-map) +(defconst evil-collection-geiser-maps '(geiser-debug-mode-map + geiser-doc-mode-map + geiser-repl-mode-map + geiser-mode-map)) + (defun evil-collection-geiser-last-sexp (command &rest args) "In normal-state or motion-state, last sexp ends at point." (if (and (not evil-move-beyond-eol) diff --git a/evil-collection-ggtags.el b/evil-collection-ggtags.el index 1f4539d..210dec5 100644 --- a/evil-collection-ggtags.el +++ b/evil-collection-ggtags.el @@ -36,6 +36,11 @@ (defvar ggtags-view-tag-history-mode-map) (defvar ggtags-navigation-map) +(defconst evil-collection-ggtags-maps '(ggtags-mode-map + ggtags-view-search-history-mode-map + ggtags-view-tag-history-mode-map + ggtags-navigation-map)) + (defun evil-collection-ggtags-setup () "Set up `evil' bindings for `ggtags'." (evil-set-initial-state 'ggtags-global-mode 'normal) diff --git a/evil-collection-go-mode.el b/evil-collection-go-mode.el index 68975e6..2d5d5b9 100644 --- a/evil-collection-go-mode.el +++ b/evil-collection-go-mode.el @@ -24,11 +24,15 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `go-mode'. +;; Bindings for `go-mode'. + +;;; Code: (require 'evil) (require 'go-mode nil t) -;;; Code: +(defconst evil-collection-go-mode-maps '(go-mode-map + godoc-mode-map)) + (defun evil-collection-go-mode-setup () "Set up `evil' bindings for `go-mode'." (evil-define-key 'normal go-mode-map diff --git a/evil-collection-helm.el b/evil-collection-helm.el index fd78776..e6accc2 100644 --- a/evil-collection-helm.el +++ b/evil-collection-helm.el @@ -48,6 +48,14 @@ (declare-function helm-window "helm-lib") +(defconst evil-collection-helm-maps '(help-map + help-find-files-map + helm-read-file-map + helm-generic-files-map + helm-buffer-map + helm-moccur-map + helm-grep-map)) + ;; From https://github.com/emacs-helm/helm/issues/362. ;; Also see https://emacs.stackexchange.com/questions/17058/change-cursor-type-in-helm-header-line#17097. ;; TODO: With Evil, the cursor type is not right in the header line and the evil @@ -113,6 +121,7 @@ header-line-format) (when update (force-mode-line-update))))))) + (defun evil-collection-helm-setup () "Set up `evil' bindings for `helm'." (add-hook 'helm-minibuffer-set-up-hook 'evil-collection-helm-hide-minibuffer-maybe) diff --git a/evil-collection-help.el b/evil-collection-help.el index cefd611..a736a1f 100644 --- a/evil-collection-help.el +++ b/evil-collection-help.el @@ -30,6 +30,8 @@ (require 'evil) (require 'help-mode) +(defconst evil-collection-help-maps '(help-mode-map)) + (defun evil-collection-help-setup () "Set up `evil' bindings for `help'." (evil-set-initial-state 'help-mode 'normal) diff --git a/evil-collection-ibuffer.el b/evil-collection-ibuffer.el index cb734db..b7369c4 100644 --- a/evil-collection-ibuffer.el +++ b/evil-collection-ibuffer.el @@ -30,6 +30,8 @@ (require 'evil) (require 'ibuffer) +(defconst evil-collection-ibuffer-maps '(ibuffer-mode-map)) + (defun evil-collection-ibuffer-setup () "Set up `evil' bindings for `ibuffer'." (evil-set-initial-state 'ibuffer-mode 'normal) diff --git a/evil-collection-image+.el b/evil-collection-image+.el index 884ff21..d6c9eb2 100644 --- a/evil-collection-image+.el +++ b/evil-collection-image+.el @@ -30,6 +30,8 @@ (require 'evil) (require 'image+ nil t) +(defconst evil-collection-image+-maps '(image-mode-map)) + (defun evil-collection-image+-setup () "Set up `evil' bindings for `image+'." (evil-define-key 'normal image-mode-map diff --git a/evil-collection-image.el b/evil-collection-image.el index 04250c4..768a1b8 100644 --- a/evil-collection-image.el +++ b/evil-collection-image.el @@ -33,6 +33,8 @@ ;; TODO: pdf and doc-view conflict with image. ;; See https://github.com/emacs-evil/evil-collection/issues/23. +(defconst evil-collection-image-maps '(image-mode-map)) + (defun evil-collection-image-setup () "Set up `evil' bindings for `image-mode'." (evil-set-initial-state 'image-mode 'normal) diff --git a/evil-collection-indium.el b/evil-collection-indium.el index 958ba50..af2c426 100644 --- a/evil-collection-indium.el +++ b/evil-collection-indium.el @@ -24,12 +24,19 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `indium'. +;; Bindings for `indium'. ;;; Code: (require 'evil-collection-settings) (require 'indium nil t) +(defconst evil-collection-indium-maps '(indium-debugger-mode-map + indium-inspector-mode-map + indium-debugger-locals-mode-map + indium-debugger-frames-mode-map + indium-interaction-mode-map + indium-repl-mode-map)) + (defun evil-collection-indium-setup () "Set up `evil' bindings for `indium'." (when evil-collection-settings-setup-debugger-keys diff --git a/evil-collection-info.el b/evil-collection-info.el index 5cad996..2638d36 100644 --- a/evil-collection-info.el +++ b/evil-collection-info.el @@ -32,6 +32,8 @@ (require 'evil-collection-evil-search) (require 'info) +(defconst evil-collection-info-maps '(Info-mode-map)) + (defun evil-collection-info-setup () "Set up `evil' bindings for `info-mode'." (evil-collection-util-inhibit-insert-state Info-mode-map) diff --git a/evil-collection-ivy.el b/evil-collection-ivy.el index 0413f9a..9ac2aa6 100644 --- a/evil-collection-ivy.el +++ b/evil-collection-ivy.el @@ -30,6 +30,10 @@ (require 'evil) (require 'ivy nil t) +(defconst evil-collection-ivy-maps '(ivy-occur-mode-map + ivy-occur-grep-mode-map + ivy-minibuffer-map)) + (defun evil-collection-ivy-setup () "Set up `evil' bindings for `ivy-mode'." (evil-define-key 'normal ivy-occur-mode-map diff --git a/evil-collection-kotlin-mode.el b/evil-collection-kotlin-mode.el index a1ba81a..7e181a0 100644 --- a/evil-collection-kotlin-mode.el +++ b/evil-collection-kotlin-mode.el @@ -30,6 +30,8 @@ (require 'evil) (require 'kotlin-mode nil t) +(defconst evil-collection-kotlin-maps '(kotlin-mode-map)) + (defun evil-collection-kotlin-mode-setup () "Set up `evil' bindings for `kotlin-mode'." (evil-define-key 'normal kotlin-mode-map "gz" 'kotlin-repl)) diff --git a/evil-collection-log-view.el b/evil-collection-log-view.el index aaa1711..a484c5c 100644 --- a/evil-collection-log-view.el +++ b/evil-collection-log-view.el @@ -24,11 +24,14 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `log-view' +;; Bindings for `log-view'. + +;;; Code: (require 'evil) (require 'log-view) -;;; Code: +(defconst evil-collection-log-view-maps '(log-view-mode-map)) + (defun evil-collection-log-view-setup () "Set up `evil' bindings for `log-view'." (evil-define-key 'normal log-view-mode-map diff --git a/evil-collection-lua-mode.el b/evil-collection-lua-mode.el index 161d305..e907075 100644 --- a/evil-collection-lua-mode.el +++ b/evil-collection-lua-mode.el @@ -32,6 +32,8 @@ (defvar lua-indent-level) +(defconst evil-collection-lua-mode-maps '(lua-mode-map)) + (defun evil-collection-lua-mode-set-evil-shift-width () "Set `evil-shift-width' according to `lua-indent-level'." (setq evil-shift-width lua-indent-level)) diff --git a/evil-collection-macrostep.el b/evil-collection-macrostep.el index d58f745..0f7045d 100644 --- a/evil-collection-macrostep.el +++ b/evil-collection-macrostep.el @@ -30,6 +30,8 @@ (require 'evil) (require 'macrostep nil t) +(defconst evil-collection-macrostep-maps '(macrostep-keymap)) + (defun evil-collection-macrostep-setup () "Set up `evil' bindings for `macrostep'." ;; Keymaps don't seem to be populated on first try. diff --git a/evil-collection-man.el b/evil-collection-man.el index a0e684b..09bf752 100644 --- a/evil-collection-man.el +++ b/evil-collection-man.el @@ -30,6 +30,8 @@ (require 'evil) (require 'man) +(defconst evil-collection-man-maps '(Man-mode-map)) + (defun evil-collection-man-setup () "Set up `evil' bindings for `man'." (evil-set-initial-state 'Man-mode 'normal) diff --git a/evil-collection-minibuffer.el b/evil-collection-minibuffer.el index 0f210a5..57b4407 100644 --- a/evil-collection-minibuffer.el +++ b/evil-collection-minibuffer.el @@ -29,6 +29,13 @@ ;;; Code: (require 'evil) +(defconst evil-collection-minibuffer-maps '(minibuffer-local-map + minibuffer-local-ns-map + minibuffer-local-completion-map + minibuffer-local-must-match-map + minibuffer-local-isearch-map + evil-ex-completion-map)) + (defun evil-collection-minibuffer-insert () "Switch to insert state. diff --git a/evil-collection-neotree.el b/evil-collection-neotree.el index 40860c7..163b71f 100644 --- a/evil-collection-neotree.el +++ b/evil-collection-neotree.el @@ -31,6 +31,8 @@ (require 'evil) (require 'neotree nil t) +(defconst evil-collection-neotree-maps '(neotree-mode-map)) + (defun evil-collection-neotree-setup () "Set up `evil' bindings for `neotree'." diff --git a/evil-collection-notmuch.el b/evil-collection-notmuch.el index 66238b1..0b2cee3 100644 --- a/evil-collection-notmuch.el +++ b/evil-collection-notmuch.el @@ -36,6 +36,13 @@ (declare-function notmuch-search-tag "notmuch") (declare-function notmuch-tree-tag "notmuch-tree") +(defconst evil-collection-notmuch-maps '(notmuch-common-keymap + notmuch-hello-mode-map + notmuch-show-mode-map + notmuch-tree-mode-map + notmuch-search-mode-map + notmuch-search-stash-map)) + (defun evil-collection-notmuch-show-toggle-delete () "Toggle deleted tag for message." (interactive) diff --git a/evil-collection-nov.el b/evil-collection-nov.el index 17d1968..0ba9a4a 100644 --- a/evil-collection-nov.el +++ b/evil-collection-nov.el @@ -31,6 +31,9 @@ (require 'nov nil t) (defvar nov-mode-map) + +(defconst evil-collection-nov-maps '(nov-mode-map)) + (defun evil-collection-nov-setup () "Set up `evil' bindings for `nov'." (evil-define-key 'normal nov-mode-map diff --git a/evil-collection-occur.el b/evil-collection-occur.el index dbe8476..ec3f3ab 100644 --- a/evil-collection-occur.el +++ b/evil-collection-occur.el @@ -32,6 +32,9 @@ (when (> emacs-major-version 25) (require 'replace)) +(defconst evil-collection-occur-maps '(occur-mode-map + occur-edit-mode-map)) + (defun evil-collection-occur-setup () "Set up `evil' bindings for `occur'." (evil-set-initial-state 'occur-mode 'normal) diff --git a/evil-collection-outline.el b/evil-collection-outline.el index 372855c..9dd86e6 100644 --- a/evil-collection-outline.el +++ b/evil-collection-outline.el @@ -40,6 +40,8 @@ mode." :group 'evil-collection-outline :type 'boolean) +(defconst evil-collection-outline-maps '(outline-mode-map)) + (defun evil-collection-outline-setup () "Set up `evil' bindings for `outline'." (evil-set-initial-state 'outline-mode 'normal) diff --git a/evil-collection-p4.el b/evil-collection-p4.el index 59288b0..2a5f3d4 100644 --- a/evil-collection-p4.el +++ b/evil-collection-p4.el @@ -31,6 +31,8 @@ (defvar p4-basic-mode-map) +(defconst evil-collection-p4-maps '(p4-basic-mode-map)) + (defun evil-collection-p4-setup () "Set up `evil' bindings for `p4'." (evil-set-initial-state 'p4-basic-mode 'normal) diff --git a/evil-collection-package-menu.el b/evil-collection-package-menu.el index 07f9737..bca8158 100644 --- a/evil-collection-package-menu.el +++ b/evil-collection-package-menu.el @@ -30,6 +30,8 @@ (require 'evil) (require 'package) +(defconst evil-collection-package-menu-maps '(package-menu-mode-map)) + (defun evil-collection-package-menu-setup () "Set up `evil' bindings for `package-menu'." (evil-set-initial-state 'package-menu-mode 'normal) diff --git a/evil-collection-pass.el b/evil-collection-pass.el index 410510a..0ffd004 100644 --- a/evil-collection-pass.el +++ b/evil-collection-pass.el @@ -32,6 +32,8 @@ (defvar pass-mode-map) +(defconst evil-collection-pass-maps '(pass-mode-map)) + (defun evil-collection-pass-setup () "Set up `evil' bindings for `pass-mode'." (evil-define-key 'normal pass-mode-map diff --git a/evil-collection-pdf.el b/evil-collection-pdf.el index 60ad858..ddd64f2 100644 --- a/evil-collection-pdf.el +++ b/evil-collection-pdf.el @@ -31,6 +31,10 @@ (require 'pdf-tools nil t) (require 'pdf-view nil t) +(defconst evil-collection-pdf-maps '(pdf-view-mode-map + pdf-outline-buffer-mode-map + pdf-occur-buffer-mode-map)) + (declare-function pdf-view-last-page "pdf-view") (declare-function pdf-view-first-page "pdf-view") (declare-function pdf-view-goto-page "pdf-view") diff --git a/evil-collection-popup.el b/evil-collection-popup.el index dfcfe77..fdb0ac5 100644 --- a/evil-collection-popup.el +++ b/evil-collection-popup.el @@ -24,11 +24,14 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `popup'. +;; Bindings for `popup'. + +;;; Code: (require 'evil) (require 'popup nil t) -;;; Code: +(defconst evil-collection-popup-maps '(popup-menu-keymap)) + (defun evil-collection-popup-setup () "Set up `evil' bindings for `popup'." (defvar popup-menu-keymap) diff --git a/evil-collection-proced.el b/evil-collection-proced.el index 0881cb1..e38fe8b 100644 --- a/evil-collection-proced.el +++ b/evil-collection-proced.el @@ -30,6 +30,8 @@ (require 'evil-collection-util) (require 'proced) +(defconst evil-collection-proced-maps '(proced-mode-map)) + (defun evil-collection-proced-setup () "Set up `evil' bindings for `proced'." (evil-collection-util-inhibit-insert-state proced-mode-map) diff --git a/evil-collection-prodigy.el b/evil-collection-prodigy.el index 8d3b6d1..bc6a9a6 100644 --- a/evil-collection-prodigy.el +++ b/evil-collection-prodigy.el @@ -30,6 +30,9 @@ (require 'evil) (require 'prodigy nil t) +(defconst evil-collection-prodigy-maps '(prodigy-mode-map + prodigy-view-mode-map)) + (defun evil-collection-prodigy-setup () "Set up `evil' bindings for `prodigy'." (evil-define-key 'normal prodigy-mode-map diff --git a/evil-collection-profiler.el b/evil-collection-profiler.el index aee2063..ff816a1 100644 --- a/evil-collection-profiler.el +++ b/evil-collection-profiler.el @@ -30,6 +30,8 @@ (require 'evil) (require 'profiler) +(defconst evil-collection-profiler-maps '(profiler-report-mode-map)) + (defun evil-collection-profiler-setup () "Set up `evil' bindings for `profiler'." (evil-set-initial-state 'profiler-report-mode 'normal) diff --git a/evil-collection-python.el b/evil-collection-python.el index b5a07fd..8b8a9c4 100644 --- a/evil-collection-python.el +++ b/evil-collection-python.el @@ -30,6 +30,8 @@ (require 'evil) (require 'python) +(defconst evil-collection-python-maps '(python-mode-map)) + (defun evil-collection-python-set-evil-shift-width () "Set `evil-shift-width' according to `python-indent-offset'." (setq evil-shift-width python-indent-offset)) diff --git a/evil-collection-quickrun.el b/evil-collection-quickrun.el index bc5efb6..f535f0a 100644 --- a/evil-collection-quickrun.el +++ b/evil-collection-quickrun.el @@ -24,11 +24,14 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `quickrun'. +;; Bindings for `quickrun'. + +;;; Code: (require 'evil) (require 'quickrun nil t) -;;; Code: +(defconst evil-collection-quickrun-maps '(quickrun--mode-map)) + (defun evil-collection-quickrun-setup () "Set up `evil' bindings for `quickrun'.." (evil-define-key 'normal quickrun--mode-map diff --git a/evil-collection-racer.el b/evil-collection-racer.el index 5c02e94..ed792a6 100644 --- a/evil-collection-racer.el +++ b/evil-collection-racer.el @@ -24,12 +24,15 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `racer'. +;; Bindings for `racer'. ;;; Code: (require 'evil) (require 'racer nil t) +(defconst evil-collection-racer-maps '(racer-mode-map + racer-help-mode-map)) + (defun evil-collection-racer-setup () "Set up `evil' bindings for `racer'." (evil-define-key 'normal racer-mode-map diff --git a/evil-collection-realgud.el b/evil-collection-realgud.el index 1e0769c..a795ed1 100644 --- a/evil-collection-realgud.el +++ b/evil-collection-realgud.el @@ -24,11 +24,14 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `realgud'. +;; Bindings for `realgud'. + +;;; Code: (require 'evil) (require 'realgud nil t) -;;; Code: +(defconst evil-collection-realgud-maps '(realgud:shortkey-mode-map)) + (defun evil-collection-realgud-setup () "Set up `evil' bindings for `realgud'." ;; This one is to represent `realgud-populate-src-buffer-map-plain'. diff --git a/evil-collection-reftex.el b/evil-collection-reftex.el index 2adbf96..f234ce4 100644 --- a/evil-collection-reftex.el +++ b/evil-collection-reftex.el @@ -32,6 +32,9 @@ (require 'reftex-ref nil t) (require 'reftex-cite nil t) +(defconst evil-collection-reftex-maps '(reftex-select-shared-map + reftex-toc-mode-map)) + ;; original code can be found in reftex-ref.el (setq reftex-select-label-prompt "Select: [RET]select [j]next [k]previous [gr]escan [go]context [q]uit [g?]help") diff --git a/evil-collection-rjsx-mode.el b/evil-collection-rjsx-mode.el index 4ec049d..7c92937 100644 --- a/evil-collection-rjsx-mode.el +++ b/evil-collection-rjsx-mode.el @@ -32,6 +32,8 @@ (defvar rjsx-mode-map) +(defconst evil-collection-rjsx-maps '(rjsx-mode-map)) + (defun evil-collection-rjsx-mode-setup () "Set up `evil' bindings for `rjsx-mode'." (when evil-want-C-d-scroll diff --git a/evil-collection-robe.el b/evil-collection-robe.el index aa645a6..372f19c 100644 --- a/evil-collection-robe.el +++ b/evil-collection-robe.el @@ -30,6 +30,8 @@ (require 'evil) (require 'robe nil t) +(defconst evil-collection-robe-maps '(robe-mode-map)) + (defun evil-collection-robe-setup () "Set up `evil' bindings for `robe'." (evil-define-key 'normal robe-mode-map diff --git a/evil-collection-rtags.el b/evil-collection-rtags.el index 1eaaf41..d5aec86 100644 --- a/evil-collection-rtags.el +++ b/evil-collection-rtags.el @@ -35,6 +35,11 @@ (defvar rtags-references-tree-mode-map) (defvar rtags-location-stack-visualize-mode-map) +(defconst evil-collection-rtags-maps '(rtags-mode-map + rtags-dependency-tree-mode-map + rtags-references-tree-mode-map + rtags-location-stack-visualize-mode-map)) + (defun evil-collection-rtags-setup () "Set up `evil' bindings for `rtags'." (evil-set-initial-state 'rtags-mode 'normal) diff --git a/evil-collection-ruby-mode.el b/evil-collection-ruby-mode.el index 994aaf9..979bd6e 100644 --- a/evil-collection-ruby-mode.el +++ b/evil-collection-ruby-mode.el @@ -30,6 +30,8 @@ (require 'evil) (require 'ruby-mode) +(defconst evil-collection-ruby-mode-maps nil) + (defun evil-collection-ruby-mode-set-evil-shift-width () "Set `evil-shift-width' according to `ruby-indent-level'." (setq evil-shift-width ruby-indent-level)) diff --git a/evil-collection-simple.el b/evil-collection-simple.el index d50bb61..23326ed 100644 --- a/evil-collection-simple.el +++ b/evil-collection-simple.el @@ -24,14 +24,16 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `simple' +;; Bindings for `simple' +;;; Code: (require 'evil) (require 'simple) (defvar special-mode-map) -;;; Code: +(defconst evil-collection-simple-maps '(special-mode-map)) + (defun evil-collection-simple-setup () "Set up `evil' bindings for `simple'." (evil-define-key '(normal visual) special-mode-map diff --git a/evil-collection-slime.el b/evil-collection-slime.el index cb9a083..d7076c0 100644 --- a/evil-collection-slime.el +++ b/evil-collection-slime.el @@ -37,6 +37,13 @@ (defvar slime-popup-buffer-mode-map) (defvar slime-xref-mode-map) +(defconst evil-collection-slime-maps '(slime-parent-map + sldb-mode-map + slime-inspector-mode-map + slime-mode-map + slime-popup-buffer-mode-map + slime-xref-mode-map )) + (defun evil-collection-slime-last-sexp (command &rest args) "In normal-state or motion-state, last sexp ends at point." (if (and (not evil-move-beyond-eol) diff --git a/evil-collection-term.el b/evil-collection-term.el index 8606b80..e4b5445 100644 --- a/evil-collection-term.el +++ b/evil-collection-term.el @@ -60,6 +60,9 @@ This is only used if `evil-collection-term-sync-state-and-mode-p' is true." ;; TODO: Add support for normal-state editing. +(defconst evil-collection-term-maps '(term-raw-map + term-mode-map)) + (defun evil-collection-term-escape-stay () "Go back to normal state but don't move cursor backwards. Moving cursor backwards is the default Vim behavior but diff --git a/evil-collection-tide.el b/evil-collection-tide.el index 58b4166..8b224ab 100644 --- a/evil-collection-tide.el +++ b/evil-collection-tide.el @@ -30,6 +30,10 @@ (require 'tide nil t) (require 'evil) +(defconst evil-collection-tide-maps '(tide-mode-map + tide-references-mode-map + tide-project-errors-mode-map)) + (defun evil-collection-tide-setup () "Set up `evil' bindings for `tide'." (evil-define-key 'normal tide-mode-map diff --git a/evil-collection-transmission.el b/evil-collection-transmission.el index e208cdc..72faa58 100644 --- a/evil-collection-transmission.el +++ b/evil-collection-transmission.el @@ -36,6 +36,11 @@ (defvar transmission-info-mode-map) (defvar transmission-peers-mode-map) +(defconst evil-collection-transmission-maps '(transmission-mode-map + transmission-files-mode-map + transmission-info-mode-map + transmission-peers-mode-map)) + (defun evil-collection-transmission-setup () "Set up `evil' bindings for `transmission'." diff --git a/evil-collection-vc-annotate.el b/evil-collection-vc-annotate.el index 8522984..f239c17 100644 --- a/evil-collection-vc-annotate.el +++ b/evil-collection-vc-annotate.el @@ -24,11 +24,14 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Bindings for `vc-annotate' +;; Bindings for `vc-annotate' + +;;; Code: (require 'evil) (require 'vc-annotate) -;;; Code: +(defconst evil-collection-vc-annotate-maps '(vc-annotate-mode-map)) + (defun evil-collection-vc-annotate-setup () "Set up `evil' bindings for `vc-annotate'." (evil-set-initial-state 'vc-annotate-mode 'normal) diff --git a/evil-collection-view.el b/evil-collection-view.el index 0a68e77..074b965 100644 --- a/evil-collection-view.el +++ b/evil-collection-view.el @@ -24,12 +24,14 @@ ;; along with this program. If not, see . ;;; Commentary: -;;; Evil bindings for View. +;; Evil bindings for View. ;;; Code: (require 'evil) (require 'view) +(defconst evil-collection-view-maps '(view-mode-map)) + (defun evil-collection-view-setup () "Set up `evil' bindings for `view'." (evil-set-initial-state 'view-mode 'normal) diff --git a/evil-collection-vlf.el b/evil-collection-vlf.el index 2cc6bbb..6ddd663 100644 --- a/evil-collection-vlf.el +++ b/evil-collection-vlf.el @@ -33,6 +33,8 @@ (defvar vlf-mode-map) (declare-function vlf-change-batch-size "vlf") +(defconst evil-collection-vlf-maps '(vlf-mode-map)) + (defun evil-collection-vlf-decrease-batch-size () "Decrease vlf batch size by factor of 2." (interactive) diff --git a/evil-collection-which-key.el b/evil-collection-which-key.el index 12f5e4f..38ef7a1 100644 --- a/evil-collection-which-key.el +++ b/evil-collection-which-key.el @@ -33,6 +33,8 @@ (defvar which-key-C-h-map) +(defconst evil-collection-which-key-maps '(which-key-C-h-map)) + ;; `which-key'is coded so that the prompt properly shows j and k as ;; the bindings. (defun evil-collection-which-key-setup () diff --git a/evil-collection-woman.el b/evil-collection-woman.el index eec3349..9f5fa21 100644 --- a/evil-collection-woman.el +++ b/evil-collection-woman.el @@ -31,6 +31,8 @@ (require 'evil-collection-man) ; WoMan's keymap inherits from Man. (require 'woman) +(defconst evil-collection-woman-maps '(woman-mode-map)) + (defun evil-collection-woman-setup () "Set up `evil' bindings for `woman'." (evil-set-initial-state 'woman-mode 'normal) diff --git a/evil-collection-xref.el b/evil-collection-xref.el index a1e4429..d1db2a1 100644 --- a/evil-collection-xref.el +++ b/evil-collection-xref.el @@ -30,6 +30,8 @@ (require 'evil) (require 'xref) +(defconst evil-collection-xref-maps '(xref--xref-buffer-mode-map)) + (defun evil-collection-xref-setup () "Set up `evil' bindings for `xref'." (evil-define-key 'normal xref--xref-buffer-mode-map diff --git a/evil-collection-ztree.el b/evil-collection-ztree.el index 94efc26..f7047ff 100644 --- a/evil-collection-ztree.el +++ b/evil-collection-ztree.el @@ -32,6 +32,8 @@ (defvar ztree-mode-map) (defvar ztreediff-mode-map) +(defconst evil-collection-ztree-maps '(ztree-mode-map ztreediff-mode-map)) + (defun evil-collection-ztree-setup () "Set up `evil' bindings for `ztree'." diff --git a/evil-collection.el b/evil-collection.el index 225d5fe..d3a492a 100644 --- a/evil-collection.el +++ b/evil-collection.el @@ -8,7 +8,7 @@ ;; Pierre Neidhardt ;; URL: https://github.com/emacs-evil/evil-collection ;; Version: 0.0.1 -;; Package-Requires: ((emacs "25.1") (evil "1.2.13")) +;; Package-Requires: ((emacs "25.1") (cl-lib "0.5") (evil "1.2.13")) ;; Keywords: evil, tools ;; This program is free software; you can redistribute it and/or modify @@ -32,7 +32,7 @@ ;; This is so because many users find it confusing. ;;; Code: - +(require 'cl-lib) (require 'evil) (defvar evil-want-integration) @@ -158,6 +158,98 @@ this confusing. It will be included if :type '(repeat (choice symbol sexp)) :group 'evil-collection) +(defvar evil-collection-setup-hook nil + "Hook run by `evil-collection-init' for each mode that is evilified. +This hook runs after all setup (including keybindings) for a mode has already +taken place. The arguments passed to functions for this hook are the name of the +mode and a list of keymap names (i.e. symbols, not actual keymaps) customized by +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 +compatibility.") + +(defun evil-collection--translate-key (state keymap-symbol + translations + destructive) + "Helper function for `evil-collection-translate-key'. +In the keymap corresponding to STATE and KEYMAP-SYMBOL, make the key +TRANSLATIONS. When DESTRUCTIVE is non-nil, make the TRANSLATIONS destructively +without creating/referencing a backup keymap." + (let* ((backup-keymap-symbol (intern (format "evil-collection-%s%s-backup-map" + keymap-symbol + (if state + (format "-%s-state" state) + "")))) + (keymap (symbol-value keymap-symbol)) + (lookup-keymap (if (and (not destructive) + (boundp backup-keymap-symbol)) + (symbol-value backup-keymap-symbol) + (copy-keymap + (if state + (evil-get-auxiliary-keymap keymap state t t) + keymap)))) + (maps (cl-loop for (key replacement) on translations by 'cddr + ;; :destructive can be in TRANSLATIONS + unless (keywordp key) + collect key + and collect (when replacement + (lookup-key lookup-keymap replacement))))) + (unless (or destructive + (boundp backup-keymap-symbol)) + (set backup-keymap-symbol lookup-keymap)) + (apply #'evil-define-key* state keymap maps))) + +;;;###autoload +(cl-defun evil-collection-translate-key (states keymaps + &rest translations + &key destructive + &allow-other-keys) + "Translate keys in the keymap(s) corresponding to STATES and KEYMAPS. +STATES should be the name of an evil state, a list of states, or nil. KEYMAPS +should be a symbol corresponding to the keymap to make the translations in or a +list of keymap symbols. Like `evil-define-key', when a keymap does not exist, +the keybindings will be deferred until the keymap is defined, so +`with-eval-after-load' is not neccessary. TRANSLATIONS corresponds to a list of +key replacement pairs. For example, specifying \"a\" \"b\" will bind \"a\" to +\"b\"'s definition in the keymap. Specifying nil as a replacement will unbind a +key. If DESTRUCTIVE is nil, a backup of the keymap will be stored on the initial +invocation, and future invocations will always look up keys in the backup +keymap. When no TRANSLATIONS are given, this function will only create the +backup keymap without making any translations. On the other hand, if DESTRUCTIVE +is non-nil, the keymap will be destructively altered without creating a backup. +For example, calling this function multiple times with \"a\" \"b\" \"b\" \"a\" +would continue to swap and unswap the definitions of these keys. This means that +when DESTRUCTIVE is non-nil, all related swaps/cycles should be done in the same +invocation." + (declare (indent defun)) + (unless (listp keymaps) + (setq keymaps (list keymaps))) + (unless (and (listp states) + (not (null states))) + (setq states (list states))) + (dolist (keymap-symbol keymaps) + (dolist (state states) + (evil-delay `(and (boundp ',keymap-symbol) + (keymapp ,keymap-symbol)) + `(evil-collection--translate-key ',state ',keymap-symbol + ',translations ,destructive) + 'after-load-functions t nil + (symbol-name (cl-gensym (format "evil-collection-translate-key-in-%s" + keymap-symbol))))))) + +;;;###autoload +(defmacro evil-collection-swap-key (states keymaps &rest args) + "Wrapper around `evil-collection-translate-key' for swapping keys. +STATES, KEYMAPS, and ARGS are passed to `evil-collection-translate-key'. ARGS +should consist of key swaps (e.g. \"a\" \"b\" is equivalent to \"a\" \"b\" \"b\" +\"a\" with `evil-collection-translate-key') and optionally keyword arguments for +`evil-collection-translate-key'." + (declare (indent defun)) + (setq args (cl-loop for (key replacement) on args by 'cddr + collect key and collect replacement + and unless (keywordp key) + collect replacement and collect key)) + `(evil-collection-translate-key ,states ,keymaps ,@args)) + ;;;###autoload (defun evil-collection-init () "Register the Evil bindings for all modes in `evil-collection-mode-list'. @@ -178,7 +270,14 @@ instance: (dolist (req reqs) (with-eval-after-load req (require (intern (concat "evil-collection-" (symbol-name m)))) - (funcall (intern (concat "evil-collection-" (symbol-name m) "-setup")))))))) + (funcall (intern (concat "evil-collection-" (symbol-name m) + "-setup"))) + (let ((mode-keymaps + (ignore-errors + (symbol-value + (intern (format "evil-collection-%s-maps" m)))))) + (run-hook-with-args 'evil-collection-setup-hook + m mode-keymaps))))))) (defvar evil-collection-delete-operators '(evil-delete evil-cp-delete diff --git a/readme.org b/readme.org index e4f5cfd..ad1fe01 100644 --- a/readme.org +++ b/readme.org @@ -384,6 +384,122 @@ definition". - ~f11~ Step Into - ~S-f11~ Step Out +** Key Translation +~evil-collection-translate-key~ allows binding a key to the definition of +another key in the same keymap (comparable to how vim's keybindings work). Its +arguments are the ~states~ and ~keymaps~ to bind/look up the key(s) in followed +optionally by keyword arguments (currently only ~:destructive~) and +key/replacement pairs. ~states~ should be nil for non-evil keymaps, and both +~states~ and ~keymaps~ can be a single symbol or a list of symbols. + +This function can be useful for making key swaps/cycles en masse. For example, +someone who uses an alternate keyboard layout may want to retain the ~hjkl~ +positions for directional movement in dired, the calendar, etc. + +Here's an example for Colemak of making swaps in a single keymap: +#+begin_src emacs-lisp +(evil-collection-translate-key nil 'evil-motion-state-map + ;; colemak hnei is qwerty hjkl + "n" "j" + "e" "k" + "i" "l" + ;; add back nei + "j" "e" + "k" "n" + "l" "i") +#+end_src + +Here's an example of using ~evil-collection-setup-hook~ to cycle the keys for +all modes in ~evil-collection-mode-list~: +#+begin_src emacs-lisp +(defun my-hjkl-rotation (_mode mode-keymaps &rest _rest) + (evil-collection-translate-key 'normal mode-keymaps + "n" "j" + "e" "k" + "i" "l" + "j" "e" + "k" "n" + "l" "i")) + +;; called after evil-collection makes its keybindings +(add-hook 'evil-collection-setup-hook #'my-hjkl-rotation) + +(evil-collection-init) +#+end_src + +A more common use case of ~evil-collection-translate-key~ would be for keeping +the functionality of some keys that users may bind globally. For example, ~SPC~, +~[~, and ~]~ are bound in some modes. If you use these keys as global prefix +keys that you never want to be overriden, you'll want to give them higher +priority than other evil keybindings (e.g. those made by ~(evil-define-key +'normal some-map ...)~). To do this, you can create an "intercept" map and bind +your prefix keys in it instead of in ~evil-normal-state-map~: +#+begin_src emacs-lisp +(defvar my-intercept-mode-map (make-sparse-keymap) + "High precedence keymap.") + +(define-minor-mode my-intercept-mode + "Global minor mode for higher precedence evil keybindings." + :global t) + +(my-intercept-mode) + +(dolist (state '(normal visual insert)) + (evil-make-intercept-map + ;; NOTE: This requires an evil version from 2018-03-20 or later + (evil-get-auxiliary-keymap my-intercept-mode-map state t t) + state)) + +(evil-define-key 'normal my-intercept-mode-map + (kbd "SPC f") 'find-file) +;; ... +#+end_src + +You can then define replacement keys: +#+begin_src emacs-lisp +(defun my-prefix-translations (_mode mode-keymaps &rest _rest) + (evil-collection-translate-key 'normal mode-keymaps + "C-SPC" "SPC" + ;; these need to be unbound first; this needs to be in same statement + "[" nil + "]" nil + "[[" "[" + "]]" "]")) + +(add-hook 'evil-collection-setup-hook #'my-prefix-translation) + +(evil-collection-init) +#+end_src + +By default, the first invocation of ~evil-collection-translate-key~ will make a +backup of the keymap. Each subsequent invocation will look up keys in the backup +instead of the original. This means that a call to +~evil-collection-translate-key~ will always have the same behavior even if +evaluated multiple times. When ~:destructive t~ is specified, keys are looked up +in the keymap as it is currently. This means that a call to +~evil-collection-translate-key~ that swapped two keys would continue to +swap/unswap them with each call. Therefore when ~:destructive t~ is used, all +cycles/swaps must be done within a single call to +~evil-collection-translate-key~. To make a comparison to Vim keybindings, +~:destructive t~ is comparable to Vim's ~map~, and ~:destructive nil~ is +comparable to vim's ~noremap~ (where the "original" keybindings are those that +existed in the keymap when ~evil-collection-translate-key~ was first called). +You'll almost always want to use the default behavior (especially in your init +file). The limitation of ~:destructive nil~ is that you can't translate a key to +another key that was defined after the first ~evil-collection-translate-key~, so +~:destructive t~ may be useful for interactive experimentation. + +~evil-collection-swap-key~ is also provided as a wrapper around +~evil-colletion-translate-key~ that allows swapping keys: +#+begin_src emacs-lisp +(evil-collection-swap-key nil 'evil-motion-state-map + ";" ":") +;; is equivalent to +(evil-collection-translate-key nil 'evil-motion-state-map + ";" ":" + ":" ";") +#+end_src + ** Modes left behind Some modes might still remain unsupported by this package. Should you be