Skip to content

Commit

Permalink
Add support for spacemacs hybrid-state and fix emacs state
Browse files Browse the repository at this point in the history
Correctly insert and delete character in emacs state
  • Loading branch information
syl20bnr committed Sep 11, 2015
1 parent 02aee7f commit 9c87994
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions evil-escape.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Sylvain Benner <[email protected]>
;; Keywords: convenience editing evil
;; Created: 22 Oct 2014
;; Version: 3.07
;; Version: 3.08
;; Package-Requires: ((emacs "24") (evil "1.0.9"))
;; URL: https://github.com/syl20bnr/evil-escape

Expand Down Expand Up @@ -128,6 +128,7 @@ with a key sequence."
(`motion (evil-escape--escape-motion-state))
(`insert (evil-normal-state))
(`emacs (evil-escape--escape-emacs-state))
(`hybrid (evil-escape--escape-emacs-state))
(`evilified (evil-escape--escape-emacs-state))
(`visual (evil-exit-visual-state))
(`replace (evil-normal-state))
Expand Down Expand Up @@ -227,28 +228,40 @@ with a key sequence."
(defun evil-escape--insert ()
"Insert the first key of the sequence."
(pcase evil-state
(`insert (pcase major-mode
(`term-mode (call-interactively 'term-send-raw))
(_ (cond
((bound-and-true-p isearch-mode) (isearch-printing-char))
(t (evil-escape--insert-func))))) t)
(`insert (evil-escape--insert-2) t)
(`emacs (evil-escape--insert-2) t)
(`hybrid (evil-escape--insert-2) t)
(`normal
(when (window-minibuffer-p) (evil-escape--insert-func) t))
(`iedit-insert (evil-escape--insert-func) t)))

(defun evil-escape--insert-2 ()
"Insert character while taking into account mode specificites."
(pcase major-mode
(`term-mode (call-interactively 'term-send-raw))
(_ (cond
((bound-and-true-p isearch-mode) (isearch-printing-char))
(t (evil-escape--insert-func))))))

(defun evil-escape--delete ()
"Revert the insertion of the first key of the sequence."
(pcase evil-state
(`insert (pcase major-mode
(`term-mode (call-interactively 'term-send-backspace))
(`deft-mode (call-interactively 'deft-filter-increment))
(_ (cond
((bound-and-true-p isearch-mode) (isearch-delete-char))
(t (evil-escape--delete-func))))))
(`insert (evil-escape--delete-2))
(`emacs (evil-escape--delete-2))
(`hybrid (evil-escape--delete-2))
(`normal
(when (minibuffer-window-active-p (evil-escape--delete-func))))
(`iedit-insert (evil-escape--delete-func))))

(defun evil-escape--delete-2 ()
"Delete character while taking into account mode specifities."
(pcase major-mode
(`term-mode (call-interactively 'term-send-backspace))
(`deft-mode (call-interactively 'deft-filter-increment))
(_ (cond
((bound-and-true-p isearch-mode) (isearch-delete-char))
(t (evil-escape--delete-func))))))

(defun evil-escape--escape-with-q ()
"Send `q' key press event to exit from a buffer."
(setq unread-command-events (listify-key-sequence "q")))
Expand Down

0 comments on commit 9c87994

Please sign in to comment.