emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil-escape 02aee7f613 079/133: New variable evil-escape-u


From: ELPA Syncer
Subject: [nongnu] elpa/evil-escape 02aee7f613 079/133: New variable evil-escape-unordered-key-sequence
Date: Wed, 3 Jan 2024 21:59:55 -0500 (EST)

branch: elpa/evil-escape
commit 02aee7f613396e8a7fe4c8c2d7ea6ef84359dc37
Author: syl20bnr <sylvain.benner@gmail.com>
Commit: syl20bnr <sylvain.benner@gmail.com>

    New variable evil-escape-unordered-key-sequence
    
    Resolves #38
---
 README.md      |  6 ++++++
 evil-escape.el | 27 ++++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index d2b97bcff8..793aae3eb2 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@
     - [Customization](#customization)
         - [Key sequence](#key-sequence)
         - [Delay between keys](#delay-between-keys)
+        - [Unordered key sequence](#unordered-key-sequence)
         - [Excluding a major mode](#excluding-a-major-mode)
         - [Enable only for a list of major 
modes](#enable-only-for-a-list-of-major-modes)
         - [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
 (setq-default evil-escape-delay 0.2)
 ```
 
+### Unordered key sequence
+
+The key sequence can be entered in any order by setting
+the variable `evil-escape-unordered-key-sequence` to non nil.
+
 ### Excluding a major mode
 
 A major mode can be excluded by adding it to the list
diff --git a/evil-escape.el b/evil-escape.el
index d87ea48069..8f8e18aca6 100644
--- a/evil-escape.el
+++ b/evil-escape.el
@@ -5,7 +5,7 @@
 ;; Author: Sylvain Benner <sylvain.benner@gmail.com>
 ;; Keywords: convenience editing evil
 ;; Created: 22 Oct 2014
-;; Version: 3.06
+;; Version: 3.07
 ;; Package-Requires: ((emacs "24") (evil "1.0.9"))
 ;; URL: https://github.com/syl20bnr/evil-escape
 
@@ -55,6 +55,9 @@
 ;; The delay between the two key presses can be customized with
 ;; the variable `evil-escape-delay'. Default is `0.1'.
 
+;; The key sequence can be entered in any order by setting
+;; the variable `evil-escape-unordered-key-sequence' to non nil.
+
 ;; A major mode can be excluded by adding it to the list
 ;; `evil-escape-excluded-major-modes'.
 
@@ -90,6 +93,12 @@
   :type 'number
   :group 'evil-escape)
 
+(defcustom evil-escape-unordered-key-sequence nil
+  "If non-nil then the key sequence can also be entered with the second
+key first."
+  :type 'boolean
+  :group 'evil-escape)
+
 (defcustom evil-escape-excluded-major-modes nil
   "Excluded major modes where escape sequences has no effect."
   :type 'sexp
@@ -132,12 +141,16 @@ with a key sequence."
   (when (evil-escape-p)
     (let ((modified (buffer-modified-p))
           (inserted (evil-escape--insert))
+          (fkey (elt evil-escape-key-sequence 0))
           (skey (elt evil-escape-key-sequence 1))
           (evt (read-event nil nil evil-escape-delay)))
       (when inserted (evil-escape--delete))
       (set-buffer-modified-p modified)
       (cond
-       ((and (integerp evt) (char-equal evt skey))
+       ((and (integerp evt)
+             (or (char-equal evt skey)
+                 (and evil-escape-unordered-key-sequence
+                      (char-equal evt fkey))))
         (evil-escape)
         (setq this-command 'ignore))
        ((null evt))
@@ -153,7 +166,9 @@ with a key sequence."
        (not (memq major-mode evil-escape-excluded-major-modes))
        (or (not evil-escape-enable-only-for-major-modes)
            (memq major-mode evil-escape-enable-only-for-major-modes))
-       (equal (this-command-keys) (evil-escape--first-key))))
+       (or (equal (this-command-keys) (evil-escape--first-key))
+           (and evil-escape-unordered-key-sequence
+                (equal (this-command-keys) (evil-escape--second-key))))))
 
 (defun evil-escape--escape-normal-state ()
   "Escape from normal state."
@@ -195,6 +210,12 @@ with a key sequence."
          (fkeystr (char-to-string first-key)))
     fkeystr))
 
+(defun evil-escape--second-key ()
+  "Return the second key string in the key sequence."
+  (let* ((sec-key (elt evil-escape-key-sequence 1))
+         (fkeystr (char-to-string sec-key)))
+    fkeystr))
+
 (defun evil-escape--insert-func ()
   "Default insert function."
   (when (not buffer-read-only) (self-insert-command 1)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]