aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Dalziel <tom_dl@hotmail.com>2023-05-22 21:50:20 +0100
committerTom Dalziel <33435574+tomdl89@users.noreply.github.com>2023-05-22 23:23:14 +0200
commitc3ae7ef6a4d43dd950dcaf846239dd8705c7364b (patch)
treed0fa718c30321f1f167ac352a258a87fec83e5f4
parent6e22e2b7f353f16df5e117ab220d89c0450b44b9 (diff)
Re-indent last line join if onto blank
-rw-r--r--evil-commands.el11
-rw-r--r--evil-tests.el7
2 files changed, 14 insertions, 4 deletions
diff --git a/evil-commands.el b/evil-commands.el
index 0a340a1..f8cf142 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -1844,12 +1844,17 @@ Add (add-hook 'evil-local-mode-hook 'turn-on-undo-tree-mode) to your init file f
(evil-define-operator evil-join (beg end)
"Join the selected lines."
:motion evil-line
- (let ((count (count-lines beg end)))
+ (let ((count (count-lines beg end))
+ last-line-blank)
(when (> count 1)
(setq count (1- count)))
(goto-char beg)
- (dotimes (_ count)
- (join-line 1))))
+ (dotimes (i count)
+ (when (= (1+ i) count) ; i.e. we're just before the last join
+ (evil-move-beginning-of-line)
+ (setq last-line-blank (looking-at "[ \t]*$")))
+ (join-line 1))
+ (and last-line-blank (indent-according-to-mode))))
(evil-define-operator evil-join-whitespace (beg end)
"Join the selected lines without changing whitespace.
diff --git a/evil-tests.el b/evil-tests.el
index e9ca224..601bacc 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -2415,7 +2415,12 @@ ABCthen enter the text in that file's own buffer.")))
"[l]ine 1\nline 2\nline 3\nline 4"
(":1,3join")
"line 1 line 2 line 3\nline 4"))
- )
+ (ert-info ("Join blank line")
+ (evil-test-buffer
+ "(when foo\n[]\n bar)"
+ (emacs-lisp-mode)
+ ("J")
+ "(when foo\n [b]ar)")))
(ert-deftest evil-test-substitute ()
"Test `evil-substitute'"