unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Óscar Fuentes" <oscarfv@telefonica.net>
To: Yuan Fu <casouri@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, 71086@debbugs.gnu.org
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	[thread overview]
Message-ID: <87cypec4r2.fsf@telefonica.net> (raw)
In-Reply-To: <EF75EFCE-99BA-4951-AFB2-2334124D20DE@gmail.com> (Yuan Fu's message of "Tue, 21 May 2024 23:23:30 -0700")

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	other threads:[~2024-05-22 14:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21  1:32 bug#71086: 30.0.50; Setting treesit-indent-function is not effective is treesit-simple-indent-rules is nil Óscar Fuentes
2024-05-21 11:43 ` Eli Zaretskii
2024-05-22  6:23   ` Yuan Fu
2024-05-22 14:15     ` Óscar Fuentes [this message]
2024-06-02 16:55   ` Óscar Fuentes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87cypec4r2.fsf@telefonica.net \
    --to=oscarfv@telefonica.net \
    --cc=71086@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).