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



> On May 21, 2024, at 4:43 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Óscar Fuentes <ofv@wanadoo.es>
>> Date: Tue, 21 May 2024 03:32:05 +0200
>> 
>> 
>> treesit-major-mode-setup setups indentation if and only if
>> treesit-simple-indent-rules is non-nil. So the major mode author is
>> forced to set that variable even when he makes no use of the
>> treesit-simple-indent facilities and instead sets
>> treesit-indent-function to his own function.
> 
> If your mode defines a treesit-indent-function, why do you need the
> help of treesit-major-mode-setup for setting up indentation?
> 
> The idea of treesit-simple-indent, AFAIU, is to automate the simple
> cases, on the assumption that the mode complex cases cannot be
> second-guessed up front, and the mode programmer will need to set that
> up manually.  For example, you can assign your functions to
> indent-line-function and indent-region-function.  Or what am I
> missing?

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. I’ve now fixed that. (Though I didn’t expect someone to use this variable.)

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?

> 
>> OTOH, the info node for "Parser-based Indentation" says:
>> 
>>     To enable the parser-based indentation engine, either set
>>  ‘treesit-simple-indent-rules’ and call ‘treesit-major-mode-setup’, or
>>  equivalently, set the value of ‘indent-line-function’ to
>>  ‘treesit-indent’.
>> 
>> However, treesit-major-mode-setup does more than what's described after
>> "equivalently":
>> 
>>  (when treesit-simple-indent-rules
>>    (setq-local treesit-simple-indent-rules
>>                (treesit--indent-rules-optimize
>>                 treesit-simple-indent-rules))
>>    (setq-local indent-line-function #'treesit-indent)
>>    (setq-local indent-region-function #'treesit-indent-region))
> 
> So this is just a matter of updating the documentation to mention
> indent-region-function?
> 
> I've added Yuan, in case he has comments or suggestions.

I also updated the manual.

Yuan




  reply	other threads:[~2024-05-22  6:23 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 [this message]
2024-05-22 14:15     ` Óscar Fuentes
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=EF75EFCE-99BA-4951-AFB2-2334124D20DE@gmail.com \
    --to=casouri@gmail.com \
    --cc=71086@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=ofv@wanadoo.es \
    /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).