diff options
| -rw-r--r-- | modules/custom-comments.el | 84 | ||||
| -rw-r--r-- | tests/test-custom-comments-comment-heavy-box.el | 8 | ||||
| -rw-r--r-- | todo.org | 4 |
3 files changed, 54 insertions, 42 deletions
diff --git a/modules/custom-comments.el b/modules/custom-comments.el index b6919d651..cae911061 100644 --- a/modules/custom-comments.el +++ b/modules/custom-comments.el @@ -409,47 +409,57 @@ LENGTH is the total width of each line." (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)) - (available-width (- length current-column-pos - (length comment-char) - (length comment-end-char) - 2)) ; spaces around content - (border-line (make-string available-width (string-to-char decoration-char))) - (text-length (length text)) - (padding-each-side (max 1 (/ (- available-width text-length) 2))) - (right-padding (if (= (% (- available-width text-length) 2) 0) - padding-each-side - (1+ padding-each-side)))) - ;; Top border - (insert comment-char " " border-line " " comment-end-char) - (newline) + (min-length (+ current-column-pos + (length comment-char) + 2 ; spaces around content + (length comment-end-char) + 6))) ; 3 border chars + text space + 3 border chars + (when (< length min-length) + (error "Length %d is too small to generate comment (minimum %d)" length min-length)) + (let* ((available-width (- length current-column-pos + (length comment-char) + (length comment-end-char) + 2)) ; spaces around content + (border-line (make-string available-width (string-to-char decoration-char))) + (text-available (- available-width 4)) ; 2 side decorations, 2 spaces + (text-length (length text)) + (padding-each-side (max 1 (/ (- text-available text-length) 2))) + (right-padding (if (= (% (- text-available text-length) 2) 0) + padding-each-side + (1+ padding-each-side))) + ;; Interior side-border lines repeat the comment prefix and suffix so + ;; the empty/text rows stay valid comments in line-comment languages + ;; (elisp, Python). Previously they began with a bare decoration char. + (empty-line (concat comment-char " " decoration-char + (make-string (- available-width 2) ?\s) + decoration-char " " comment-end-char))) + ;; Top border + (insert comment-char " " border-line " " comment-end-char) + (newline) - ;; Empty line with side borders - (dotimes (_ current-column-pos) (insert " ")) - (insert decoration-char) - (dotimes (_ available-width) (insert " ")) - (insert " " decoration-char) - (newline) + ;; Empty line with side borders + (dotimes (_ current-column-pos) (insert " ")) + (insert empty-line) + (newline) - ;; Centered text line - (dotimes (_ current-column-pos) (insert " ")) - (insert decoration-char " ") - (dotimes (_ padding-each-side) (insert " ")) - (insert text) - (dotimes (_ right-padding) (insert " ")) - (insert " " decoration-char) - (newline) + ;; Centered text line + (dotimes (_ current-column-pos) (insert " ")) + (insert comment-char " " decoration-char " ") + (dotimes (_ padding-each-side) (insert " ")) + (insert text) + (dotimes (_ right-padding) (insert " ")) + (insert " " decoration-char " " comment-end-char) + (newline) - ;; Empty line with side borders - (dotimes (_ current-column-pos) (insert " ")) - (insert decoration-char) - (dotimes (_ available-width) (insert " ")) - (insert " " decoration-char) - (newline) + ;; Empty line with side borders + (dotimes (_ current-column-pos) (insert " ")) + (insert empty-line) + (newline) - ;; Bottom border - (dotimes (_ current-column-pos) (insert " ")) - (insert comment-char " " border-line " " comment-end-char) - (newline))) + ;; Bottom border + (dotimes (_ current-column-pos) (insert " ")) + (insert comment-char " " border-line " " comment-end-char) + (newline)))) (defun cj/comment-heavy-box () "Insert a heavy box comment with blank lines around centered text. diff --git a/tests/test-custom-comments-comment-heavy-box.el b/tests/test-custom-comments-comment-heavy-box.el index 94d4aaa5f..8acb9ff0b 100644 --- a/tests/test-custom-comments-comment-heavy-box.el +++ b/tests/test-custom-comments-comment-heavy-box.el @@ -64,8 +64,8 @@ Returns the buffer string for assertions." (should (string-match-p "^;; \\*" result)) ;; Middle line should contain centered text (should (string-match-p "Section Header" result)) - ;; Should have side borders - (should (string-match-p "^\\*.*\\*$" result)))) + ;; Interior side-border lines carry the comment prefix/suffix (not a bare *) + (should (string-match-p "^;; \\*.*\\* ;;$" result)))) (ert-deftest test-heavy-box-elisp-custom-decoration () "Should use custom decoration character." @@ -83,8 +83,8 @@ Returns the buffer string for assertions." (let ((result (test-heavy-box-at-column 0 ";;" "" "*" "" 70))) ;; Should still generate 5 lines (should (= 5 (length (split-string result "\n" t)))) - ;; Middle line should just have side borders and spaces - (should (string-match-p "^\\*.*\\*$" result)))) + ;; Middle line should just have side borders and spaces, comment-prefixed + (should (string-match-p "^;; \\*.*\\* ;;$" result)))) (ert-deftest test-heavy-box-elisp-at-column-0 () "Should work at column 0." @@ -989,7 +989,9 @@ Add the buffer-local var, set it on each "Run a test..." selection, use it as th *** TODO [#B] TS/JS coverage status sync Update the =dev-fkeys.el= header comment (L33) — TS/JS is no longer punted; the cmd-builder at L384 emits vitest/jest. Document the prefer-vitest fallback. -** TODO [#B] heavy-box comment inserts non-comment lines :bug:solo:next: +** DONE [#B] heavy-box comment inserts non-comment lines :bug:solo:next: +CLOSED: [2026-06-15 Mon] +cj/--comment-heavy-box now prefixes the interior empty/text lines with the comment char + suffix (like cj/--comment-box) so they stay valid comments in line-comment languages, and gained the min-length guard (small/negative widths now error cleanly instead of hitting make-string). The two characterization assertions that pinned the broken bare-* lines were updated to the corrected output. =modules/custom-comments.el:427= — =cj/--comment-heavy-box= interior/empty lines carry no comment prefix, so in line-comment languages (elisp, Python) C-; C h injects syntax-breaking bare =*...= lines. The existing test characterizes the broken output (asserts =^\*.*\*$=). Prefix interiors like =cj/--comment-box= does; add the missing min-length validation (negative width hits make-string with a raw error); fix the test to assert corrected output. From the 2026-06 config audit. ** TODO [#B] jumper: register collisions and dead-marker errors :bug:solo: |
