branch: elpa/evil commit 7e87b82660668cb10f1f9838ddd622abab1f7a62 Author: Tom Dalziel <tom...@hotmail.com> Commit: Tom Dalziel <33435574+tomd...@users.noreply.github.com>
Ex yank doesn't move point In visual state, it restores point to beginning of visual range Fixes #1593 --- evil-commands.el | 1 + evil-ex.el | 5 ++++- evil-macros.el | 2 ++ evil-tests.el | 11 ++++++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 6e7a11bf68..24e4953091 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)) diff --git a/evil-ex.el b/evil-ex.el index af04f7076f..b375a74455 100644 --- a/evil-ex.el +++ b/evil-ex.el @@ -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 329f54c3aa..fe26723232 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 b38be76f4e..2836f22751 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'"