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

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

[nongnu] elpa/evil 8325ba0dee: evil-select-parens selects next pair if n


From: ELPA Syncer
Subject: [nongnu] elpa/evil 8325ba0dee: evil-select-parens selects next pair if not in parens (#1673)
Date: Sun, 2 Oct 2022 15:58:24 -0400 (EDT)

branch: elpa/evil
commit 8325ba0deeca0953b7957485d33de2188b6ded67
Author: Garklein <63201615+Garklein@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    evil-select-parens selects next pair if not in parens (#1673)
    
    Co-authored-by: marcolgl <marco-9-6-96@hotmail.it>
    Co-authored-by: Tom Dalziel <tom_dl@hotmail.com>
---
 evil-commands.el |   3 +-
 evil-common.el   | 113 +++++++++++++++++++++++++++++++++----------------------
 evil-tests.el    |  28 ++++++++++++++
 3 files changed, 99 insertions(+), 45 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index d814ad76e5..65d17dd245 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -1477,7 +1477,8 @@ or line COUNT to the top of the window."
      ((memq type '(line screen-line))
       (evil-yank-lines beg end register yank-handler))
      (t
-      (evil-yank-characters beg end register yank-handler)))))
+      (evil-yank-characters beg end register yank-handler)
+      (goto-char beg)))))
 
 (evil-define-operator evil-yank-line (beg end type register)
   "Save whole lines into the kill-ring."
diff --git a/evil-common.el b/evil-common.el
index 42290c1476..c0282ce4ab 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -3403,6 +3403,9 @@ respectively. BEG END TYPE are the currently selected 
(visual)
 range.  If INCLUSIVE is non-nil, OPEN and CLOSE are included in
 the range; otherwise they are excluded.
 
+If you aren't inside a pair of the opening and closing delimiters,
+it jumps you inside the next one. If there isn't one, it errors.
+
 The types of OPEN and CLOSE specify which kind of THING is used
 for parsing with `evil-select-block'. If OPEN and CLOSE are
 characters `evil-up-paren' is used. Otherwise OPEN and CLOSE
@@ -3411,50 +3414,72 @@ must be regular expressions and `evil-up-block' is used.
 If the selection is exclusive, whitespace at the end or at the
 beginning of the selection until the end-of-line or beginning-of-line
 is ignored."
-  ;; we need special linewise exclusive selection
-  (unless inclusive (setq inclusive 'exclusive-line))
-  (cond
-   ((and (characterp open) (characterp close))
-    (let ((thing #'(lambda (&optional cnt)
-                     (evil-up-paren open close cnt)))
-          (bnd (or (bounds-of-thing-at-point 'evil-string)
-                   (bounds-of-thing-at-point 'evil-comment)
-                   ;; If point is at the opening quote of a string,
-                   ;; this must be handled as if point is within the
-                   ;; string, i.e. the selection must be extended
-                   ;; around the string. Otherwise
-                   ;; `evil-select-block' might do the wrong thing
-                   ;; because it accidentally moves point inside the
-                   ;; string (for inclusive selection) when looking
-                   ;; for the current surrounding block. (re #364)
-                   (and (= (point) (or beg (point)))
-                        (save-excursion
-                          (goto-char (1+ (or beg (point))))
-                          (or (bounds-of-thing-at-point 'evil-string)
-                              (bounds-of-thing-at-point 'evil-comment)))))))
-      (if (not bnd)
-          (evil-select-block thing beg end type count inclusive)
-        (or (evil-with-restriction (car bnd) (cdr bnd)
-              (condition-case nil
-                  (evil-select-block thing beg end type count inclusive)
-                (error nil)))
-            (save-excursion
-              (setq beg (or beg (point))
-                    end (or end (point)))
-              (goto-char (car bnd))
-              (let ((extbeg (min beg (car bnd)))
-                    (extend (max end (cdr bnd))))
-                (evil-select-block thing
-                                   extbeg extend
-                                   type
-                                   count
-                                   inclusive
-                                   (or (< extbeg beg) (> extend end))
-                                   t)))))))
-   (t
-    (evil-select-block #'(lambda (&optional cnt)
-                           (evil-up-block open close cnt))
-                       beg end type count inclusive))))
+  (condition-case nil
+      (progn
+        ;; we need special linewise exclusive selection
+        (unless inclusive (setq inclusive 'exclusive-line))
+        (cond
+         ((and (characterp open) (characterp close))
+          (let ((thing #'(lambda (&optional cnt)
+                           (evil-up-paren open close cnt)))
+                (bnd (or (bounds-of-thing-at-point 'evil-string)
+                         (bounds-of-thing-at-point 'evil-comment)
+                         ;; If point is at the opening quote of a string,
+                         ;; this must be handled as if point is within the
+                         ;; string, i.e. the selection must be extended
+                         ;; around the string. Otherwise
+                         ;; `evil-select-block' might do the wrong thing
+                         ;; because it accidentally moves point inside the
+                         ;; string (for inclusive selection) when looking
+                         ;; for the current surrounding block. (re #364)
+                         (and (= (point) (or beg (point)))
+                              (save-excursion
+                                (goto-char (1+ (or beg (point))))
+                                (or (bounds-of-thing-at-point 'evil-string)
+                                    (bounds-of-thing-at-point 
'evil-comment)))))))
+            (if (not bnd)
+                (evil-select-block thing beg end type count inclusive)
+              (or (evil-with-restriction (car bnd) (cdr bnd)
+                    (ignore-errors
+                      (evil-select-block thing beg end type count inclusive)))
+                  (save-excursion
+                    (setq beg (or beg (point))
+                          end (or end (point)))
+                    (goto-char (car bnd))
+                    (let ((extbeg (min beg (car bnd)))
+                          (extend (max end (cdr bnd))))
+                      (evil-select-block thing
+                                         extbeg extend
+                                         type
+                                         count
+                                         inclusive
+                                         (or (< extbeg beg) (> extend end))
+                                         t)))))))
+         (t
+          (evil-select-block #'(lambda (&optional cnt)
+                                 (evil-up-block open close cnt))
+                             beg end type count inclusive))))
+    (error ; we aren't in the parens, so find next instance
+     (save-match-data
+       (goto-char (or (if (and count (> 0 count)) end beg)
+                      (point)))
+       (let ((re (if (characterp open) (string open) open)))
+         (if (and (not (string= (string (char-after)) re))
+                  (re-search-forward re nil t count))
+             (progn
+               (goto-char (match-beginning 0))
+               (let* ((mbeg (match-beginning 0))
+                      (res (evil-select-paren open close mbeg mbeg
+                                              type nil inclusive)))
+                 (if (< (car res) mbeg)
+                     ;; this will error if the beginning of the found parens 
is before the target paren
+                     ;; this prevents things such as on the line `prova ( 
verder "((testo)")`,
+                     ;; the inputs `g2ci(` from putting your cursor inside the 
deleted `()` after `prova`
+                     ;; without this, it would go to the second paren (the 
unbalanced first paren inside the quotes)
+                     ;; and then do a change there, changing inside the whole 
paren after `prova`
+                     (error "No surrounding delimiters found")
+                   res)))
+           (error "No surrounding delimiters found")))))))
 
 (defun evil-select-quote-thing (thing beg end _type count &optional inclusive)
   "Selection THING as if it described a quoted object.
diff --git a/evil-tests.el b/evil-tests.el
index 34926c0c3b..8373464516 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -9501,6 +9501,34 @@ when an error stops the execution of the macro"
      ("@a")
      "inserted text appended tex[t]")))
 
+(ert-deftest evil-test-paren-jumping ()
+  :tags '(evil paren)
+  (ert-info ("Test doing motions on parens that you aren't in")
+    (evil-test-buffer
+      "[m]ain(argc, argv) char **argv; {"
+      ("dib" [escape])
+      "main([)] char **argv; {")
+    (evil-test-buffer
+      "[a]lpha (bravo) charlie "
+      ("yi(")
+      "alpha ([b]ravo) charlie "
+      ("$p")
+      "alpha (bravo) charlie brav[o]")
+      (evil-test-buffer
+        "[a]lpha (bravo (charlie))"
+        ("2di(")
+        "alpha (bravo ([)]")
+    (evil-test-buffer
+"[#]include \"stdlib.h\"
+main(argc, argv) char **argv; {
+  while (1) malloc(0);
+}"
+      ("ci{  return 0;" [escape])
+"#include \"stdlib.h\"
+main(argc, argv) char **argv; {
+  return 0[;]
+}")))
+
 ;;; Core
 
 (ert-deftest evil-test-initial-state ()



reply via email to

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