Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove evil--visual-eol-anchored #1892

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 25 additions & 60 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ of the line or the buffer; just return nil."
((not crosslines)
;; For efficiency, narrow the buffer to the projected
;; movement before determining the current line
(evil-with-restriction (point) (+ (point) (or count 1) 1)
(evil-with-restriction nil (min (+ (point) (or count 1) 1) (point-max))
(condition-case err
(evil-narrow-to-line (forward-char count))
(error
Expand All @@ -75,11 +75,10 @@ of the line or the buffer; just return nil."
(t (evil-motion-loop (nil (or count 1))
(forward-char)
;; don't put the cursor on a newline
(and (not evil-move-beyond-eol)
(not (evil-visual-state-p))
(not (evil-operator-state-p))
(eolp) (not (eobp)) (not (bolp))
(forward-char))))))
(or evil-move-beyond-eol
(evil-visual-state-p) (evil-operator-state)
(not (eolp)) (bolp)
(forward-char))))))

(evil-define-motion evil-backward-char (count &optional crosslines noerror)
"Move cursor to the left by COUNT characters.
Expand All @@ -92,7 +91,9 @@ of the line or the buffer; just return nil."
(cond
((not crosslines)
;; Restrict movement to the current line
(evil-with-restriction (- (point) (or count 1)) (1+ (point))
(evil-with-restriction
(max (- (point) (or count 1)) (point-min))
(min (1+ (point)) (point-max))
(condition-case err
(evil-narrow-to-line (backward-char count))
(error
Expand All @@ -108,73 +109,43 @@ 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"
;; Used for repeated commands like "dd"
(evil-define-motion evil-line (count)
"Move COUNT - 1 lines down."
:type line
(let (line-move-visual)
;; Catch bob and eob errors. These are caused when not moving
;; point starting in the first or last line, respectively. In this
;; case the current line should be selected.
(condition-case _err
(evil-line-move (1- (or count 1)))
((beginning-of-buffer end-of-buffer)))))
(evil-line-move (1- (or count 1)) t)))

(evil-define-motion evil-line-or-visual-line (count)
"Move COUNT - 1 lines down."
:type screen-line
(let ((line-move-visual (and evil-respect-visual-line-mode
visual-line-mode)))
;; Catch bob and eob errors. These are caused when not moving
;; point starting in the first or last line, respectively. In this
;; case the current line should be selected.
(condition-case _err
(evil-line-move (1- (or count 1)))
((beginning-of-buffer end-of-buffer)))))
(evil-line-move (1- (or count 1)) t)))

(evil-define-motion evil-beginning-of-line ()
"Move the cursor to the beginning of the current line."
Expand All @@ -188,16 +159,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 +176,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 Expand Up @@ -3424,18 +3391,16 @@ command."
(switch-to-buffer buffer)))))

(evil-define-command evil-next-buffer (&optional count)
"Go to the `count'-th next buffer in the buffer list."
"Go to the COUNTth next buffer in the buffer list."
:repeat nil
(interactive "p")
(dotimes (_ (or count 1))
(next-buffer)))
(next-buffer count))

(evil-define-command evil-prev-buffer (&optional count)
"Go to the `count'-th prev buffer in the buffer list."
"Go to the COUNTth prev buffer in the buffer list."
:repeat nil
(interactive "p")
(dotimes (_ (or count 1))
(previous-buffer)))
(previous-buffer count))

(evil-define-command evil-delete-buffer (buffer &optional bang)
"Delete a buffer.
Expand Down Expand Up @@ -4561,14 +4526,14 @@ of the parent of the splitted window are rebalanced."
:repeat nil
(interactive "p")
(evil-window-split)
(evil-next-buffer count))
(next-buffer count))

(evil-define-command evil-split-prev-buffer (&optional count)
"Split window and go to the COUNT-th prev buffer in the buffer list."
:repeat nil
(interactive "p")
(evil-window-split)
(evil-prev-buffer count))
(previous-buffer count))

(evil-define-command evil-window-left (count)
"Move the cursor to new COUNT-th window left of the current one."
Expand Down
61 changes: 27 additions & 34 deletions evil-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -917,28 +917,26 @@ so it is more compatible with Evil's notion of EOL tracking."
"Restrict the buffer to BEG and END.
BEG or END may be nil, specifying a one-sided restriction including
`point-min' or `point-max'. See also `evil-with-restriction.'"
(declare (obsolete nil "1.15.0"))
(narrow-to-region
(if beg (max beg (point-min)) (point-min))
(if end (min end (point-max)) (point-max))))

