|
1 | 1 | ;;; holy-mode.el --- Enter the church of Emacs
|
2 | 2 |
|
3 |
| -;; Copyright (C) 2012-2016 Sylvain Benner & Contributors |
| 3 | +;; Copyright (C) 2014-2015 syl20bnr |
4 | 4 | ;;
|
5 | 5 | ;; Author: Sylvain Benner <[email protected]>
|
6 | 6 | ;; Keywords: convenience editing
|
|
28 | 28 |
|
29 | 29 | ;;; Code:
|
30 | 30 |
|
31 |
| -(defvar holy-mode-modes-to-disable-alist |
32 |
| - `((evil-mode . 1) |
33 |
| - (hybrid-mode . -1) |
34 |
| - (evil-escape-mode . ,(if (boundp 'evil-escape-mode) evil-escape-mode -1))) |
35 |
| - "Alist of modes that should be disabled when activating |
36 |
| -`holy-mode'. The cdr in each cell stores the state of the mode |
37 |
| -before it was disabled.") |
| 31 | +(defadvice evil-insert-state (around holy-insert-to-emacs-state disable) |
| 32 | + "Forces Emacs state." |
| 33 | + (if (equal -1 (ad-get-arg 0)) |
| 34 | + ad-do-it |
| 35 | + (evil-emacs-state))) |
| 36 | + |
| 37 | +(defadvice evil-motion-state (around holy-motion-to-emacs-state disable) |
| 38 | + "Forces Emacs state." |
| 39 | + (if (equal -1 (ad-get-arg 0)) |
| 40 | + ad-do-it |
| 41 | + (evil-emacs-state))) |
| 42 | + |
| 43 | +(defadvice evil-normal-state (around holy-normal-to-emacs-state disable) |
| 44 | + "Forces Emacs state." |
| 45 | + (if (equal -1 (ad-get-arg 0)) |
| 46 | + ad-do-it |
| 47 | + (evil-emacs-state))) |
38 | 48 |
|
39 | 49 | ;;;###autoload
|
40 | 50 | (define-minor-mode holy-mode
|
41 | 51 | "Global minor mode to repulse the evil from spacemacs.
|
42 | 52 |
|
43 |
| -`evil-mode' and other minor modes in |
44 |
| -`holy-mode-modes-to-disable-alist' are turned off." |
| 53 | +The `insert state' is replaced by the `emacs state'." |
45 | 54 | :global t
|
46 | 55 | :lighter " holy"
|
47 | 56 | :group 'spacemacs
|
48 | 57 | (if holy-mode
|
49 |
| - (progn |
50 |
| - (dolist (mode holy-mode-modes-to-disable-alist) |
51 |
| - (when (boundp (car mode)) (funcall (car mode) -1))) |
52 |
| - (setq cursor-type 'box) |
53 |
| - (set-cursor-color "SkyBlue2") |
54 |
| - (when (fboundp 'spacemacs//helm-hjkl-navigation) |
55 |
| - (spacemacs//helm-hjkl-navigation nil))) |
56 |
| - (when (fboundp 'spacemacs//helm-hjkl-navigation) |
57 |
| - (spacemacs//helm-hjkl-navigation t)) |
58 |
| - (dolist (mode holy-mode-modes-to-disable-alist) |
59 |
| - (when (boundp (car mode)) |
60 |
| - (funcall (car mode) (cdr mode)))))) |
| 58 | + (in-nominus-patris-et-filii-et-sipritus-sancti) |
| 59 | + (amen))) |
| 60 | + |
| 61 | +(defun in-nominus-patris-et-filii-et-sipritus-sancti () |
| 62 | + "Enter the church of Emacs (wash your hands)." |
| 63 | + ;; make all buffers' initial state emacs |
| 64 | + (push '("." . emacs) evil-buffer-regexps) |
| 65 | + ;; replace evil states by `emacs state' |
| 66 | + (ad-enable-advice 'evil-insert-state 'around 'holy-insert-to-emacs-state) |
| 67 | + (ad-enable-advice 'evil-motion-state 'around 'holy-motion-to-emacs-state) |
| 68 | + (ad-enable-advice 'evil-normal-state 'around 'holy-normal-to-emacs-state) |
| 69 | + (ad-activate 'evil-insert-state) |
| 70 | + (ad-activate 'evil-motion-state) |
| 71 | + (ad-activate 'evil-normal-state) |
| 72 | + ;; key bindings hooks for dynamic switching of editing styles |
| 73 | + (run-hook-with-args 'spacemacs-editing-style-hook 'emacs) |
| 74 | + ;; initiate `emacs state' and enter the church |
| 75 | + (holy-mode//update-states-for-current-buffers 'emacs)) |
| 76 | + |
| 77 | +(defun amen () |
| 78 | + "May the force be with you my son (or not)." |
| 79 | + ;; restore defaults |
| 80 | + (setq evil-buffer-regexps (delete '("." . emacs) evil-buffer-regexps)) |
| 81 | + ;; restore evil states |
| 82 | + (ad-disable-advice 'evil-insert-state 'around 'holy-insert-to-emacs-state) |
| 83 | + (ad-disable-advice 'evil-motion-state 'around 'holy-motion-to-emacs-state) |
| 84 | + (ad-disable-advice 'evil-normal-state 'around 'holy-normal-to-emacs-state) |
| 85 | + (ad-activate 'evil-insert-state) |
| 86 | + (ad-activate 'evil-motion-state) |
| 87 | + (ad-activate 'evil-normal-state) |
| 88 | + ;; restore key bindings |
| 89 | + (run-hook-with-args 'spacemacs-editing-style-hook 'vim) |
| 90 | + ;; restore the states |
| 91 | + (holy-mode//update-states-for-current-buffers 'vim)) |
| 92 | + |
| 93 | +(defun holy-mode//update-states-for-current-buffers (style) |
| 94 | + "Update the active state in all current buffers given current STYLE." |
| 95 | + (dolist (buffer (buffer-list)) |
| 96 | + (with-current-buffer buffer |
| 97 | + (cond |
| 98 | + ((eq 'emacs style) (evil-emacs-state)) |
| 99 | + ((and (eq 'vim style) |
| 100 | + (eq 'emacs evil-state)) |
| 101 | + (cond |
| 102 | + ((memq major-mode evil-evilified-state-modes) (evil-evilified-state)) |
| 103 | + ((memq major-mode evil-motion-state-modes) (evil-motion-state)) |
| 104 | + (t (evil-normal-state)))))))) |
61 | 105 |
|
62 | 106 | (provide 'holy-mode)
|
0 commit comments