GNU bug report logs - #59662
29.0.50; [PATCH] Add treesit--indent-defun

Previous Next

Package: emacs;

Reported by: Theodor Thornhill <theo <at> thornhill.no>

Date: Mon, 28 Nov 2022 19:33:01 UTC

Severity: wishlist

Tags: patch

Found in version 29.0.50

Done: Yuan Fu <casouri <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #14 received at 59662 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 59662 <at> debbugs.gnu.org, casouri <at> gmail.org
Subject: Re: bug#59662: 29.0.50; [PATCH] Add treesit--indent-defun
Date: Tue, 29 Nov 2022 13:14:21 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

>> Cc: eliz <at> gnu.org, casouri <at> gmail.org
>> From: Theodor Thornhill <theo <at> thornhill.no>
>> 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?
>

Not really, but see below answer.

>> 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_?

This is why I was thinking it would maybe be better to put it into a
treesit-mode-map that major-modes can inherit from, thus binding it to
things such as C-c C-q.  The reason I put it in filling was because that
is a common key to press in everything _but_ prog-modes.  And prog-modes
seem to mostly just turn it off if not inside of comments etc.  This
would behave just like that, except we would reformat/reindent/refill
code.

In a way filling _is_ formatting/reindenting, at least that's how I look
at it.

Theo




This bug report was last modified 2 years and 158 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.