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 #11 received at 59662 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Theodor Thornhill <theo <at> thornhill.no>
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 14:01:54 +0200
> 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?

> 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 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.