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

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

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


From: Eli Zaretskii
Subject: bug#59662: 29.0.50; [PATCH] Add treesit--indent-defun
Date: Tue, 29 Nov 2022 16:15:19 +0200

Resending with correct address of Yuan.

> From: Theodor Thornhill <theo@thornhill.no>
> Cc: 59662@debbugs.gnu.org, casouri@gmail.org
> Date: Tue, 29 Nov 2022 13:14:21 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> Cc: eliz@gnu.org, casouri@gmail.org
> >> From: Theodor Thornhill <theo@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
> 





reply via email to

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