From 2aa1038e0b4cae15dc158c22f5c98adf9276b6b0 Mon Sep 17 00:00:00 2001 From: roryk Date: Fri, 25 Apr 2014 15:49:22 -0400 Subject: [PATCH] Add prelude-evil. A reasonable default setup for using evil-mode with prelude. --- README.md | 5 ++ modules/prelude-evil.el | 123 ++++++++++++++++++++++++++++++++++++++ sample/prelude-modules.el | 1 + 3 files changed, 129 insertions(+) create mode 100644 modules/prelude-evil.el diff --git a/README.md b/README.md index 669809c..19e9825 100644 --- a/README.md +++ b/README.md @@ -388,6 +388,11 @@ If you're an `evil-mode` user you'll probably do well to disable `key-chord-mode (key-chord-mode -1) ``` +#### vim emulation + +If you want to use vim inside of emacs enable the `prelude-evil` module which provides +support for `evil-mode`. + ## Automatic package installation The default Prelude installation comes with a bare minimum of diff --git a/modules/prelude-evil.el b/modules/prelude-evil.el new file mode 100644 index 0000000..803daf7 --- /dev/null +++ b/modules/prelude-evil.el @@ -0,0 +1,123 @@ +;;; prelude-evil.el --- Emacs Prelude: evil-mode configuration. +;; +;; Copyright © 2011-2013 Bozhidar Batsov +;; +;; Author: Bozhidar Batsov +;; URL: http://batsov.com/prelude +;; Version: 1.0.0 +;; Keywords: convenience + +;; This file is not part of GNU Emacs. + +;;; Commentary: + +;; Some basic configuration for evil-mode. + +;;; License: + +;; This program 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. +;; +;; This program 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 GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Code: + +;;; goto-chg lets you use the g-; and g-, to go to recent changes +;;; evil-visualstar enables searching visual selection with * +;;; evil-numbers enables vim style numeric incrementing and decrementing + +(prelude-require-packages '(evil goto-chg surround evil-visualstar evil-numbers)) + +(setq evil-mode-line-format 'before) + +(setq evil-emacs-state-cursor '("red" box)) +(setq evil-normal-state-cursor '("gray" box)) +(setq evil-visual-state-cursor '("gray" box)) +(setq evil-insert-state-cursor '("gray" bar)) +(setq evil-motion-state-cursor '("gray" box)) + +(evil-mode 1) +(global-surround-mode 1) + +(define-key evil-normal-state-map (kbd "C-A") + 'evil-numbers/inc-at-pt) +(define-key evil-normal-state-map (kbd "C-S-A") + 'evil-numbers/dec-at-pt) + +;; +;; Other useful Commands +;; +(evil-ex-define-cmd "W" 'evil-write-all) +(evil-ex-define-cmd "Tree" 'speedbar-get-focus) +(evil-ex-define-cmd "linum" 'linum-mode) +(evil-ex-define-cmd "Align" 'align-regexp) + + +;; Scrolling +(defun prelude-evil-scroll-down-other-window () + (interactive) + (scroll-other-window)) + +(defun prelude-evil-scroll-up-other-window () + (interactive) + (scroll-other-window '-)) + +(define-key evil-normal-state-map + (kbd "C-S-d") 'prelude-evil-scroll-down-other-window) + +(define-key evil-normal-state-map + (kbd "C-S-u") 'prelude-evil-scroll-up-other-window) + +;; +;; Magit from avsej +;; +(evil-add-hjkl-bindings magit-log-mode-map 'emacs) +(evil-add-hjkl-bindings magit-commit-mode-map 'emacs) +(evil-add-hjkl-bindings magit-branch-manager-mode-map 'emacs + "K" 'magit-discard-item + "L" 'magit-key-mode-popup-logging) +(evil-add-hjkl-bindings magit-status-mode-map 'emacs + "K" 'magit-discard-item + "l" 'magit-key-mode-popup-logging + "h" 'magit-toggle-diff-refine-hunk) + +(setq evil-shift-width 2) + +;;; enable ace-jump mode with evil-mode +(define-key evil-normal-state-map (kbd "SPC") 'ace-jump-mode) + +;;; snagged from Eric S. Fraga +;;; http://lists.gnu.org/archive/html/emacs-orgmode/2012-05/msg00153.html +(defun prelude-evil-key-bindings-for-org () + ;;(message "Defining evil key bindings for org") + (evil-declare-key 'normal org-mode-map + "gk" 'outline-up-heading + "gj" 'outline-next-visible-heading + "H" 'org-beginning-of-line ; smarter behaviour on headlines etc. + "L" 'org-end-of-line ; smarter behaviour on headlines etc. + "t" 'org-todo ; mark a TODO item as DONE + ",c" 'org-cycle + (kbd "TAB") 'org-cycle + ",e" 'org-export-dispatch + ",n" 'outline-next-visible-heading + ",p" 'outline-previous-visible-heading + ",t" 'org-set-tags-command + ",u" 'outline-up-heading + "$" 'org-end-of-line ; smarter behaviour on headlines etc. + "^" 'org-beginning-of-line ; ditto + "-" 'org-ctrl-c-minus ; change bullet style + "<" 'org-metaleft ; out-dent + ">" 'org-metaright ; indent + )) +(prelude-evil-key-bindings-for-org) +(provide 'prelude-evil) diff --git a/sample/prelude-modules.el b/sample/prelude-modules.el index 840d042..674ab4b 100644 --- a/sample/prelude-modules.el +++ b/sample/prelude-modules.el @@ -25,6 +25,7 @@ ;; (require 'prelude-scala) (require 'prelude-scheme) (require 'prelude-shell) +;; (require 'prelude-evil) ;; (require 'prelude-scss) ;; (require 'prelude-web) ;; Emacs mode for web templates (require 'prelude-xml)