all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Theodor Thornhill <theo@thornhill.no>
Cc: bruce.stephens@isode.com, Eli Zaretskii <eliz@gnu.org>,
	59686@debbugs.gnu.org
Subject: bug#59686: 30.0.50; tree-sitter indentation in some loops and conditional statements is wrong
Date: Sat, 3 Dec 2022 02:48:34 -0800	[thread overview]
Message-ID: <F75E7056-3D82-4B45-B11D-137BD87E290A@gmail.com> (raw)
In-Reply-To: <ff6f80b5-d94a-1d5e-b47c-1c8d8ecc5506@isode.com>


Theodor Thornhill <theo@thornhill.no> writes:

> Bruce Stephens <bruce.stephens@isode.com> writes:
>
>> On 02/12/2022 08:39, Eli Zaretskii wrote:
>>
>>> FWIW, this is an unusual style, so I see no catastrophe if it is not 110%
>>> according to expectations.  Users can easily fix that by tweaking their BOLs
>>> where important.
>>
>>
>> The example I gave would be unusual, I think, but I'd argue that the
>> situations where I saw the problem are quite natural.
>>
>> For example,
>>
>>                  } else if ( MYSTRCMP (attname, SOME_PREFIX_X400ADDRESS) ||
>>                              MYSTRCMP (attname, SOME_PREFIX_X400) ) {
>>                      FOO_ptr orp = foo_std2foo (val);
>>
>> or a function declaration with several arguments with types that are
>> rather long.
>>
>> I agree it's not a critical bug but if there's no appropriate general
>> fix it would be helpful to have some guidance for users to resolve our
>> specific cases.
>
> This is the case I was thinking of.  In the for-loop a grand-parent-bol
> on compound_statement rule would match the 'for' keyword, so the
> indentation will be correct, but this one will not, IIRC.  I plan to dig
> into this some more soon, but motivation left me a little on that issue.
> Maybe we could make a preset like:
>
> ```
> (seq
>  (parent-is "compound_statement") parent (parent-is "for_statement") bol)
> ```
>
>
> In other words, make other presets execute sequentially, move point,
> check again, and if all are true, pick indent offset.  Or allow multiple
> captures, like so:
>
> ```
> (for_statement @offset-anchor
>   body: (compound_statement (_) @to-indent))
> ```
>
> Here the @to-indent capture would get the new indent level based on
> treesit-node-start of for_statement.
>
> What do you think, Yuan?

I think we can just test for the grandparent, there is an
(undocumented) matcher n-p-gp which matches parent and grandparent.

Yuan





  parent reply	other threads:[~2022-12-03 10:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29 18:41 bug#59686: 30.0.50; tree-sitter indentation in some loops and conditional statements is wrong Bruce Stephens
2022-12-02  5:13 ` Yuan Fu
2022-12-02  5:42   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02  8:39     ` Eli Zaretskii
2022-12-02  9:20       ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 10:46       ` Bruce Stephens
2022-12-02 11:51         ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-03 10:48 ` Yuan Fu [this message]
2022-12-03 11:08   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-03 11:19     ` Yuan Fu

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

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

  git send-email \
    --in-reply-to=F75E7056-3D82-4B45-B11D-137BD87E290A@gmail.com \
    --to=casouri@gmail.com \
    --cc=59686@debbugs.gnu.org \
    --cc=bruce.stephens@isode.com \
    --cc=eliz@gnu.org \
    --cc=theo@thornhill.no \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.