From 6ea7d98a57aae1c654fcd772bdf78d579229f199 Mon Sep 17 00:00:00 2001 From: James Nguyen Date: Mon, 10 Sep 2018 19:05:12 -0700 Subject: [PATCH] Split keybindings out from evil-integration --- evil-integration.el | 87 +++---------------------------- evil-keybindings.el | 121 ++++++++++++++++++++++++++++++++++++++++++++ evil-vars.el | 10 ++++ evil.el | 3 ++ 4 files changed, 140 insertions(+), 81 deletions(-) create mode 100644 evil-keybindings.el diff --git a/evil-integration.el b/evil-integration.el index bc086111..4fd63886 100644 --- a/evil-integration.el +++ b/evil-integration.el @@ -25,6 +25,12 @@ ;; You should have received a copy of the GNU General Public License ;; along with Evil. If not, see . + +;;; Commentary: +;; This provides evil integration for various emacs modes. +;; Additional keybindings (or default state) should go into evil-keybindings.el. +;; If you want to use Evil in the minibuffer, you'll have to enable it by + (require 'evil-maps) (require 'evil-core) (require 'evil-macros) @@ -90,63 +96,12 @@ (when (fboundp 'evil-repeat-abort) (evil-repeat-abort))) -;; etags-select -;; FIXME: probably etags-select should be recomended in docs -(eval-after-load 'etags-select - '(progn - (define-key evil-motion-state-map "g]" 'etags-select-find-tag-at-point))) - -;;; Buffer-menu - -(evil-add-hjkl-bindings Buffer-menu-mode-map 'motion) - -;; dictionary.el - -(evil-add-hjkl-bindings dictionary-mode-map 'motion - "?" 'dictionary-help ; "h" - "C-o" 'dictionary-previous) ; "l" - -;;; Dired - -(eval-after-load 'dired - '(progn - ;; use the standard Dired bindings as a base - (defvar dired-mode-map) - (evil-make-overriding-map dired-mode-map 'normal) - (evil-add-hjkl-bindings dired-mode-map 'normal - "J" 'dired-goto-file ; "j" - "K" 'dired-do-kill-lines ; "k" - "r" 'dired-do-redisplay ; "l" - ;; ":d", ":v", ":s", ":e" - ";" (lookup-key dired-mode-map ":")))) - (eval-after-load 'wdired '(progn (add-hook 'wdired-mode-hook #'evil-change-to-initial-state) (defadvice wdired-change-to-dired-mode (after evil activate) (evil-change-to-initial-state nil t)))) -;;; ELP - -(eval-after-load 'elp - '(defadvice elp-results (after evil activate) - (evil-motion-state))) - -;;; ERT - -(evil-add-hjkl-bindings ert-results-mode-map 'motion) - -;;; Info - -(evil-add-hjkl-bindings Info-mode-map 'motion - "0" 'evil-digit-argument-or-evil-beginning-of-line - (kbd "\M-h") 'Info-help ; "h" - "\C-t" 'Info-history-back ; "l" - "\C-o" 'Info-history-back - " " 'Info-scroll-up - "\C-]" 'Info-follow-nearest-node - (kbd "DEL") 'Info-scroll-down) - ;;; Parentheses (defadvice show-paren-function (around evil disable) @@ -184,29 +139,6 @@ (let ((ov (and (boundp ov) (symbol-value ov)))) (when (overlayp ov) (delete-overlay ov)))))))) -;;; Speedbar - -(evil-add-hjkl-bindings speedbar-key-map 'motion - "h" 'backward-char - "j" 'speedbar-next - "k" 'speedbar-prev - "l" 'forward-char - "i" 'speedbar-item-info - "r" 'speedbar-refresh - "u" 'speedbar-up-directory - "o" 'speedbar-toggle-line-expansion - (kbd "RET") 'speedbar-edit-line) - -;; Ibuffer -(eval-after-load 'ibuffer - '(progn - (defvar ibuffer-mode-map) - (evil-make-overriding-map ibuffer-mode-map 'normal) - (evil-define-key 'normal ibuffer-mode-map - "j" 'evil-next-line - "k" 'evil-previous-line - "RET" 'ibuffer-visit-buffer))) - ;;; Undo tree (when (and (require 'undo-tree nil t) (fboundp 'global-undo-tree-mode)) @@ -556,13 +488,6 @@ Based on `evil-enclose-ace-jump-for-motion'." '(with-no-warnings (push 'evil-mode-cmhh mumamo-change-major-mode-no-nos))) -;;; ag.el -(eval-after-load 'ag - '(progn - (defvar ag-mode-map) - (add-to-list 'evil-motion-state-modes 'ag-mode) - (evil-add-hjkl-bindings ag-mode-map 'motion))) - ;; visual-line-mode integration (when evil-respect-visual-line-mode (let ((swaps '((evil-next-line . evil-next-visual-line) diff --git a/evil-keybindings.el b/evil-keybindings.el new file mode 100644 index 00000000..dbd5013a --- /dev/null +++ b/evil-keybindings.el @@ -0,0 +1,121 @@ +;;; evil-keybindings.el --- Add some Evil keybindings to other modules + +;; Author: Vegard Øye +;; Maintainer: Vegard Øye + +;; Version: 1.2.13 + +;; +;; This file is NOT part of GNU Emacs. + +;;; License: + +;; This file is part of Evil. +;; +;; Evil is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; Evil is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with Evil. If not, see . + +;;; Commentary: +;; This provides a set of keybindings for other emacs modes. This also includes +;; setting up the initial evil state of those other modes. + +(require 'evil-maps) +(require 'evil-core) +(require 'evil-macros) +(require 'evil-types) +(require 'evil-repeat) + +;; etags-select +;; FIXME: probably etags-select should be recomended in docs +(eval-after-load 'etags-select + '(progn + (define-key evil-motion-state-map "g]" 'etags-select-find-tag-at-point))) + +;;; Buffer-menu + +(evil-add-hjkl-bindings Buffer-menu-mode-map 'motion) + +;; dictionary.el + +(evil-add-hjkl-bindings dictionary-mode-map 'motion + "?" 'dictionary-help ; "h" + "C-o" 'dictionary-previous) ; "l" + +;;; Dired + +(eval-after-load 'dired + '(progn + ;; use the standard Dired bindings as a base + (defvar dired-mode-map) + (evil-make-overriding-map dired-mode-map 'normal) + (evil-add-hjkl-bindings dired-mode-map 'normal + "J" 'dired-goto-file ; "j" + "K" 'dired-do-kill-lines ; "k" + "r" 'dired-do-redisplay ; "l" + ;; ":d", ":v", ":s", ":e" + ";" (lookup-key dired-mode-map ":")))) + +;;; ERT + +(evil-add-hjkl-bindings ert-results-mode-map 'motion) + +;;; Info + +(evil-add-hjkl-bindings Info-mode-map 'motion + "0" 'evil-digit-argument-or-evil-beginning-of-line + (kbd "\M-h") 'Info-help ; "h" + "\C-t" 'Info-history-back ; "l" + "\C-o" 'Info-history-back + " " 'Info-scroll-up + "\C-]" 'Info-follow-nearest-node + (kbd "DEL") 'Info-scroll-down) + +;;; Speedbar + +(evil-add-hjkl-bindings speedbar-key-map 'motion + "h" 'backward-char + "j" 'speedbar-next + "k" 'speedbar-prev + "l" 'forward-char + "i" 'speedbar-item-info + "r" 'speedbar-refresh + "u" 'speedbar-up-directory + "o" 'speedbar-toggle-line-expansion + (kbd "RET") 'speedbar-edit-line) + +;; Ibuffer +(eval-after-load 'ibuffer + '(progn + (defvar ibuffer-mode-map) + (evil-make-overriding-map ibuffer-mode-map 'normal) + (evil-define-key 'normal ibuffer-mode-map + "j" 'evil-next-line + "k" 'evil-previous-line + "RET" 'ibuffer-visit-buffer))) + +;;; ag.el +(eval-after-load 'ag + '(progn + (defvar ag-mode-map) + (add-to-list 'evil-motion-state-modes 'ag-mode) + (evil-add-hjkl-bindings ag-mode-map 'motion))) + +;;; ELP + +(eval-after-load 'elp + '(defadvice elp-results (after evil activate) + (evil-motion-state))) + +(provide 'evil-keybindings) + +;;; evil-keybindings.el ends here diff --git a/evil-vars.el b/evil-vars.el index 25644a2f..d93fc83b 100644 --- a/evil-vars.el +++ b/evil-vars.el @@ -1877,6 +1877,16 @@ This variable must be set before Evil is loaded." :type 'boolean :group 'evil) +(defcustom evil-want-keybinding t + "Whether to load evil-keybindings.el. + +This loads a set of keybindings for evil in other modes as well as +setting the initial evil state in those modes. + +This variable must be set before evil is loaded." + :type 'boolean + :group 'evil) + (defcustom evil-want-minibuffer nil "Whether to enable Evil in minibuffer(s)." :type 'boolean diff --git a/evil.el b/evil.el index 5c9e54a7..dcfd97c4 100644 --- a/evil.el +++ b/evil.el @@ -141,6 +141,9 @@ (when evil-want-integration (require 'evil-integration)) +(when evil-want-keybinding + (require 'evil-keybindings)) + (run-hooks 'evil-after-load-hook) (provide 'evil)