Subject: 30.0.50; [PATCH]: Search for comment at bol in prog-fill-reindent-defun

From: Theodor Thornhill <[email-masked]>
Date: Sun, 25 Dec 2022 22:54:44 +0100

Hi!

Attached is a small adjustment to the regex used in
prog-fill-reindent-defun.  The point is that we shouldn't consider lines
where comments come after actual code as inside a comment.

Theo

>From 8cbd514496d45e3b22523c5dc303abf97b3761f7 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <[email-masked]>
Date: Sun, 25 Dec 2022 22:47:36 +0100
Subject: [PATCH] Search for comment at bol in prog-fill-reindent-defun

Ensure that we don't consider lines such as

    switch (foo) {
        case 2:  // If point on 'c' in 'case'
            return 2;

not to be considered for filling.

* lisp/progmodes/prog-mode.el (prog-fill-reindent-defun): Adjust
regex.
---
 lisp/progmodes/prog-mode.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index aa37a4ac86..cebd759a4e 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -164,7 +164,7 @@ prog-fill-reindent-defun
                  (treesit-node-type (treesit-node-at (point)))))))
       (if (or treesit-text-node
               (nth 8 (syntax-ppss))
-              (re-search-forward comment-start-skip (line-end-position) t))
+              (re-search-forward "^\\s<" (line-end-position) t))
           (if (memq fill-paragraph-function '(t nil))
               (lisp-fill-paragraph argument)
             (funcall fill-paragraph-function argument))
-- 
2.34.1