Subject: bug#59662: 29.0.50; [PATCH] Add treesit--indent-defun

From: Eli Zaretskii <[email-masked]>
Date: Tue, 29 Nov 2022 14:01:54 +0200

> Cc: [email-masked], [email-masked]
> From: Theodor Thornhill <[email-masked]>
> Date: Mon, 28 Nov 2022 20:32:01 +0100
> 
> I've added a function to treesit.el, for use in
> treesit-major-mode-setup.  Because the treesit-defun-type-regexp gives
> us "defuns" for free, we can set fill-paragraph-function to this new
> function, thus enabling quick formatting, and some sensible default for
> fill-paragraph.  It aims to mirror c-indent-defun.
> 
> I think this is a nice way to get this functionality for free, but I'm
> not 100% whether this is considered ok or not.

Sounds good, but why did you think it wouldn't be OK?  Anything here that
doesn't meet the eye?

> An alternative could be to add a 'treesit-mode-map' where we can
> auto-enable such constructs.

I think this is less desirable.

Yuan, WDYT?

> @@ -1698,7 +1713,10 @@ treesit-major-mode-setup
>    ;; Navigation.
>    (when treesit-defun-type-regexp
>      (setq-local beginning-of-defun-function #'treesit-beginning-of-defun)
> -    (setq-local end-of-defun-function #'treesit-end-of-defun)))
> +    (setq-local end-of-defun-function #'treesit-end-of-defun))
> +  ;; Filling
> +  (when (and treesit-defun-type-regexp treesit-simple-indent-rules)
> +    (setq-local fill-paragraph-function #'treesit--indent-defun)))

I'm a bit confused: if the function's name is treesit--indent-defun, and it
uses treesit-indent-region to do its job, why do we assign it to
fill-paragraph-function, which is supposed to _fill_, not to _indent_?