bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#67462: 30.0.50; prog-fill-reindent-defun does not respect buffer-loc


From: Dmitry Gutov
Subject: bug#67462: 30.0.50; prog-fill-reindent-defun does not respect buffer-local fill-paragraph-function
Date: Fri, 1 Dec 2023 01:56:40 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0

On 30/11/2023 22:40, Jens Schmidt wrote:
If so, perhaps we should offer a user option to let users choose which
method to use, because some might prefer the new behavior?
I'd be fine with that, and also with making the new behavior the
default.  A reference to that user option would also nicely complete the
NEWS entry, which IMO currently is a bit weak in mentioning the possible
consequences of the new feature.

Dmitry, what do you think?

I think we should try to see whether those custom functions are better, and in which cases.

makefile-mode is actually an odd case because while it inherits from prog-mode, it doesn't quite satisfy an informal definition of what should be prog modes: its value of indent-line-function is #'indent-to-left-margin, which looks more like a text mode.

As a consequence, prog-fill-reindent-defun usually does nothing good outside of strings and comments in makefile-mode. Since I'm guessing the idea of ceasing to derive from prog-mode right away is not going to fly, we can add exceptions like this (with a docstring update, of course):

diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 37c54a90f42..1927de7de2c 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -165,7 +165,10 @@ prog-fill-reindent-defun
                  (treesit-node-at (point)) 'text t))))
       (if (or treesit-text-node
               (nth 8 (syntax-ppss))
-              (re-search-forward "\\s-*\\s<" (line-end-position) t))
+              (re-search-forward "\\s-*\\s<" (line-end-position) t)
+              (memq indent-line-function
+                    '(indent-relative
+                      indent-to-left-margin)))
           (fill-paragraph argument (region-active-p))
         (beginning-of-defun)
         (let ((start (point)))

or even just this:

diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 37c54a90f42..0ff3701f8fc 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -165,7 +165,8 @@ prog-fill-reindent-defun
                  (treesit-node-at (point)) 'text t))))
       (if (or treesit-text-node
               (nth 8 (syntax-ppss))
-              (re-search-forward "\\s-*\\s<" (line-end-position) t))
+              (re-search-forward "\\s-*\\s<" (line-end-position) t)
+              (not beginning-of-defun-function))
           (fill-paragraph argument (region-active-p))
         (beginning-of-defun)
         (let ((start (point)))

because defun navigation is not set up there either.

fortran, octave and cfengine, however, could use rebinding or user options (I can't really form an opinion on which of the behaviors is more useful). cfengine doesn't set fill-paragraph-function either, so the required changes would be a little less trivial than for the others. But using the prog-mode's binding by default is probably better for consistency.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]