diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-16 02:48:18 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-16 02:48:18 -0500 |
| commit | a9a4d8c7148c115a242a7b35d16dd536f9c0c700 (patch) | |
| tree | 3370202a1fd1a6e8eb7c14984bf602d0d37265d3 /modules/custom-comments.el | |
| parent | 1c5a2ebab7c721d795ed9331afdb305fd683e172 (diff) | |
| download | dotemacs-a9a4d8c7148c115a242a7b35d16dd536f9c0c700.tar.gz dotemacs-a9a4d8c7148c115a242a7b35d16dd536f9c0c700.zip | |
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.
Diffstat (limited to 'modules/custom-comments.el')
| -rw-r--r-- | modules/custom-comments.el | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/custom-comments.el b/modules/custom-comments.el index d5419be2..7e8e1404 100644 --- a/modules/custom-comments.el +++ b/modules/custom-comments.el @@ -85,6 +85,19 @@ ;; ======================== Comment Generation Functions ======================= +(defun cj/--validate-decoration-char (decoration-char) + "Signal `user-error' unless DECORATION-CHAR is a printable single character. +Returns DECORATION-CHAR unchanged on success. Rejects multi-char +strings, empty strings, control chars like newline/tab, and non-string +inputs. Used by all divider / border helpers below." + (unless (and (stringp decoration-char) + (= (length decoration-char) 1) + (string-match-p "[[:print:]]" decoration-char)) + (user-error + "Decoration character must be a single printable character, got: %S" + decoration-char)) + decoration-char) + ;; ----------------------------- Inline Border --------------------------------- (defun cj/--comment-inline-border (cmt-start cmt-end decoration-char text length) @@ -93,6 +106,7 @@ CMT-START and CMT-END are the comment syntax strings. DECORATION-CHAR is the character to use for borders (string). TEXT is the comment text (will be centered). LENGTH is the total width of the line." + (cj/--validate-decoration-char decoration-char) (let* ((current-column-pos (current-column)) (text-length (length text)) (comment-start-len (+ (length cmt-start) @@ -157,6 +171,7 @@ CMT-START and CMT-END are the comment syntax strings. DECORATION-CHAR is the character to use for the divider lines. TEXT is the comment text. LENGTH is the total width of each line." + (cj/--validate-decoration-char decoration-char) (let* ((current-column-pos (current-column)) (min-length (+ current-column-pos (length cmt-start) @@ -233,6 +248,7 @@ DECORATION-CHAR is the character to use for the divider lines. TEXT is the comment text. LENGTH is the total width of each line. PADDING is the number of spaces before the text." + (cj/--validate-decoration-char decoration-char) (when (< padding 0) (error "Padding %d cannot be negative" padding)) (let* ((current-column-pos (current-column)) @@ -314,6 +330,7 @@ CMT-START and CMT-END are the comment syntax strings. DECORATION-CHAR is the character to use for borders. TEXT is the comment text (centered). LENGTH is the total width of each line." + (cj/--validate-decoration-char decoration-char) (let* ((current-column-pos (current-column)) (comment-char (if (equal cmt-start ";") ";;" cmt-start)) (comment-end-char (if (string-empty-p cmt-end) comment-char cmt-end)) @@ -377,6 +394,7 @@ CMT-START and CMT-END are the comment syntax strings. DECORATION-CHAR is the character to use for borders. TEXT is the comment text (centered). LENGTH is the total width of each line." + (cj/--validate-decoration-char decoration-char) (let* ((current-column-pos (current-column)) (comment-char (if (equal cmt-start ";") ";;" cmt-start)) (comment-end-char (if (string-empty-p cmt-end) comment-char cmt-end)) @@ -542,6 +560,7 @@ CMT-END should be the block comment end (e.g., '*/'). DECORATION-CHAR is the character to use for the border line. TEXT is the comment text. LENGTH is the total width of each line." + (cj/--validate-decoration-char decoration-char) (let* ((current-column-pos (current-column)) (min-length (+ current-column-pos (length cmt-start) |
