aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Dalziel <tom_dl@hotmail.com>2022-04-15 10:40:10 +0100
committerTom Dalziel <33435574+tomdl89@users.noreply.github.com>2022-04-15 12:03:35 +0200
commit41006dc73d8c850d2a6378a3c026aedb16b80813 (patch)
tree0fa17df4a04dcdef1ad91d65fe0a98692d81827b
parent05714e8daacadb7603a05ffe81d1fbda7439a748 (diff)
Preserve non-blank last line when :move ing
Fixes #1595
-rw-r--r--evil-commands.el5
-rw-r--r--evil-tests.el17
2 files changed, 15 insertions, 7 deletions
diff --git a/evil-commands.el b/evil-commands.el
index 24e4953..ad57b22 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -1754,8 +1754,11 @@ of the block."
(forward-line address)
(let* ((m (set-marker (make-marker) (point)))
(txt (buffer-substring-no-properties beg end))
- (len (length txt)))
+ (len (length txt))
+ (last-line-blank (progn (goto-char (point-max)) (bolp))))
(delete-region beg end)
+ (unless last-line-blank ; as vim, preserve lack of blank last line
+ (progn (goto-char (point-max)) (when (bolp) (delete-char -1))))
(goto-char m)
(set-marker m nil)
;; ensure text consists of complete lines
diff --git a/evil-tests.el b/evil-tests.el
index b0d2ce1..028a105 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -8386,12 +8386,17 @@ Source
(evil-test-buffer
"5\n4\n3\n2\n1\n"
(":g/^/m0")
- "1\n2\n3\n4\n5\n"))
- (ert-info ("Move with global, and visual selection")
- (evil-test-buffer
- "<5\n4\n3\n2\n[1]>\n"
- (":g/^/m0")
- "1\n2\n3\n4\n5\n")))
+ "1\n2\n3\n4\n5\n")
+ (ert-info ("... and visual selection")
+ (evil-test-buffer
+ "<5\n4\n3\n2\n[1]>\n"
+ (":g/^/m0")
+ "1\n2\n3\n4\n5\n"))
+ (ert-info ("... and no last blank line")
+ (evil-test-buffer
+ "5\n4\n3\n2\n1"
+ (":g/^/m0")
+ "1\n2\n3\n4\n5"))))
(ert-deftest evil-test-write ()
:tags '(evil ex)