Last active
November 21, 2016 14:21
-
-
Save gridaphobe/9765143 to your computer and use it in GitHub Desktop.
evil-mode god state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(evil-define-state god | |
"God state." | |
:tag " <G> " | |
:message "-- GOD MODE --" | |
:entry-hook (evil-god-start-hook) | |
:exit-hook (evil-god-stop-hook) | |
:input-method t | |
:intercept-esc nil) | |
(defun evil-god-start-hook () | |
(diminish 'god-local-mode) | |
(god-local-mode 1)) | |
(defun evil-god-stop-hook () | |
(god-local-mode -1) | |
(diminish-undo 'god-local-mode)) | |
(defvar evil-execute-in-god-state-buffer nil) | |
(defun evil-stop-execute-in-god-state () | |
(when (and (not (eq this-command #'evil-execute-in-god-state)) | |
(not (minibufferp))) | |
(remove-hook 'post-command-hook 'evil-stop-execute-in-god-state) | |
(when (buffer-live-p evil-execute-in-god-state-buffer) | |
(with-current-buffer evil-execute-in-god-state-buffer | |
(if (and (eq evil-previous-state 'visual) | |
(not (use-region-p))) | |
(progn | |
(evil-change-to-previous-state) | |
(evil-exit-visual-state)) | |
(evil-change-to-previous-state)))) | |
(setq evil-execute-in-god-state-buffer nil))) | |
(evil-define-command evil-execute-in-god-state () | |
"Execute the next command in God state." | |
(add-hook 'post-command-hook #'evil-stop-execute-in-god-state t) | |
(setq evil-execute-in-god-state-buffer (current-buffer)) | |
(cond | |
((evil-visual-state-p) | |
(let ((mrk (mark)) | |
(pnt (point))) | |
(evil-god-state) | |
(set-mar mrk) | |
(goto-char pnt))) | |
(t | |
(evil-god-state))) | |
(evil-echo "Switched to God state for the next command ...")) | |
(evil-define-key 'normal global-map "," 'evil-execute-in-god-state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outstanding! This is exactly what I was looking for.
I added
to keep escape as a get-out-of-everything-ever key. Too used to just whacking Esc a few times to back out of everything in vim.
Edit: Actually, that doesn't work. I'll update this when I get it right...
Edit2: Updated. What I have is probably overkill but what the heck. I'm a noob and it seems to do what I want.