aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-20 23:35:57 -0500
committerCraig Jennings <c@cjennings.net>2026-07-20 23:35:57 -0500
commitc3afc208b538c0a1de0890514e9d362c840c2930 (patch)
treeaf08aa459703a7e147b6039b9768da13100891f1
parentf4c2974ba4dacf8e9417d3036b9396ec5fff9470 (diff)
downloaddotemacs-c3afc208b538c0a1de0890514e9d362c840c2930.tar.gz
dotemacs-c3afc208b538c0a1de0890514e9d362c840c2930.zip
fix(comments): render padded dividers at LENGTH exactly
available-width omitted the doubled semicolon and the space after comment-start that the emit path adds, so dividers rendered LENGTH+2 (elisp) or LENGTH+1 wide. The budget now mirrors every term min-length already counts.
-rw-r--r--modules/custom-comments.el5
-rw-r--r--tests/test-custom-comments-comment-padded-divider.el18
2 files changed, 23 insertions, 0 deletions
diff --git a/modules/custom-comments.el b/modules/custom-comments.el
index 73d29b0c..7f66424c 100644
--- a/modules/custom-comments.el
+++ b/modules/custom-comments.el
@@ -200,8 +200,13 @@ PADDING is the number of spaces before the text."
(if (string-empty-p cmt-end) 0 (1+ (length cmt-end))))))
(when (< length min-length)
(error "Length %d is too small to generate comment (minimum %d)" length min-length))
+ ;; Mirror every term the emit path adds: the prologue also inserts a
+ ;; doubled semicolon (elisp) and a trailing space that this budget used
+ ;; to omit, rendering dividers LENGTH+2 (elisp) or LENGTH+1 wide.
(let* ((available-width (- length current-column-pos
(length cmt-start)
+ (if (equal cmt-start ";") 1 0) ; doubled semicolon
+ 1 ; space after comment-start
(if (string-empty-p cmt-end) 0 (1+ (length cmt-end)))))
(line (make-string available-width (string-to-char decoration-char))))
;; Top line
diff --git a/tests/test-custom-comments-comment-padded-divider.el b/tests/test-custom-comments-comment-padded-divider.el
index d4c18905..9f2b4fd7 100644
--- a/tests/test-custom-comments-comment-padded-divider.el
+++ b/tests/test-custom-comments-comment-padded-divider.el
@@ -246,5 +246,23 @@ Returns the buffer string for assertions."
;; Should include comment-end
(should (string-match-p "\\*/" result))))
+;;; Rendered width honors LENGTH exactly
+
+(ert-deftest test-padded-divider-width-matches-length-exactly ()
+ "Normal: each decoration line renders exactly LENGTH wide.
+available-width forgot the doubled semicolon (elisp) and the space after
+comment-start that the emit path adds, so dividers rendered LENGTH+2
+(elisp) or LENGTH+1 wide, contradicting the docstring."
+ ;; elisp: lone ";" doubles to ";;" plus a space
+ (let* ((result (test-padded-divider-at-column 0 ";" "" "-" "x" 40 1))
+ (lines (split-string result "\n" t)))
+ (should (= 40 (length (car lines))))
+ (should (= 40 (length (car (last lines))))))
+ ;; c-style with an end delimiter and no doubling
+ (let* ((result (test-padded-divider-at-column 0 "/*" "*/" "-" "x" 40 1))
+ (lines (split-string result "\n" t)))
+ (should (= 40 (length (car lines))))
+ (should (= 40 (length (car (last lines)))))))
+
(provide 'test-custom-comments-comment-padded-divider)
;;; test-custom-comments-comment-padded-divider.el ends here