diff options
| author | Tom Dalziel <tom_dl@hotmail.com> | 2022-04-13 12:05:02 +0100 |
|---|---|---|
| committer | Tom Dalziel <33435574+tomdl89@users.noreply.github.com> | 2022-04-13 13:12:42 +0200 |
| commit | 7e87b82660668cb10f1f9838ddd622abab1f7a62 (patch) | |
| tree | f4a2aa572fee7a29f884eac7ca75152ce032826c | |
| parent | dbab24f01daeef99039e6cd6f671d8b9ff1b4796 (diff) | |
Ex yank doesn't move point
In visual state, it restores point to beginning of visual range
Fixes #1593
| -rw-r--r-- | evil-commands.el | 1 | ||||
| -rw-r--r-- | evil-ex.el | 5 | ||||
| -rw-r--r-- | evil-macros.el | 2 | ||||
| -rw-r--r-- | evil-tests.el | 11 |
4 files changed, 17 insertions, 2 deletions
diff --git a/evil-commands.el b/evil-commands.el index 6e7a11b..24e4953 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1653,6 +1653,7 @@ given." (evil-define-operator evil-ex-yank (beg end type register count yank-handler) "The Ex yank command. \[BEG,END]yank [REGISTER] [COUNT]" + :restore-point t (interactive "<R><xc/><y>") (evil-ex-delete-or-yank nil beg end type register count yank-handler)) @@ -703,6 +703,8 @@ This function interprets special file names like # and %." (evil-ex-range (or range (and count (evil-ex-range count count)))) (evil-ex-command (evil-ex-completed-binding command)) + (restore-point (when (evil-get-command-property evil-ex-command :restore-point) + (min (point) (or (mark) most-positive-fixnum)))) (evil-ex-bang (and bang t)) (evil-ex-argument (copy-sequence argument)) (evil-this-type (evil-type evil-ex-range)) @@ -734,7 +736,8 @@ This function interprets special file names like # and %." (goto-char beg) (activate-mark) (call-interactively evil-ex-command) - (run-hooks 'post-command-hook)))) + (run-hooks 'post-command-hook) + (when restore-point (goto-char restore-point))))) (when (buffer-live-p buf) (with-current-buffer buf (deactivate-mark))))))) diff --git a/evil-macros.el b/evil-macros.el index 329f54c..fe26723 100644 --- a/evil-macros.el +++ b/evil-macros.el @@ -480,6 +480,8 @@ Optional keyword arguments are: - `:keep-visual' - if non-nil, the selection is not disabled when the operator is executed in visual state. By default, visual state is exited automatically. +- `:restore-point' - if non-nil, point is restored when the + operator is executed from ex. \(fn OPERATOR (BEG END ARGS...) DOC [[KEY VALUE]...] BODY...)" (declare (indent defun) diff --git a/evil-tests.el b/evil-tests.el index b38be76..2836f22 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -1935,7 +1935,16 @@ New Tex[t] "a\n[b]\nc\nd\ne\nf\n" (":yank r 3") "a\nb\nc\nd\ne\nf\n" - (should (string= (substring-no-properties (evil-get-register ?r)) "b\nc\nd\n"))))) + (should (string= (substring-no-properties (evil-get-register ?r)) "b\nc\nd\n")))) + (ert-info (":yank with range yanks without moving point") + (evil-test-buffer + "[a]\nb\nc\nd\ne\n" + (":4y" [return] "p") + "a\n[d]\nb\nc\nd\ne\n") + (evil-test-buffer + "[a]\nb\nc\nd\ne\n" + (":+4y" [return] "p") + "a\n[e]\nb\nc\nd\ne\n"))) (ert-deftest evil-test-delete () "Test `evil-delete'" |
