From 19a73261008dc8d4fa497f1d64ad57fa845674ce Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 16 May 2026 02:48:18 -0500 Subject: refactor(custom-editing): five hygiene fixes from the module-by-module re-review - Guard `cj/duplicate-line-or-region' when COMMENT is non-nil but the current mode has no `comment-start' (e.g. fundamental-mode). Previously the function silently produced malformed output via `comment-region'; now it signals a clear `user-error'. - Factor the `find-file' advice install in external-open.el into `cj/external-open-install-advice'. Same idempotent shape (remove-then-add) but the intent is named. - Add `cj/--validate-decoration-char' in custom-comments.el and wire it into all six divider / border / box helpers. Rejects multi-char strings, empty strings, and control characters like newline/tab that would corrupt subsequent `M-q' flows. Updated the five nil-decoration ERT tests from `:type 'wrong-type-argument' (the old crash signal from `string-to-char' on nil) to `:type 'user-error', since the validator produces a clear message instead of a deep crash. - Extract `cj/--require-spell-checker' in flyspell-and-abbrev.el. Both `cj/flyspell-toggle' and `cj/flyspell-then-abbrev' now call the shared helper; the checker list lives in `cj/--spell-checker-executables', so adding nuspell or any other checker is a one-line edit. - Preserve trailing newlines in custom-ordering output. Both `cj/--arrayify' and `cj/--unarrayify' now detect a trailing newline on the input region and re-append it to the result, matching the pattern custom-text-enclose.el already uses. --- modules/custom-line-paragraph.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'modules/custom-line-paragraph.el') diff --git a/modules/custom-line-paragraph.el b/modules/custom-line-paragraph.el index 27f24cfe2..0eb1e2a52 100644 --- a/modules/custom-line-paragraph.el +++ b/modules/custom-line-paragraph.el @@ -54,8 +54,15 @@ (defun cj/duplicate-line-or-region (&optional comment) "Duplicate the current line or active region below. -Comment the duplicated text when optional COMMENT is non-nil." +Comment the duplicated text when optional COMMENT is non-nil. +Signal `user-error' when COMMENT is non-nil but the current mode has +no `comment-start' (e.g. `fundamental-mode'), since commenting would +produce malformed output silently." (interactive "P") + (when (and comment (not (and (stringp comment-start) + (> (length comment-start) 0)))) + (user-error + "Cannot comment in %s: no comment syntax defined" major-mode)) (let* ((b (if (region-active-p) (region-beginning) (line-beginning-position))) (e (if (region-active-p) (region-end) (line-end-position))) (lines (split-string (buffer-substring-no-properties b e) "\n"))) -- cgit v1.2.3