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

From: Theodor Thornhill <[email-masked]>
Date: Thu, 08 Dec 2022 09:11:28 +0100

Eli Zaretskii <[email-masked]> writes:

>> Date: Thu, 8 Dec 2022 03:37:54 +0200
>> Cc: [email-masked], [email-masked], [email-masked],
>>  [email-masked]
>> From: Dmitry Gutov <[email-masked]>
>> 
>> >> AFAICT, these behaviors are quite compatible. But paredit's binding
>> >> seems to be useful in more contexts.
>> > I'm fine with trying something like that on master, to see whether users
>> > like this conflation, but not on the release branch.
>> 
>> Here's a patch that people can try. From my brief testing, seems useful 
>> enough. I suppose some might dislike it, though, in some codebases where 
>> the methods/functions are consistently longer than a screenful. I do 
>> like this binding in Emacs Lisp too, though.
>
> Stefan, Lars: any comments?
>
> I'm okay with installing this on master, but please rename the new
> function to something like prog-fill-reindent; the "fill" part should
> appear in the name, to explain why we have both prog-indent and this
> function.
>
> Also, a NEWS entry and some addition to the "Multi-line Indent" node
> of the Emacs user manual would be nice.
>
> Bonus points for adding something that could use treesit.el
> capabilities, when those are available, instead of syntax-ppss, to
> determine when we are in a comment or in a string.  Or maybe Theo or
> Yuan could suggest such an addition.
>

This works perfectly as is in *-ts-modes.  At least for modes where
syntax-table is set correctly.  I don't think there's a reason to enable
treesit.el capabilities, unless there's a case where this doesn't work.

If this ends up in master, should I backport some similar feature for
the *ts-modes?

Theo