Skip to content

Commit 02aee7f

Browse files
committed
New variable evil-escape-unordered-key-sequence
Resolves #38
1 parent d7f9940 commit 02aee7f

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Customization](#customization)
1212
- [Key sequence](#key-sequence)
1313
- [Delay between keys](#delay-between-keys)
14+
- [Unordered key sequence](#unordered-key-sequence)
1415
- [Excluding a major mode](#excluding-a-major-mode)
1516
- [Enable only for a list of major modes](#enable-only-for-a-list-of-major-modes)
1617
- [Assign a key binding directly](#assign-a-key-binding-directly)
@@ -86,6 +87,11 @@ composed with the two same characters it is recommended to set the delay to
8687
(setq-default evil-escape-delay 0.2)
8788
```
8889

90+
### Unordered key sequence
91+
92+
The key sequence can be entered in any order by setting
93+
the variable `evil-escape-unordered-key-sequence` to non nil.
94+
8995
### Excluding a major mode
9096

9197
A major mode can be excluded by adding it to the list

evil-escape.el

+24-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
66
;; Keywords: convenience editing evil
77
;; Created: 22 Oct 2014
8-
;; Version: 3.06
8+
;; Version: 3.07
99
;; Package-Requires: ((emacs "24") (evil "1.0.9"))
1010
;; URL: https://github.com/syl20bnr/evil-escape
1111

@@ -55,6 +55,9 @@
5555
;; The delay between the two key presses can be customized with
5656
;; the variable `evil-escape-delay'. Default is `0.1'.
5757

58+
;; The key sequence can be entered in any order by setting
59+
;; the variable `evil-escape-unordered-key-sequence' to non nil.
60+
5861
;; A major mode can be excluded by adding it to the list
5962
;; `evil-escape-excluded-major-modes'.
6063

@@ -90,6 +93,12 @@
9093
:type 'number
9194
:group 'evil-escape)
9295

96+
(defcustom evil-escape-unordered-key-sequence nil
97+
"If non-nil then the key sequence can also be entered with the second
98+
key first."
99+
:type 'boolean
100+
:group 'evil-escape)
101+
93102
(defcustom evil-escape-excluded-major-modes nil
94103
"Excluded major modes where escape sequences has no effect."
95104
:type 'sexp
@@ -132,12 +141,16 @@ with a key sequence."
132141
(when (evil-escape-p)
133142
(let ((modified (buffer-modified-p))
134143
(inserted (evil-escape--insert))
144+
(fkey (elt evil-escape-key-sequence 0))
135145
(skey (elt evil-escape-key-sequence 1))
136146
(evt (read-event nil nil evil-escape-delay)))
137147
(when inserted (evil-escape--delete))
138148
(set-buffer-modified-p modified)
139149
(cond
140-
((and (integerp evt) (char-equal evt skey))
150+
((and (integerp evt)
151+
(or (char-equal evt skey)
152+
(and evil-escape-unordered-key-sequence
153+
(char-equal evt fkey))))
141154
(evil-escape)
142155
(setq this-command 'ignore))
143156
((null evt))
@@ -153,7 +166,9 @@ with a key sequence."
153166
(not (memq major-mode evil-escape-excluded-major-modes))
154167
(or (not evil-escape-enable-only-for-major-modes)
155168
(memq major-mode evil-escape-enable-only-for-major-modes))
156-
(equal (this-command-keys) (evil-escape--first-key))))
169+
(or (equal (this-command-keys) (evil-escape--first-key))
170+
(and evil-escape-unordered-key-sequence
171+
(equal (this-command-keys) (evil-escape--second-key))))))
157172

158173
(defun evil-escape--escape-normal-state ()
159174
"Escape from normal state."
@@ -195,6 +210,12 @@ with a key sequence."
195210
(fkeystr (char-to-string first-key)))
196211
fkeystr))
197212

213+
(defun evil-escape--second-key ()
214+
"Return the second key string in the key sequence."
215+
(let* ((sec-key (elt evil-escape-key-sequence 1))
216+
(fkeystr (char-to-string sec-key)))
217+
fkeystr))
218+
198219
(defun evil-escape--insert-func ()
199220
"Default insert function."
200221
(when (not buffer-read-only) (self-insert-command 1)))

0 commit comments

Comments
 (0)