GNU bug report logs -
#66845
29.1; cmake-ts-mode indentation broken
Previous Next
Reported by: Juan Palacios <jpalaciosdev <at> gmail.com>
Date: Tue, 31 Oct 2023 11:37:02 UTC
Severity: normal
Tags: patch
Found in version 29.1
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #34 received at 66845 <at> debbugs.gnu.org (full text, mbox):
On Tuesday, November 7th, 2023 at 21:52, Yuan Fu <casouri <at> gmail.com> wrote:
>
> > On Nov 7, 2023, at 9:21 AM, Randy Taylor dev <at> rjt.dev wrote:
> >
> > On Tuesday, November 7th, 2023 at 03:25, Yuan Fu casouri <at> gmail.com wrote:
> >
> > > IMO it makes more sense to use prev-sibling:
> > >
> > > ,@(ignore-errors
> > > (treesit-query-capture 'cmake '((body) @capture))
> > > `(((parent-is "body") prev-sibling 0)))
> > >
> > > This would allow users to manually adjust the indentation of a line and have the rest of the body follow that.
> >
> > This would be much more elegant but unfortunately that and my previous patch failed to account for the following:
> >
> > 1 if(TRUE) # Comment.
> > 2 endif()
> >
> > And place POINT at the end of line 1 and hit RET. It will indent to the start of the comment :(. However, you gave me an idea: use the grand-parent as the anchor (which in this case is the if - exactly what we want). I've attached a new patch which accounts for that.
>
>
> Ah, I was a bit rusty too. The approach I mentioned should also have a rule for the first sibling which anchors on the parent, while the rest siblings anchor on the previous sibling. But anchoring all on the parent is equally valid.
I see.
Could you (or someone else) install the patch to emacs-29?
>
> > Juan, thanks for testing the first patch. Please give this new one a whirl if you're able to.
> >
> > > As for why parent-bol returns the BOL of the comment line, that’s expected: The parent is body, and body starts at the comment, so of course the beginning of the parent line is the beginning of the comment line. In the image below, the highlighted portion marks the body node.
> > >
> > > Some tree-sitter grammar would mark the beginning of body at the end of if(TRUE), but what tree-sitter-cmake does here is equally valid.
> >
> > Thanks, I understand what's happening now. Whenever line_comment is NOT the first child, the beginning of body is at the end of if(TRUE). If line_comment is the first child, then the beginning of body is at the start of the comment. I was expecting them to behave the same - that's why I was so confused, and I don't really understand why it was done that way.<0001-Fix-cmake-ts-mode-indentation-Bug-66845.patch>
>
>
> You’re right. That’s a strange behavior. We should probably report to tree-sitter-cmake.
I will try to get around to that sometime next week.
This bug report was last modified 1 year and 195 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.