From 7e038cce93981e2b78bf6e160694d81cfa5dda67 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 26 Oct 2025 01:24:42 -0500 Subject: fix+test:custom-line-paragraph:infinite loop remove-lines-containing - Add guard clause to handle empty string input gracefully (would cause infinite loop) - Add 33 comprehensive tests covering normal cases, boundary cases, and error cases - Tests verify Unicode support, regex character escaping, region vs buffer operations - All 33 tests passing --- modules/custom-line-paragraph.el | 44 +++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'modules') diff --git a/modules/custom-line-paragraph.el b/modules/custom-line-paragraph.el index 811f2a4b..f33d6b55 100644 --- a/modules/custom-line-paragraph.el +++ b/modules/custom-line-paragraph.el @@ -82,27 +82,29 @@ buffer." If region is active, operate only on the region, otherwise on entire buffer. The operation is undoable." (interactive "sRemove lines containing: ") - (save-excursion - (save-restriction - (let ((region-active (use-region-p)) - (count 0)) - (when region-active - (narrow-to-region (region-beginning) (region-end))) - (goto-char (point-min)) - ;; Count lines before deletion - (while (re-search-forward (regexp-quote text) nil t) - (setq count (1+ count)) - (beginning-of-line) - (forward-line)) - ;; Go back and delete - (goto-char (point-min)) - (delete-matching-lines (regexp-quote text)) - ;; Report what was done - (message "Removed %d line%s containing '%s' from %s" - count - (if (= count 1) "" "s") - text - (if region-active "region" "buffer")))))) + (if (string-empty-p text) + (message "Empty search string - nothing to remove") + (save-excursion + (save-restriction + (let ((region-active (use-region-p)) + (count 0)) + (when region-active + (narrow-to-region (region-beginning) (region-end))) + (goto-char (point-min)) + ;; Count lines before deletion + (while (re-search-forward (regexp-quote text) nil t) + (setq count (1+ count)) + (beginning-of-line) + (forward-line)) + ;; Go back and delete + (goto-char (point-min)) + (delete-matching-lines (regexp-quote text)) + ;; Report what was done + (message "Removed %d line%s containing '%s' from %s" + count + (if (= count 1) "" "s") + text + (if region-active "region" "buffer"))))))) (defun cj/underscore-line () "Underline the current line by inserting a row of characters below it. -- cgit v1.2.3