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

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

bug#71086: 30.0.50; Setting treesit-indent-function is not effective is


From: Óscar Fuentes
Subject: bug#71086: 30.0.50; Setting treesit-indent-function is not effective is treesit-simple-indent-rules is nil
Date: Wed, 22 May 2024 16:15:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Yuan Fu <casouri@gmail.com> writes:

> There are actually another level of customization between setting
> treesit-simple-indent-rules and setting indent-line-function, which is
> setting treesit-indent-function. IIUC Óscar is trying to do that but
> found out treesit-major-mode-setup doesn’t automatically setup
> indent-line-functions when treesit-indent-function is set.

More specifically, I found that treesit-major-mode-setup doesn't setup
indentation when treesit-simple-indent-rules is *not* set, even when
treesit-indent-function has been set.

> I’ve now fixed that.

Indeed, thank you.

> (Though I didn’t expect someone to use this variable.)

Why not? It is documented and the natural alternative when
treesit-simple-indent-rules is not fit for the job, isn't it?

> And to Óscar, I’m curious and interested to know what indentation
> function you came up with; if it’s useful maybe we can add it to
> Emacs?

I started with treesit-simple-indent-rules until I stumbled on something
that it is not easily workable with the existing functions. My language
has a Lisp syntax, and the problem was with indenting comments (and with
how the presence of comments affected the indentation of other things).

For instance, the typical indentation of

(if p
    foo
  bar)

That's simple enough to achieve with treesit-simple-indent-rules, but if
we insert a comment:

(if p
    ;; blah
    (foo)
  (bar))

things suddenly turn hairy.

Likewise, starting with this:

(progn (foo)
       (bar))

... after inserting a comment, this is the desired indentation:

(progn ;; blah
  (foo)
  (bar))

... not this:

(progn ;; blah
       (foo)
       (bar))

Maybe a variant of `match' and `nth-sibling' that take an argument of
node types to skip would be enough to cover this case? That was
basically what I did.

Anyways, going the treesit-indent-function route was easy enough, and it
is more powerful, flexible and future-proof. I don't think that
treesit-simple-indent-rules would yield a significantly shorter and
mantainable implementation.

> I also updated the manual.

Thanks!

BTW, the treesit-based implementation of the major mode for this simple
language is a tiny fraction of its traditional counterpart. And
providing a great basis for adding more features :-)





reply via email to

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