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

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

[nongnu] elpa/evil 67115c894f 2/2: Error at boundaries with h/l even if


From: ELPA Syncer
Subject: [nongnu] elpa/evil 67115c894f 2/2: Error at boundaries with h/l even if point moved
Date: Mon, 9 Jan 2023 05:58:54 -0500 (EST)

branch: elpa/evil
commit 67115c894f4be23bec843cacf0622500bb1b38e1
Author: Axel Forsman <axelsfor@gmail.com>
Commit: Axel Forsman <axelsfor@gmail.com>

    Error at boundaries with h/l even if point moved
    
    This matches the behavior of Vim in how repeated macros are aborted.
---
 evil-commands.el | 64 +++++++++++++++++++++++---------------------------------
 evil-common.el   | 11 ----------
 evil-macros.el   | 51 +++++++++++++++++++-------------------------
 evil-tests.el    |  8 +++----
 evil-types.el    | 16 ++++++--------
 5 files changed, 57 insertions(+), 93 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index 1ebcdcfdf0..50288dee50 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -61,37 +61,31 @@ of the line or the buffer; just return nil."
   (interactive "<c>" (list evil-cross-lines
                            (evil-kbd-macro-suppress-motion-error)))
   (cond
-   (noerror
-    (condition-case nil
-        (evil-forward-char count crosslines nil)
-      (error nil)))
    ((not crosslines)
-    ;; for efficiency, narrow the buffer to the projected
+    ;; For efficiency, narrow the buffer to the projected
     ;; movement before determining the current line
-    (evil-with-restriction
-        (point)
-        (save-excursion
-          (evil-forward-char (1+ (or count 1)) t t)
-          (point))
+    (evil-with-restriction (point) (+ (point) (or count 1) 1)
       (condition-case err
-          (evil-narrow-to-line
-            (evil-forward-char count t noerror))
+          (evil-narrow-to-line (forward-char count))
         (error
-         ;; Restore the previous command (this one never happend).
-         ;; Actually, this preserves the current column if the
-         ;; previous command was `evil-next-line' or
-         ;; `evil-previous-line'.
+         ;; Restore the previous command (this one never happened).
+         ;; This preserves the current column if the previous command
+         ;; was `evil-next-line' or `evil-previous-line'.
          (setq this-command last-command)
-         (signal (car err) (cdr err))))))
+         (unless noerror (signal (car err) (cdr err)))))))
+   (noerror
+    (condition-case nil
+        (evil-forward-char count crosslines nil)
+      (error)))
    (t
     (evil-motion-loop (nil (or count 1))
       (forward-char)
       ;; don't put the cursor on a newline
-      (when (and (not evil-move-beyond-eol)
-                 (not (evil-visual-state-p))
-                 (not (evil-operator-state-p))
-                 (eolp) (not (eobp)) (not (bolp)))
-        (forward-char))))))
+      (and (not evil-move-beyond-eol)
+           (not (evil-visual-state-p))
+           (not (evil-operator-state-p))
+           (eolp) (not (eobp)) (not (bolp))
+           (forward-char))))))
 
 (evil-define-motion evil-backward-char (count &optional crosslines noerror)
   "Move cursor to the left by COUNT characters.
@@ -102,27 +96,21 @@ of the line or the buffer; just return nil."
   (interactive "<c>" (list evil-cross-lines
                            (evil-kbd-macro-suppress-motion-error)))
   (cond
-   (noerror
-    (condition-case nil
-        (evil-backward-char count crosslines nil)
-      (error nil)))
    ((not crosslines)
-    ;; restrict movement to the current line
-    (evil-with-restriction
-        (save-excursion
-          (evil-backward-char (1+ (or count 1)) t t)
-          (point))
-        (1+ (point))
+    ;; Restrict movement to the current line
+    (evil-with-restriction (- (point) (or count 1)) (1+ (point))
       (condition-case err
-          (evil-narrow-to-line
-            (evil-backward-char count t noerror))
+          (evil-narrow-to-line (backward-char count))
         (error
          ;; Restore the previous command (this one never happened).
-         ;; Actually, this preserves the current column if the
-         ;; previous command was `evil-next-line' or
-         ;; `evil-previous-line'.
+         ;; This preserves the current column if the previous command
+         ;; was `evil-next-line' or `evil-previous-line'.
          (setq this-command last-command)
-         (signal (car err) (cdr err))))))
+         (unless noerror (signal (car err) (cdr err)))))))
+   (noerror
+    (condition-case nil
+        (evil-backward-char count crosslines nil)
+      (error nil)))
    (t
     (evil-motion-loop (nil (or count 1))
       (backward-char)
diff --git a/evil-common.el b/evil-common.el
index 26015984cc..02d86806cd 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -1141,17 +1141,6 @@ the loop immediately quits. See also `evil-loop'.
              (when (= (point) ,orig)
                (throw ',done ,i))))))))
 
-(defmacro evil-signal-without-movement (&rest body)
-  "Catch errors provided point moves within this scope."
-  (declare (indent defun)
-           (debug t))
-  `(let ((p (point)))
-     (condition-case err
-         (progn ,@body)
-       (error
-        (when (= p (point))
-          (signal (car err) (cdr err)))))))
-
 (defun evil-signal-at-bob-or-eob (&optional count)
   "Signal error if `point' is at boundaries.
 If `point' is at bob and COUNT is negative this function signal
diff --git a/evil-macros.el b/evil-macros.el
index 10ccddd630..f70a4148b7 100644
--- a/evil-macros.el
+++ b/evil-macros.el
@@ -166,40 +166,32 @@ Optional keyword arguments are:
 (defmacro evil-narrow-to-line (&rest body)
   "Narrow BODY to the current line.
 BODY will signal the errors 'beginning-of-line or 'end-of-line
-upon reaching the beginning or end of the current line.
-
-\(fn [[KEY VAL]...] BODY...)"
-  (declare (indent defun)
-           (debug t))
-  `(let* ((range (evil-expand (point) (point) 'line))
-          (beg (evil-range-beginning range))
-          (end (evil-range-end range))
-          (min (point-min))
-          (max (point-max)))
+upon reaching the beginning or end of the current line."
+  (declare (indent defun) (debug t))
+  `(cl-destructuring-bind (beg end &rest) (evil-line-expand (point) (point))
      (when (save-excursion (goto-char end) (bolp))
        (setq end (max beg (1- end))))
-     ;; don't include the newline in Normal state
-     (when (and (not evil-move-beyond-eol)
-                (not (evil-visual-state-p))
-                (not (evil-operator-state-p)))
-       (setq end (max beg (1- end))))
+     ;; Do not include the newline in Normal state
+     (and (not evil-move-beyond-eol)
+          (not (evil-visual-state-p))
+          (not (evil-operator-state-p))
+          (setq end (max beg (1- end))))
      (evil-with-restriction beg end
-       (evil-signal-without-movement
-         (condition-case err
-             (progn ,@body)
-           (beginning-of-buffer
-            (if (= beg min)
-                (signal (car err) (cdr err))
-              (signal 'beginning-of-line nil)))
-           (end-of-buffer
-            (if (= end max)
-                (signal (car err) (cdr err))
-              (signal 'end-of-line nil))))))))
+       (condition-case err
+           (progn ,@body)
+         (beginning-of-buffer
+          (if (= (point-min) beg)
+              (signal 'beginning-of-line nil)
+            (signal (car err) (cdr err))))
+         (end-of-buffer
+          (if (= (point-max) end)
+              (signal 'end-of-line nil)
+            (signal (car err) (cdr err))))))))
 
 ;; we don't want line boundaries to trigger the debugger
 ;; when `debug-on-error' is t
-(add-to-list 'debug-ignored-errors "^Beginning of line$")
-(add-to-list 'debug-ignored-errors "^End of line$")
+(cl-pushnew 'beginning-of-line debug-ignored-errors)
+(cl-pushnew 'end-of-line debug-ignored-errors)
 
 (defun evil-eobp (&optional pos)
   "Whether point is at end-of-buffer with regard to end-of-line."
@@ -208,8 +200,7 @@ upon reaching the beginning or end of the current line.
     (cond
      ((eobp))
      ;; the rest only pertains to Normal state
-     ((not (evil-normal-state-p))
-      nil)
+     ((not (evil-normal-state-p)) nil)
      ;; at the end of the last line
      ((eolp)
       (forward-char)
diff --git a/evil-tests.el b/evil-tests.el
index 4b8ef46ef7..4865237a57 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -3256,12 +3256,12 @@ sed do eiusmod tempor incididunt"))
   (ert-info ("End of line")
     (evil-test-buffer
       ";; This buffer is for notes[.]"
-      (should-error (execute-kbd-macro "l"))
-      (should-error (execute-kbd-macro "10l"))))
+      (error end-of-line "l")
+      (error end-of-line "10l")))
   (ert-info ("Until end-of-line")
     (evil-test-buffer
       "[;]; This buffer is for notes."
-      ("100l")
+      (error end-of-line "100l")
       ";; This buffer is for notes[.]"))
   (ert-info ("On empty line")
     (evil-test-buffer
@@ -3292,7 +3292,7 @@ Below some empty line"
   (ert-info ("Until beginning-of-line")
     (evil-test-buffer
       ";; This[ ]buffer is for notes."
-      ("100h")
+      (error beginning-of-line "100h")
       "[;]; This buffer is for notes."))
   (ert-info ("On empty line")
     (evil-test-buffer
diff --git a/evil-types.el b/evil-types.el
index 645d2cfd03..276cdbbf1f 100644
--- a/evil-types.el
+++ b/evil-types.el
@@ -118,18 +118,14 @@ and will be removed in a future version."
             (evil-range
              (progn
                (goto-char beg)
-               (min (line-beginning-position)
-                    (progn
-                      ;; move to beginning of line as displayed
-                      (evil-move-beginning-of-line)
-                      (line-beginning-position))))
+               ;; move to beginning of line as displayed
+               (evil-move-beginning-of-line)
+               (point))
              (progn
                (goto-char end)
-               (max (line-beginning-position 2)
-                    (progn
-                      ;; move to end of line as displayed
-                      (evil-move-end-of-line)
-                      (line-beginning-position 2))))))
+               ;; move to the end of line as displayed
+               (evil-move-end-of-line)
+               (line-beginning-position 2))))
   :contract (lambda (beg end)
               (evil-range beg (max beg (1- end))))
   :string (lambda (beg end)



reply via email to

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