[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-escape ca4c6f6065 017/133: Correctly restore bindings
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-escape ca4c6f6065 017/133: Correctly restore bindings when the mode is disabled |
Date: |
Wed, 3 Jan 2024 21:59:49 -0500 (EST) |
branch: elpa/evil-escape
commit ca4c6f606522d1605cdd9d13ec4aa1a453357806
Author: syl20bnr <sylvain.benner@gmail.com>
Commit: syl20bnr <sylvain.benner@gmail.com>
Correctly restore bindings when the mode is disabled
---
evil-escape.el | 61 +++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 45 insertions(+), 16 deletions(-)
diff --git a/evil-escape.el b/evil-escape.el
index dbdae53110..0c58ecda5b 100644
--- a/evil-escape.el
+++ b/evil-escape.el
@@ -66,6 +66,18 @@
:type 'key-sequence
:group 'evil-escape))
+(defvar evil-escape-motion-state-shadowed-func nil
+ "Original function of `evil-motion-state' shadowed by `evil-espace'.
+This variable is used to restore the original function bound to the
+first key of the escape key sequence when `evil-escape'
+mode is disabled.")
+
+(defvar evil-escape-isearch-shadowed-func nil
+ "Original function of `isearch-mode-map' shadowed by `evil-escape'.
+This variable is used to restore the original function bound to the
+first key of the escape key sequence when `evil-escape'
+mode is disabled.")
+
;;;###autoload
(define-minor-mode evil-escape-mode
"Buffer-local minor mode to escape insert state and everythin else
@@ -81,6 +93,12 @@ with a key sequence."
evil-escape-key-sequence))
(evil-escape--undefine-keys)))
+(defun evil-escape--first-key ()
+ "Return the first key string in the key sequence."
+ (let* ((first-key (elt evil-escape-key-sequence 0))
+ (fkeystr (char-to-string first-key)))
+ fkeystr))
+
(defmacro evil-escape-define-escape (map command &rest properties)
"Define an escape in MAP keymap by executing COMMAND.
@@ -92,10 +110,11 @@ with a key sequence."
If BOOL is not nil the first character is deleted using `:delete-func' if
the escape sequence succeeded.
-`:shadowed BOOL'
- BOOL not nil indicates that the first key of the sequence shadows a
- function. This function is looked-up from `evil-motion-state-map'.
- Whenever the escape sequence does not succeed and BOOL is not nil
+`:shadowed-map MAP'
+ MAP not nil indicates that the first key of the sequence shadows a
+ function bound in MAP. This function is looked-up from
+ `evil-motion-state-map'.
+ Whenever the escape sequence does not succeed and MAP is not nil
the shadowed function is called.
`:insert-func FUNCTION'
@@ -103,18 +122,18 @@ with a key sequence."
`:delete-func FUNCTION'
Specify the delete function to call when deleting the first key."
- (let* ((first-key (elt evil-escape-key-sequence 0))
- (fkeystr (char-to-string first-key))
- (insertp (plist-get properties :insert))
- (deletep (plist-get properties :delete))
- (insert-func (plist-get properties :insert-func))
- (delete-func (plist-get properties :delete-func)))
+ (let ((insertp (plist-get properties :insert))
+ (deletep (plist-get properties :delete))
+ (shadowed-map (plist-get properties :shadowed-map))
+ (insert-func (plist-get properties :insert-func))
+ (delete-func (plist-get properties :delete-func)))
`(progn
- (define-key ,map ,fkeystr
+ (define-key ,map ,(evil-escape--first-key)
(lambda () (interactive)
(evil-escape--escape
,evil-escape-key-sequence
- ',(if (plist-get properties :shadowed) (lookup-key
evil-motion-state-map fkeystr))
+ ',(if (plist-get properties :shadowed-map)
+ (lookup-key shadowed-map (evil-escape--first-key)))
,insertp
,deletep
',command
@@ -136,13 +155,15 @@ with a key sequence."
;; visual state
(key-chord-define evil-visual-state-map evil-escape-key-sequence
'evil-exit-visual-state)
;; motion state
+ (setq evil-escape-motion-state-shadowed-func
+ (lookup-key evil-motion-state-map (evil-escape--first-key)))
(let ((exit-func (lambda () (interactive)
(cond ((or (eq 'apropos-mode major-mode)
(eq 'help-mode major-mode)) (quit-window))
((eq 'neotree-mode major-mode) (neotree-hide))
(t (evil-normal-state))))))
(eval `(evil-escape-define-escape evil-motion-state-map ,exit-func
- :shadowed t)))
+ :shadowed-map ,evil-motion-state-map)))
;; lisp state if installed
(eval-after-load 'evil-lisp-state
'(key-chord-define evil-lisp-state-map evil-escape-key-sequence
'evil-normal-state))
@@ -151,6 +172,8 @@ with a key sequence."
;; evil ex command
(key-chord-define evil-ex-completion-map evil-escape-key-sequence
'abort-recursive-edit)
;; key-chord does not work with isearch, use evil-escape implementation
+ (setq evil-escape-isearch-shadowed-func
+ (lookup-key isearch-mode-map (evil-escape--first-key)))
(evil-escape-define-escape isearch-mode-map isearch-abort
:insert t
:delete t
@@ -163,15 +186,21 @@ with a key sequence."
(dolist (map '(evil-insert-state-map
evil-emacs-state-map
evil-visual-state-map
- evil-motion-state-map
minibuffer-local-map
evil-ex-completion-map))
(key-chord-define (eval map) evil-escape-key-sequence nil))
;; lisp state if installed
(eval-after-load 'evil-lisp-state
'(key-chord-define evil-lisp-state-map evil-escape-key-sequence nil))
- ;; isearch
- (define-key isearch-mode-map (kbd "f") 'isearch-printing-char))
+ (let ((first-key (evil-escape--first-key)))
+ ;; motion state
+ (if evil-escape-motion-state-shadowed-func
+ (define-key evil-motion-state-map
+ (kbd first-key) evil-escape-motion-state-shadowed-func))
+ ;; isearch
+ (if evil-escape-isearch-shadowed-func
+ (define-key isearch-mode-map
+ (kbd first-key) evil-escape-isearch-shadowed-func))))
(defun evil-escape--default-insert-func (key)
"Insert KEY in current buffer if not read only."
- [nongnu] elpa/evil-escape a04305aa74 028/133: typos in comments, (continued)
- [nongnu] elpa/evil-escape a04305aa74 028/133: typos in comments, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 7e0b99467f 061/133: Use `self-insert-command` instead of `insert`, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 5a8704e6a6 066/133: Add missing docstring, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 509e39d3a0 088/133: Declare function for compiler, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 47d2031f62 046/133: Fix `f is undefined`, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 8012e3d21f 054/133: Correctly escape in evil replace state, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 8af706a87c 013/133: Fixes #4 evil-escape confuse evil's minibuffer echo system, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape b33a5c722d 012/133: Fixes #5 fd-escaping makes 'df<char>' motion work, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 4779435d94 001/133: Initial commit, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 0fbedcbd86 016/133: Version 1.5.0, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape ca4c6f6065 017/133: Correctly restore bindings when the mode is disabled,
ELPA Syncer <=
- [nongnu] elpa/evil-escape 3e3920f524 008/133: Version 1.01, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 2def4a3b54 006/133: Merge pull request #1 from purcell/patch-1, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape f85416cc7c 015/133: Escape apropos buffers, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 177eccdd92 022/133: Fix byte-compilation error: void function evil-escape--first-key, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 773e7144e2 003/133: Version 1.0, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 95cd06f3c5 029/133: Fix regression with term buffers, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 09b6486054 038/133: Add limitation in macro in README, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape f8657037f4 042/133: Add new custom variable `evil-escape-excluded-major-modes`, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 1d7052cebc 039/133: Bump to version 2.11, ELPA Syncer, 2024/01/03
- [nongnu] elpa/evil-escape 7067e1b84d 034/133: Fix escape sequence for evil-lisp-state, ELPA Syncer, 2024/01/03