diff options
| author | Tom Dalziel <tom_dl@hotmail.com> | 2022-04-12 23:49:41 +0100 |
|---|---|---|
| committer | Tom Dalziel <33435574+tomdl89@users.noreply.github.com> | 2022-04-13 01:09:56 +0200 |
| commit | dbab24f01daeef99039e6cd6f671d8b9ff1b4796 (patch) | |
| tree | e4b867773e2057cf54e0951fa062ed35ff9f416a | |
| parent | be009a9eaa101bba4a964c3e55de9849d6b473e2 (diff) | |
Don't ex move if source = destination
fixes #1595
| -rw-r--r-- | evil-commands.el | 37 | ||||
| -rw-r--r-- | evil-tests.el | 7 |
2 files changed, 25 insertions, 19 deletions
diff --git a/evil-commands.el b/evil-commands.el index fbfcc17..6e7a11b 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1748,24 +1748,25 @@ of the block." "Move lines in BEG END below line given by ADDRESS." :motion evil-line-or-visual-line (interactive "<r><addr>") - (goto-char (point-min)) - (forward-line address) - (let* ((m (set-marker (make-marker) (point))) - (txt (buffer-substring-no-properties beg end)) - (len (length txt))) - (delete-region beg end) - (goto-char m) - (set-marker m nil) - ;; ensure text consists of complete lines - (when (or (zerop len) (/= (aref txt (1- len)) ?\n)) - (setq txt (concat txt "\n"))) - (when (and (eobp) (not (bolp))) (newline)) ; incomplete last line - (when (evil-visual-state-p) - (move-marker evil-visual-mark (point))) - (insert txt) - (forward-line -1) - (when (evil-visual-state-p) - (move-marker evil-visual-point (point))))) + (unless (= (1+ address) (line-number-at-pos beg)) + (goto-char (point-min)) + (forward-line address) + (let* ((m (set-marker (make-marker) (point))) + (txt (buffer-substring-no-properties beg end)) + (len (length txt))) + (delete-region beg end) + (goto-char m) + (set-marker m nil) + ;; ensure text consists of complete lines + (when (or (zerop len) (/= (aref txt (1- len)) ?\n)) + (setq txt (concat txt "\n"))) + (when (and (eobp) (not (bolp))) (newline)) ; incomplete last line + (when (evil-visual-state-p) + (move-marker evil-visual-mark (point))) + (insert txt) + (forward-line -1) + (when (evil-visual-state-p) + (move-marker evil-visual-point (point)))))) (defun evil--check-undo-system () (when (and (eq evil-undo-system 'undo-tree) diff --git a/evil-tests.el b/evil-tests.el index b8100a8..b38be76 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -8372,7 +8372,12 @@ Source Target Source [O]ther line -"))) +")) + (ert-info ("Move with global (classic line reversal)") + (evil-test-buffer + "5\n4\n3\n2\n1\n" + (":g/^/m0") + "1\n2\n3\n4\n5\n"))) (ert-deftest evil-test-write () :tags '(evil ex) |
