summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-26 01:24:42 -0500
committerCraig Jennings <c@cjennings.net>2025-10-26 01:24:42 -0500
commit7e038cce93981e2b78bf6e160694d81cfa5dda67 (patch)
tree81a7d02fa85b438bb7df6001a83cdb4f033c2ef0 /modules
parente712c8b00e47b6f9d9cbb6e6bf0a0732b4ef2e5c (diff)
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
Diffstat (limited to 'modules')
-rw-r--r--modules/custom-line-paragraph.el44
1 files changed, 23 insertions, 21 deletions
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.