Add key translation functionality

Also add evil-collection-setup-hook. Fixes #5 and #98.
This commit is contained in:
noctuid 2017-12-17 22:26:31 -05:00 committed by Pierre Neidhardt
parent 488b3d8fe7
commit 1853b53a8d
84 changed files with 483 additions and 20 deletions

View File

@ -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

View File

@ -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)

View File

@ -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.

View File

@ -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)

View File

@ -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)

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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'."

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -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 "<tab>") 'widget-forward

View File

@ -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)

View File

@ -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)

View File

@ -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'."

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -24,11 +24,15 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -24,12 +24,19 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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

View File

@ -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)

View File

@ -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

View File

@ -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))

View File

@ -24,11 +24,14 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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

View File

@ -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))

View File

@ -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.

View File

@ -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)

View File

@ -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.

View File

@ -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'."

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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")

View File

@ -24,11 +24,14 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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))

View File

@ -24,11 +24,14 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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

View File

@ -24,12 +24,15 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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

View File

@ -24,11 +24,14 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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'.

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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))

View File

@ -24,14 +24,16 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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'."

View File

@ -24,11 +24,14 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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)

View File

@ -24,12 +24,14 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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)

View File

@ -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)

View File

@ -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 ()

View File

@ -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)

View File

@ -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

View File

@ -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'."

View File

@ -8,7 +8,7 @@
;; Pierre Neidhardt <ambrevar@gmail.com>
;; 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

View File

@ -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