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

From: Theodor Thornhill <[email-masked]>
Date: Thu, 29 Dec 2022 20:23:08 +0100

Dmitry Gutov <[email-masked]> writes:

> On 25/12/2022 23:54, Theodor Thornhill via Bug reports for GNU Emacs, 
> the Swiss army knife of text editors wrote:
>> 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.
>
> How about we allow indentation?
>
> And allow to be called not from BOL too?
>
> (re-search-forward "\\s-*\\s<" (line-end-position) t)

Sure!

Will you install it for me?

Theo

>From b92043c5f1c3f835d19aa9d632920804283eccfd Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <[email-masked]>
Date: Thu, 29 Dec 2022 20:19:46 +0100
Subject: [PATCH] Allow for indentation in prog-fill-reindent-defun

(bug#60322)

* lisp/progmodes/prog-mode.el (prog-fill-reindent-defun): Adjust
regexp.
---
 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 5e692980b2..2e0cb6cd25 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 "^\\s<" (line-end-position) t))
+              (re-search-forward "\\s-*\\s<" (line-end-position) t))
           (fill-paragraph argument (region-active-p))
         (beginning-of-defun)
         (let ((start (point)))
-- 
2.34.1