From 1ba475cb0cf7076a284b13d808029309d13ea08c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 11 Jul 2026 14:29:02 -0500 Subject: fix(custom-line-paragraph): correct paren-jump, line-join, and duplicate This module carried three editing bugs. cj/jump-to-matching-paren, with point on a closing delimiter, ran backward-sexp from there and landed on the last inner sexp instead of the opener. It now steps past the closer first so backward-sexp spans the whole expression, and restores point when the delimiter is unmatched. Four tests that asserted the last-inner-sexp landings are corrected to the true matching opener. cj/join-line-or-region, without a region, added a newline unconditionally after joining, which left a stray blank line when joining a line in the middle of the buffer. It now adds the newline only at end of buffer. cj/duplicate-line-or-region duplicated a stray empty line for a region ending at beginning-of-line and split the line for a region ending mid-line. I normalized the bounds to the whole lines the region touches and insert that block once. --- .../test-custom-line-paragraph-join-line-or-region.el | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tests/test-custom-line-paragraph-join-line-or-region.el') diff --git a/tests/test-custom-line-paragraph-join-line-or-region.el b/tests/test-custom-line-paragraph-join-line-or-region.el index f8738910..5d421683 100644 --- a/tests/test-custom-line-paragraph-join-line-or-region.el +++ b/tests/test-custom-line-paragraph-join-line-or-region.el @@ -62,8 +62,8 @@ (should (string-match-p "line one line two" (buffer-string)))) (test-join-line-or-region-teardown))) -(ert-deftest test-join-line-or-region-no-region-adds-newline-after-join () - "Without region, should add newline after joining." +(ert-deftest test-join-line-or-region-no-region-adds-newline-at-end-of-buffer () + "Without region, joining the last line adds a trailing newline at end of buffer." (test-join-line-or-region-setup) (unwind-protect (with-temp-buffer @@ -73,6 +73,20 @@ (should (string-suffix-p "\n" (buffer-string)))) (test-join-line-or-region-teardown))) +(ert-deftest test-join-line-or-region-no-region-mid-buffer-no-blank-line () + "Without region, joining a non-last line must not insert a blank line. +The trailing newline belongs only at end of buffer; adding it unconditionally +left a stray blank line between the joined line and the rest of the buffer." + (test-join-line-or-region-setup) + (unwind-protect + (with-temp-buffer + (insert "line one\nline two\nline three") + (goto-char (point-min)) + (forward-line 1) ; point on "line two", not the last line + (cj/join-line-or-region) + (should (string= "line one line two\nline three" (buffer-string)))) + (test-join-line-or-region-teardown))) + (ert-deftest test-join-line-or-region-with-region-joins-all-lines () "With region, should join all lines in region." (test-join-line-or-region-setup) -- cgit v1.2.3