aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--evil-commands.el37
-rw-r--r--evil-tests.el7
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)