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

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

[nongnu] elpa/evil-surround 72d35afc40 051/175: Fix surrounding with inv


From: ELPA Syncer
Subject: [nongnu] elpa/evil-surround 72d35afc40 051/175: Fix surrounding with invalid chars, like ESC (Fix #51)
Date: Mon, 9 Oct 2023 13:01:02 -0400 (EDT)

branch: elpa/evil-surround
commit 72d35afc4049e4f52d8c906a8e47da56214cef6a
Author: Henrik Lissner <henrik@lissner.net>
Commit: Henrik Lissner <henrik@lissner.net>

    Fix surrounding with invalid chars, like ESC (Fix #51)
---
 evil-surround.el | 80 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 43 insertions(+), 37 deletions(-)

diff --git a/evil-surround.el b/evil-surround.el
index 3ded066994..4a8aaf5aa5 100755
--- a/evil-surround.el
+++ b/evil-surround.el
@@ -95,6 +95,10 @@ Each item is of the form (OPERATOR . OPERATION)."
     (cons (format "<%s%s>" (or tag "") (or rest ""))
           (format "</%s>" (or tag "")))))
 
+(defun evil-surround-valid-char-p (char)
+  "Returns whether CHAR is a valid surround char or not."
+  (not (memq char '(?\C-\[ ?\C-?))))
+
 (defun evil-surround-pair (char)
   "Return the evil-surround pair of char.
 This is a cons cell (LEFT . RIGHT), both strings."
@@ -191,9 +195,10 @@ overlays OUTER and INNER, which are passed to 
`evil-surround-delete'."
   (cond
    ((and outer inner)
     (evil-surround-delete char outer inner)
-    (evil-surround-region (overlay-start outer)
-                     (overlay-end outer)
-                     nil (read-char)))
+    (let ((key (read-char)))
+      (evil-surround-region (overlay-start outer)
+                            (overlay-end outer)
+                            nil (if (evil-surround-valid-char-p key) key 
char))))
    (t
     (let* ((outer (evil-surround-outer-overlay char))
            (inner (evil-surround-inner-overlay char)))
@@ -275,40 +280,41 @@ Becomes this:
    }"
 
   (interactive "<R>c")
-  (let* ((overlay (make-overlay beg end nil nil t))
-         (pair (evil-surround-pair char))
-         (open (car pair))
-         (close (cdr pair)))
-    (unwind-protect
-        (progn
-          (goto-char (overlay-start overlay))
-
-          (cond ((eq type 'block)
-                 (evil-surround-block beg end char))
-
-                ((eq type 'line)
-                 (insert open)
-                 (indent-according-to-mode)
-                 (newline-and-indent)
-                 (goto-char (overlay-end overlay))
-                 (insert close)
-                 (indent-according-to-mode)
-                 (newline))
-
-                (force-new-line
-                 (insert open)
-                 (indent-according-to-mode)
-                 (newline-and-indent)
-                 (goto-char (overlay-end overlay))
-                 (newline-and-indent)
-                 (insert close))
-
-                (t
-                 (insert open)
-                 (goto-char (overlay-end overlay))
-                 (insert close)))
-          (goto-char (overlay-start overlay)))
-      (delete-overlay overlay))))
+  (when (evil-surround-valid-char-p char)
+    (let* ((overlay (make-overlay beg end nil nil t))
+           (pair (evil-surround-pair char))
+           (open (car pair))
+           (close (cdr pair)))
+      (unwind-protect
+          (progn
+            (goto-char (overlay-start overlay))
+
+            (cond ((eq type 'block)
+                   (evil-surround-block beg end char))
+
+                  ((eq type 'line)
+                   (insert open)
+                   (indent-according-to-mode)
+                   (newline-and-indent)
+                   (goto-char (overlay-end overlay))
+                   (insert close)
+                   (indent-according-to-mode)
+                   (newline))
+
+                  (force-new-line
+                   (insert open)
+                   (indent-according-to-mode)
+                   (newline-and-indent)
+                   (goto-char (overlay-end overlay))
+                   (newline-and-indent)
+                   (insert close))
+
+                  (t
+                   (insert open)
+                   (goto-char (overlay-end overlay))
+                   (insert close)))
+            (goto-char (overlay-start overlay)))
+        (delete-overlay overlay)))))
 
 (evil-define-operator evil-Surround-region (beg end type char)
   "Call surround-region, toggling force-new-line"



reply via email to

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