From 9fab95f193eb7da9e6787122b885d1de29b5b657 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sat, 21 Oct 2023 16:05:05 -0400 Subject: [PATCH] Use buffer-local comment-continue in comment-indent-new-line As the FIXME said, comment-indent-new-line was wiping out the value of comment-continue even if it had been set explicitly. Checking local-variable-p should be sufficient to fix this. This makes comment-indent-new-line work properly if comment-continue can't be recalculated from comment-start, such as if comment-continue is all whitespace. * lisp/newcomment.el (comment-indent-new-line): Don't set comment-continue to nil if it's local-variable-p. * test/lisp/newcomment-tests.el (local-comment-continue-in-comment-indent-new-line): Add a test. --- lisp/newcomment.el | 5 +++-- test/lisp/newcomment-tests.el | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 9ae7de70a0e..b217f700f22 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -1541,9 +1541,10 @@ comment-indent-new-line (cadr (assoc comment-style comment-styles)))) ;; Recreate comment-continue from comment-start. - ;; FIXME: wrong if comment-continue was set explicitly! ;; FIXME: use prev line's continuation if available. - (comment-continue nil)) + (comment-continue (if (local-variable-p 'comment-continue) + comment-continue + nil))) (comment-indent continuep)) (save-excursion (let ((pt (point))) diff --git a/test/lisp/newcomment-tests.el b/test/lisp/newcomment-tests.el index cb0f304c463..9851b4c2c45 100644 --- a/test/lisp/newcomment-tests.el +++ b/test/lisp/newcomment-tests.el @@ -36,4 +36,21 @@ test-uncomment-space-comment-continue (uncomment-region (point-min) (point-max)) (buffer-string)))))) +(ert-deftest local-comment-continue-in-comment-indent-new-line () + (with-temp-buffer + (setq-local comment-start "/* ") + (setq-local comment-end "*/") + (insert "foo") + (newline) + (insert "bar") + (forward-line -1) + (end-of-line) + (comment-region (point-min) (point-max)) + (should (equal (thing-at-point 'line) "/* foo\n")) + (comment-indent-new-line) + (should (equal (thing-at-point 'line) " * \n")) + (setq-local comment-continue " ") + (comment-indent-new-line) + (should (equal (thing-at-point 'line) " \n")))) + ;;; newcomment-tests.el ends here -- 2.39.3