(defmacro evil-with-restriction (beg end &rest body)
"Execute BODY with the buffer narrowed to BEG and END.
BEG or END may be nil as passed to `evil-narrow'; this creates
a one-sided restriction."
(declare (indent 2)
(debug t))
BEG or END may be nil to specify a one-sided restriction."
(declare (indent 2) (debug t))
`(save-restriction
(let ((evil-restriction-stack
(cons (cons (point-min) (point-max)) evil-restriction-stack)))
(evil-narrow ,beg ,end)
(narrow-to-region (or ,beg (point-min)) (or ,end (point-max)))
,@body)))

(defmacro evil-without-restriction (&rest body)
"Execute BODY with the top-most narrowing removed.
This works only if the previous narrowing has been generated by
`evil-with-restriction'."
(declare (indent defun)
(debug t))
(declare (indent defun) (debug t))
`(save-restriction
(widen)
(narrow-to-region (car (car evil-restriction-stack))
Expand Down Expand Up @@ -1239,25 +1237,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 Expand Up @@ -2931,8 +2930,8 @@ linewise, otherwise it is character wise."
(objbnd
(let ((wsend (evil-with-restriction
;; restrict to current line if we do non-line selection
(and (not line) (line-beginning-position))
(and (not line) (line-end-position))
(unless line (line-beginning-position))
(unless line (line-end-position))
(evil-bounds-of-not-thing-at-point thing dir))))
(cond
(wsend
Expand All @@ -2946,11 +2945,11 @@ linewise, otherwise it is character wise."
(setq wsend
(evil-with-restriction
;; restrict to current line if we do non-line selection
(and (not line)
(if (member thing '(evil-word evil-WORD))
(save-excursion (back-to-indentation) (point))
(line-beginning-position)))
(and (not line) (line-end-position))
(unless line
(if (member thing '(evil-word evil-WORD))
(save-excursion (back-to-indentation) (point))
(line-beginning-position)))
(unless line (line-end-position))
(evil-bounds-of-not-thing-at-point thing (- dir))))
(when wsend (setq other wsend addcurrent t)))))))
;; current match is whitespace, add thing
Expand Down Expand Up @@ -3763,14 +3762,8 @@ should be left-aligned for left justification."
(let ((fill-column position)
adaptive-fill-mode fill-prefix)
(evil-with-restriction
(save-excursion
(goto-char beg)
(line-beginning-position))
(save-excursion
(goto-char end)
(if (bolp)
(line-end-position 0)
(line-end-position)))
(save-excursion (goto-char beg) (line-beginning-position))
(save-excursion (goto-char end) (line-end-position (if (bolp) 0 1)))
(goto-char (point-min))
(while (progn
(if (eq justify 'left)
Expand Down
17 changes: 7 additions & 10 deletions evil-macros.el
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,18 @@ the beginning or end of the current line."
(when (save-excursion (goto-char end) (bolp))
(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))))
(or evil-move-beyond-eol
(evil-visual-state-p) (evil-operator-state-p)
(setq end (max beg (1- end))))
(evil-with-restriction beg end
(condition-case err
(progn ,@body)
(beginning-of-buffer
(if (= (point-min) beg)
(signal 'beginning-of-line nil)
(signal (car err) (cdr err))))
(signal (if (= (point-min) beg) 'beginning-of-line (car err))
(cdr err)))
(end-of-buffer
(if (= (point-max) end)
(signal 'end-of-line nil)
(signal (car err) (cdr err))))))))
(signal (if (= (point-max) end) 'end-of-line (car err))
(cdr err)))))))

(defun evil-eobp (&optional pos)
"Whether point is at end-of-buffer with regard to end-of-line."
Expand Down
18 changes: 2 additions & 16 deletions evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3526,26 +3526,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 Expand Up @@ -9009,7 +8995,7 @@ Source

(ert-deftest evil-test-ex-sort ()
:tags '(evil ex)
"Text ex command :sort `evil-ex-sort`."
"Text Ex command \":sort\" (`evil-ex-sort')."
(ert-info ("Plain sort")
(evil-test-buffer
"[z]zyy\ntest\ntEst\ntesT\nTEST\ntest\n"
Expand Down
3 changes: 1 addition & 2 deletions evil-types.el
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ and will be removed in a future version."
when `evil-respect-visual-line-mode' is non-nil."
:one-to-one nil
:expand (lambda (beg end)
(if (or (not evil-respect-visual-line-mode)
(not visual-line-mode))
(if (not (and evil-respect-visual-line-mode visual-line-mode))
(evil-line-expand beg end)
(evil-range
(progn
Expand Down