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

Fix: Should not (evil-set-jump previous-pos) jump after evil-jump-forward #1772

Merged
merged 2 commits into from
Jul 12, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions evil-jumps.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Otherwise the jump commands act only within the current buffer."

(defvar evil--jumps-jumping nil)

(defvar evil--jumps-jumping-backward nil
(defvar evil--jumps-jump-command nil
"Set by `evil--jump-backward', used and cleared in the
`post-command-hook' by `evil--jump-handle-buffer-crossing'")

Expand Down Expand Up @@ -242,7 +242,7 @@ POS defaults to point."
(put 'evil-set-jump 'permanent-local-hook t)

(defun evil--jump-backward (count)
(setq evil--jumps-jumping-backward t)
(setq evil--jumps-jump-command t)
(let ((count (or count 1)))
(evil-motion-loop (nil count)
(let* ((struct (evil--jumps-get-current))
Expand All @@ -255,6 +255,7 @@ POS defaults to point."
(evil--jumps-jump idx 1)))))

(defun evil--jump-forward (count)
(setq evil--jumps-jump-command t)
tomdl89 marked this conversation as resolved.
Show resolved Hide resolved
(let ((count (or count 1)))
(evil-motion-loop (nil count)
(let* ((struct (evil--jumps-get-current))
Expand Down Expand Up @@ -303,30 +304,30 @@ change the current buffer."
(put 'evil--jump-hook 'permanent-local-hook t)

(defun evil--jump-handle-buffer-crossing ()
(let ((jumping-backward evil--jumps-jumping-backward))
(setq evil--jumps-jumping-backward nil)
(let ((jump-command evil--jumps-jump-command))
(setq evil--jumps-jump-command nil)
(dolist (frame (frame-list))
(dolist (window (window-list frame))
(let* ((struct (evil--jumps-get-current window))
(previous-pos (evil-jumps-struct-previous-pos struct)))
(when previous-pos
(setf (evil-jumps-struct-previous-pos struct) nil)
(if (and
;; `evil-jump-backward' (and other backward jumping
;; commands) needs to be handled specially. When
;; jumping backward multiple times, calling
;; `evil-set-jump' is always wrong: If you jump back
;; twice and we call `evil-set-jump' after the second
;; time, we clear the forward jump list and
;; `evil--jump-forward' won't work.
;; `evil-jump-backward' and 'evil-jump-forward' need
;; to be handled specially. When jumping backward
;; multiple times, calling `evil-set-jump' is always
;; wrong: If you jump back twice and we call
;; `evil-set-jump' after the second time, we clear
;; the forward jump list and `evil--jump-forward'
;; won't work.

;; The first time you jump backward, setting a jump
;; point is sometimes correct. But we don't do it
;; here because this function is called after
;; `evil--jump-backward' has updated our position in
;; the jump list so, again, `evil-set-jump' would
;; break `evil--jump-forward'.
(not jumping-backward)
(not jump-command)
(let ((previous-buffer (marker-buffer previous-pos)))
(and previous-buffer
(not (eq previous-buffer (window-buffer window))))))
Expand Down
27 changes: 22 additions & 5 deletions evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -9722,8 +9722,7 @@ parameter set."
("3\C-i") ;; even after jumping forward 3 times it can't get past the 3rd z
"z z [z] z z z z z"))
(ert-info ("Jump across files")
(let ((temp-file "evil-test-"))
(make-temp-file "evil-test-")
(let ((temp-file (make-temp-file "evil-test-")))
(unwind-protect
(evil-test-buffer
"[z] z z z z z z"
Expand All @@ -9734,9 +9733,27 @@ parameter set."
("\C-i")
"new buffe[r]")
(delete-file temp-file)
(with-current-buffer (get-file-buffer temp-file)
(set-buffer-modified-p nil))
(kill-buffer (get-file-buffer temp-file)))))))
(let ((buf (file-name-nondirectory temp-file)))
(when (get-buffer buf) (kill-buffer buf))))))
(ert-info ("Jump multiple times between files")
(let ((a (make-temp-file "evil-aa-" nil nil "evil-bb\n\nthis is a"))
(b (make-temp-file "evil-bb-" nil nil "evil-cc\n\nthis is b"))
(c (make-temp-file "evil-cc-" nil nil "this is c")))
(unwind-protect
(evil-test-buffer
(find-file a)
("gf" [return])
"evil-cc\n\nthis is b"
("gf" [return])
"this is c"
("\C-o" "\C-o")
"evil-bb\n\nthis is a"
("\C-i" "\C-i")
"this is c")
(dolist (f (list a b c))
(let ((buf (file-name-nondirectory f)))
(when (get-buffer buf) (kill-buffer buf)))
(delete-file f)))))))

(ert-deftest evil-test-find-file ()
:tags '(evil jumps)
Expand Down