Skip to content

Commit 989c8d0

Browse files
committed
Backport new holy-mode using evil
Fixes wrong state when exiting from evil-lisp-state and evil-iedit-state
1 parent 41f466e commit 989c8d0

File tree

1 file changed

+66
-22
lines changed
  • layers/+distribution/spacemacs-base/local/holy-mode

1 file changed

+66
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; holy-mode.el --- Enter the church of Emacs
22

3-
;; Copyright (C) 2012-2016 Sylvain Benner & Contributors
3+
;; Copyright (C) 2014-2015 syl20bnr
44
;;
55
;; Author: Sylvain Benner <[email protected]>
66
;; Keywords: convenience editing
@@ -28,35 +28,79 @@
2828

2929
;;; Code:
3030

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

3949
;;;###autoload
4050
(define-minor-mode holy-mode
4151
"Global minor mode to repulse the evil from spacemacs.
4252
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'."
4554
:global t
4655
:lighter " holy"
4756
:group 'spacemacs
4857
(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))))))))
61105

62106
(provide 'holy-mode)

0 commit comments

Comments
 (0)