unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60322: 30.0.50; [PATCH]: Search for comment at bol in prog-fill-reindent-defun
@ 2022-12-25 21:54 Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-12-29  9:02 ` Eli Zaretskii
  2022-12-29 16:04 ` Dmitry Gutov
  0 siblings, 2 replies; 7+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-25 21:54 UTC (permalink / raw)
  To: 60322

[-- Attachment #1: Type: text/plain, Size: 198 bytes --]


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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Search-for-comment-at-bol-in-prog-fill-reindent-defu.patch --]
[-- Type: text/x-diff, Size: 1224 bytes --]

From 8cbd514496d45e3b22523c5dc303abf97b3761f7 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-29 19:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-25 21:54 bug#60322: 30.0.50; [PATCH]: Search for comment at bol in prog-fill-reindent-defun Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-29  9:02 ` Eli Zaretskii
2022-12-29 10:48   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-29 11:12     ` Eli Zaretskii
2022-12-29 16:04 ` Dmitry Gutov
2022-12-29 19:23   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-29 19:25     ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).