Skip to content

Commit

Permalink
Remove evil--visual-eol-anchored
Browse files Browse the repository at this point in the history
There already exists a method for sticking to EOL: Setting
temporary-goal-column to most-positive-fixnum. As such, there is no
need for the variable evil--visual-eol-anchored introduced by commit
e31bff8.

This commit also fixes a regression where "g$" made "gj"/"gk" stick to
visual EOLs.
  • Loading branch information
axelf4 committed Apr 30, 2024
1 parent 8d3da0c commit b6629ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 59 deletions.
40 changes: 8 additions & 32 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -108,49 +108,29 @@ of the line or the buffer; just return nil."
(unless (or (evil-visual-state-p) (evil-operator-state-p))
(evil-adjust-cursor))))))

(defvar evil--visual-eol-anchored nil
"Non nil if the cursor should be anchored at the end of the visual line.
Only reliably usable via `evil-visual-eol-anchored-p'.")

(defun evil-visual-eol-anchored-p ()
"Return non nil if the cursor should be anchored at the end of the visual line."
(if (memq last-command '(next-line previous-line evil-end-of-visual-line))
evil--visual-eol-anchored
(setq evil--visual-eol-anchored nil)))

(evil-define-motion evil-next-line (count)
"Move the cursor COUNT lines down."
:type line
(let (line-move-visual)
(unless (memq last-command '(next-line previous-line evil-end-of-visual-line))
(setq evil--visual-eol-anchored nil))
(evil-line-move (or count 1))))

(evil-define-motion evil-previous-line (count)
"Move the cursor COUNT lines up."
:type line
(let (line-move-visual)
(unless (memq last-command '(next-line previous-line evil-end-of-visual-line))
(setq evil--visual-eol-anchored nil))
(evil-line-move (- (or count 1)))))

(evil-define-motion evil-next-visual-line (count)
"Move the cursor COUNT screen lines down."
:type exclusive
(let ((line-move-visual t))
(when (eq most-positive-fixnum temporary-goal-column)
(setq temporary-goal-column (current-column))) ; Fix #1876
(evil-line-move (or count 1))
(when (evil-visual-eol-anchored-p) (evil-end-of-visual-line))))
(evil-line-move (or count 1))))

(evil-define-motion evil-previous-visual-line (count)
"Move the cursor COUNT screen lines up."
:type exclusive
(let ((line-move-visual t))
(when (eq most-positive-fixnum temporary-goal-column)
(setq temporary-goal-column (current-column))) ; Fix #1876
(evil-line-move (- (or count 1)))
(when (evil-visual-eol-anchored-p) (evil-end-of-visual-line))))
(evil-line-move (- (or count 1)))))

;; used for repeated commands like "dd"
(evil-define-motion evil-line (count)
Expand Down Expand Up @@ -188,16 +168,13 @@ If COUNT is given, move COUNT - 1 lines downward first."
(move-end-of-line count)
(when evil-track-eol
(setq temporary-goal-column most-positive-fixnum
evil--visual-eol-anchored t
this-command 'next-line))
(if (evil-visual-state-p)
(when evil-v$-excludes-newline
(let ((evil-move-beyond-eol nil))
(evil-adjust-cursor)))
(evil-adjust-cursor)
(when (eolp)
;; prevent "c$" and "d$" from deleting blank lines
(setq evil-this-type 'exclusive))))
(let ((evil-move-beyond-eol
(if (evil-visual-state-p) (not evil-v$-excludes-newline)
evil-move-beyond-eol)))
(evil-adjust-cursor))
;; Prevent "c$" and "d$" from deleting blank lines
(when (eolp) (setq evil-this-type 'exclusive)))

(evil-define-motion evil-beginning-of-visual-line ()
"Move the cursor to the first character of the current screen line."
Expand All @@ -208,7 +185,6 @@ If COUNT is given, move COUNT - 1 lines downward first."
"Move the cursor to the last character of the current screen line.
If COUNT is given, move COUNT - 1 screen lines downward first."
:type inclusive
(setq evil--visual-eol-anchored t)
(end-of-visual-line count))

(evil-define-motion evil-end-of-line-or-visual-line (count)
Expand Down
25 changes: 13 additions & 12 deletions evil-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -1239,25 +1239,26 @@ If STATE is given it used a parsing state at point."
;; comes from simple.el, and I hope it will work in future.
(defun evil-line-move (count &optional noerror)
"Like `line-move' but conserves the column.
Signals an error at buffer boundaries unless NOERROR is non-nil."
Signal an error at buffer boundaries unless NOERROR is non-nil."
(setq this-command (if (< count 0) 'previous-line 'next-line))
(let ((last-command
;; Reset tmp goal column between visual/logical movement
(when (or (eq line-move-visual (consp temporary-goal-column))
(eq temporary-goal-column most-positive-fixnum))
last-command))
(opoint (point)))
(condition-case err
(line-move count)
((beginning-of-buffer end-of-buffer)
(let ((col (or goal-column
(car-safe temporary-goal-column)
temporary-goal-column)))
(line-move-finish col opoint (< count 0)))
(or noerror (/= (point) opoint) (signal (car err) (cdr err))))
(args-out-of-range
(unless (eq most-positive-fixnum temporary-goal-column)
(signal (car err) (cdr err)))))))
(if (and line-move-visual
(eq temporary-goal-column most-positive-fixnum)
(memq last-command '(next-line previous-line)))
(let (temporary-goal-column) (end-of-visual-line (1+ count)))
(condition-case err
(line-move count)
((beginning-of-buffer end-of-buffer)
(let ((col (or goal-column
(car-safe temporary-goal-column)
temporary-goal-column)))
(line-move-finish col opoint (< count 0)))
(or noerror (/= (point) opoint) (signal (car err) (cdr err))))))))

(defun evil-forward-syntax (syntax &optional count)
"Move point to the end or beginning of a sequence of characters in SYNTAX.
Expand Down
16 changes: 1 addition & 15 deletions evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3536,26 +3536,12 @@ Below some empty line"
("Gkgk")
(should-not (bolp))))

(ert-deftest evil-test-end-of-visual-line ()
"Test `evil-end-of-visual-line'."
:tags '(evil motion)
(skip-unless (and (not noninteractive) (> (window-width) 2)))
(evil-test-buffer
"alpha bravo charlie\nd[e]lta echo\nfoxtrot golf hotel india"
("g$" "gj")
"alpha bravo charlie\ndelta echo\nfoxtrot golf hotel indi[a]"
("gkgk")
"alpha bravo charli[e]\ndelta echo\nfoxtrot golf hotel india"
("ro" "2gj")
"alpha bravo charlio\ndelta echo\nfoxtrot golf hotel[ ]india"))

(ert-deftest evil-test-eol-anchoring-with-visual-line-movement ()
"Test gj and gk once the cursor is anchored at eol with $."
:tags '(evil motion)
(skip-unless (and (not noninteractive) (> (window-width) 2)))
(skip-unless (and (not noninteractive) (> (window-width) 13)))
(evil-test-buffer
"Short [l]ine\nA longer line\nThird line"
(visual-line-mode 1)
("$gj")
"Short line\nA longer lin[e]\nThird line"))

Expand Down

0 comments on commit b6629ae

Please sign in to comment.