Skip to content

Commit

Permalink
Fix issue 1295: failed visual-paste from registers >1
Browse files Browse the repository at this point in the history
The `kill-ring` let binding in `evil-visual-paste` meant that
`evil-get-register`'s view of `kill-ring` (used in `evil-paste-before`
and `evil-paste-after`) was limited to only entry `0` (and whatever
`evil-delete` may have added to rebound `kill-ring`). Therefore,
registers >1 were not actually visible to functions that needed
them. Condensing the `let*` binding so `kill-ring-yank-pointer` is
bound directly to `(list (current-kill 0))` was chosen as a simple and
effective method to fix the bug.

Test added to `evil-test-visual-paste` to ensure higher number
registers are available to visual-paste.
  • Loading branch information
tomdl89 authored and TheBB committed May 30, 2020
1 parent aaaeac7 commit 25fc5c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 2 additions & 4 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -2041,8 +2041,7 @@ The return value is the yanked text."
new-kill
paste-eob)
(evil-with-undo
(let* ((kill-ring (list (current-kill 0)))
(kill-ring-yank-pointer kill-ring))
(let ((kill-ring-yank-pointer (list (current-kill 0))))
(when (evil-visual-state-p)
(evil-visual-rotate 'upper-left)
;; if we replace the last buffer line that does not end in a
Expand All @@ -2058,13 +2057,12 @@ The return value is the yanked text."
(not (= evil-visual-end (point-max))))
(insert "\n"))
(evil-normal-state)
(setq new-kill (current-kill 0))
(current-kill 1))
(if paste-eob
(evil-paste-after count register)
(evil-paste-before count register)))
(when evil-kill-on-visual-paste
(kill-new new-kill))
(current-kill -1))
;; mark the last paste as visual-paste
(setq evil-last-paste
(list (nth 0 evil-last-paste)
Expand Down
15 changes: 14 additions & 1 deletion evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,20 @@ This bufferThis bufferThis buffe[r];; and for Lisp evaluation."))
;; [I]f you want to create a file, visit that file with C-x C-f."
("Vp")
";; This buffer is for notes you don't want to save.
\[;]; This buffer is for notes you don't want to save."))
\[;]; This buffer is for notes you don't want to save.")
(ert-info ("Visual-paste from register 3")
;; This behaviour deviates from vim, which populates registers 1-9 with
;; deleted text only, not yanked text. This is an aspect of `evil-yank's
;; use of the emacs kill-ring, so is consistent with non-visual paste.
(evil-test-buffer
"[w]ord1a word1b word1c word1d
word2a word2b word2c word2d"
("yiwwyiwwyiw")
"word1a word1b [w]ord1c word1d
word2a word2b word2c word2d"
("+viw\"3p")
"word1a word1b word1c word1d
word1[a] word2b word2c word2d")))

(ert-deftest evil-test-visual-paste-pop ()
"Test `evil-paste-pop' after visual paste."
Expand Down

1 comment on commit 25fc5c6

@sorawee
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomdl89 This commit breaks the functionality of evil-kill-on-visual-paste. When evil-kill-on-visual-paste is nil, it should not copy stuff to the kill ring on visual paste, but this commit makes it does it.

Please sign in to comment.