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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 66845 in the body.
You can then email your comments to 66845 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Tue, 31 Oct 2023 11:37:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Juan Palacios <jpalaciosdev <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 31 Oct 2023 11:37:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Using cmake grammar from https://github.com/uyha/tree-sitter-cmake
Reproduction:
1. emacs -q
2. C-x C-f test.cmake
3. M-x cmake-ts-mode
4. Insert the following text:
if(TRUE)
message("indent")
endif()
5. Move the point to the beginning of the second line.
6. TAB
7. Notice that no indentation is performed.
treesit-simple-indent-rules local value:
((cmake
((node-is ")")
parent-bol 0)
((node-is "else_command")
parent-bol 0)
((node-is "elseif_command")
parent-bol 0)
((node-is "endforeach_command")
parent-bol 0)
((node-is "endfunction_command")
parent-bol 0)
((node-is "endif_command")
parent-bol 0)
((parent-is "foreach_loop")
parent-bol cmake-ts-mode-indent-offset)
((parent-is "function_def")
parent-bol cmake-ts-mode-indent-offset)
((parent-is "if_condition")
parent-bol cmake-ts-mode-indent-offset)
((parent-is "normal_command")
parent-bol cmake-ts-mode-indent-offset)))
treesit-explore-mode shows:
(if_condition
(if_command (if) (
(argument_list
(argument (unquoted_argument)))
))
(body
(normal_command (identifier) (
(argument_list
(argument
(quoted_argument " (quoted_element) ")))
)))
(endif_command (endif) ( )))
In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38,
cairo version 1.17.8)
Windowing system distributor 'The X.Org Foundation', version 11.0.12101009
System Description: Arch Linux
Configured using:
'configure --with-x-toolkit=gtk3 --with-native-compilation=aot
--sysconfdir=/etc --prefix=/usr --libexecdir=/usr/lib
--with-tree-sitter --localstatedir=/var --with-cairo
--disable-build-details --with-harfbuzz --with-libsystemd
--with-modules 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt
-fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
-fstack-clash-protection -fcf-protection -g
-ffile-prefix-map=/build/emacs/src=/usr/src/debug/emacs -flto=auto'
'LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto=auto'
'CXXFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
-Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
-fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -g
-ffile-prefix-map=/build/emacs/src=/usr/src/debug/emacs -flto=auto''
Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB
Important settings:
value of $LANG: es_ES.utf8
locale-coding-system: utf-8-unix
Major mode: CMake
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
show-paren-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
line-number-mode: t
indent-tabs-mode: t
transient-mark-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
Load-path shadows:
None found.
Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils time-date cmake-ts-mode
treesit cl-loaddefs comp comp-cstr warnings icons subr-x rx cl-seq
cl-macs gv cl-extra help-mode bytecomp byte-compile cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo move-toolbar gtk x-toolkit xinput2 x multi-tty
make-network-process native-compile emacs)
Memory information:
((conses 16 82323 7814)
(symbols 48 7373 0)
(strings 32 20469 1882)
(string-bytes 1 626948)
(vectors 16 16173)
(vector-slots 8 335652 13542)
(floats 8 32 42)
(intervals 56 404 0)
(buffers 984 13))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Tue, 31 Oct 2023 15:52:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 66845 <at> debbugs.gnu.org (full text, mbox):
On Tuesday, October 31st, 2023 at 07:35, Juan Palacios <jpalaciosdev <at> gmail.com> wrote:
> Using cmake grammar from https://github.com/uyha/tree-sitter-cmake
>
> Reproduction:
> 1. emacs -q
> 2. C-x C-f test.cmake
> 3. M-x cmake-ts-mode
> 4. Insert the following text:
> if(TRUE)
> message("indent")
> endif()
> 5. Move the point to the beginning of the second line.
> 6. TAB
> 7. Notice that no indentation is performed.
>
> treesit-simple-indent-rules local value:
> ((cmake
> ((node-is ")")
> parent-bol 0)
> ((node-is "else_command")
> parent-bol 0)
> ((node-is "elseif_command")
> parent-bol 0)
> ((node-is "endforeach_command")
> parent-bol 0)
> ((node-is "endfunction_command")
> parent-bol 0)
> ((node-is "endif_command")
> parent-bol 0)
> ((parent-is "foreach_loop")
> parent-bol cmake-ts-mode-indent-offset)
> ((parent-is "function_def")
> parent-bol cmake-ts-mode-indent-offset)
> ((parent-is "if_condition")
> parent-bol cmake-ts-mode-indent-offset)
> ((parent-is "normal_command")
> parent-bol cmake-ts-mode-indent-offset)))
>
> treesit-explore-mode shows:
> (if_condition
> (if_command (if) (
> (argument_list
> (argument (unquoted_argument)))
> ))
> (body
> (normal_command (identifier) (
> (argument_list
> (argument
> (quoted_argument " (quoted_element) ")))
> )))
> (endif_command (endif) ( )))
>
Thanks for the report, I'll take a look tonight.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Wed, 01 Nov 2023 02:47:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 66845 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Tuesday, October 31st, 2023 at 07:35, Juan Palacios <jpalaciosdev <at> gmail.com> wrote:
> Using cmake grammar from https://github.com/uyha/tree-sitter-cmake
>
> Reproduction:
> 1. emacs -q
> 2. C-x C-f test.cmake
> 3. M-x cmake-ts-mode
> 4. Insert the following text:
> if(TRUE)
> message("indent")
> endif()
> 5. Move the point to the beginning of the second line.
> 6. TAB
> 7. Notice that no indentation is performed.
>
> treesit-simple-indent-rules local value:
> ((cmake
> ((node-is ")")
> parent-bol 0)
> ((node-is "else_command")
> parent-bol 0)
> ((node-is "elseif_command")
> parent-bol 0)
> ((node-is "endforeach_command")
> parent-bol 0)
> ((node-is "endfunction_command")
> parent-bol 0)
> ((node-is "endif_command")
> parent-bol 0)
> ((parent-is "foreach_loop")
> parent-bol cmake-ts-mode-indent-offset)
> ((parent-is "function_def")
> parent-bol cmake-ts-mode-indent-offset)
> ((parent-is "if_condition")
> parent-bol cmake-ts-mode-indent-offset)
> ((parent-is "normal_command")
> parent-bol cmake-ts-mode-indent-offset)))
>
> treesit-explore-mode shows:
> (if_condition
> (if_command (if) (
> (argument_list
> (argument (unquoted_argument)))
> ))
> (body
> (normal_command (identifier) (
> (argument_list
> (argument
> (quoted_argument " (quoted_element) ")))
> )))
> (endif_command (endif) ( )))
>
I've attached a patch fixing this while retaining compatibility with
older grammars. 2 new versions of the grammar, v0.3.0 and v0.4.0
(and anything beyond for now) wrap things in new nodes.
Yuan,
It's been awhile since I've touched any tree-sitter stuff so I'm
probably missing something obvious, but it seems to me like the
function I've added in the patch
(cmake-ts-mode--argument-list-body-offset) is working around a bug
somewhere? I'm not sure why the start of line_comment is considered
parent-bol for indentation.
For example, with this test cmake file: (test.cmake)
if(TRUE)
# Comment.
message("indent")
endif()
We get:
(source_file
(if_condition
(if_command (if) (
(argument_list
(argument (unquoted_argument)))
))
(body (line_comment)
(normal_command (identifier) (
(argument_list
(argument
(quoted_argument " (quoted_element) ")))
)))
(endif_command (endif) ( ))))
With cmake-ts-mode--argument-list-body-offset always returning
cmake-ts-mode-indent-offset (which is what I would expect), the
`parent-is "body"` rule will cause this indentation:
if(TRUE)
# Comment.
message("indent")
endif()
Am I being silly or is there indeed something odd going on?
[0001-Fix-cmake-ts-mode-indentation-Bug-66845.patch (text/x-patch, attachment)]
Added tag(s) patch.
Request was from
Stefan Kangas <stefankangas <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Thu, 02 Nov 2023 19:43:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Sun, 05 Nov 2023 14:34:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 66845 <at> debbugs.gnu.org (full text, mbox):
El mié, 1 nov 2023 a las 3:45, Randy Taylor (<dev <at> rjt.dev>) escribió:
>
> On Tuesday, October 31st, 2023 at 07:35, Juan Palacios <jpalaciosdev <at> gmail.com> wrote:
> > Using cmake grammar from https://github.com/uyha/tree-sitter-cmake
> >
> > Reproduction:
> > 1. emacs -q
> > 2. C-x C-f test.cmake
> > 3. M-x cmake-ts-mode
> > 4. Insert the following text:
> > if(TRUE)
> > message("indent")
> > endif()
> > 5. Move the point to the beginning of the second line.
> > 6. TAB
> > 7. Notice that no indentation is performed.
> >
> > treesit-simple-indent-rules local value:
> > ((cmake
> > ((node-is ")")
> > parent-bol 0)
> > ((node-is "else_command")
> > parent-bol 0)
> > ((node-is "elseif_command")
> > parent-bol 0)
> > ((node-is "endforeach_command")
> > parent-bol 0)
> > ((node-is "endfunction_command")
> > parent-bol 0)
> > ((node-is "endif_command")
> > parent-bol 0)
> > ((parent-is "foreach_loop")
> > parent-bol cmake-ts-mode-indent-offset)
> > ((parent-is "function_def")
> > parent-bol cmake-ts-mode-indent-offset)
> > ((parent-is "if_condition")
> > parent-bol cmake-ts-mode-indent-offset)
> > ((parent-is "normal_command")
> > parent-bol cmake-ts-mode-indent-offset)))
> >
> > treesit-explore-mode shows:
> > (if_condition
> > (if_command (if) (
> > (argument_list
> > (argument (unquoted_argument)))
> > ))
> > (body
> > (normal_command (identifier) (
> > (argument_list
> > (argument
> > (quoted_argument " (quoted_element) ")))
> > )))
> > (endif_command (endif) ( )))
> >
>
> I've attached a patch fixing this while retaining compatibility with
> older grammars. 2 new versions of the grammar, v0.3.0 and v0.4.0
> (and anything beyond for now) wrap things in new nodes.
I applied the patch to 29.1, and I can confirm that it's working fine.
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Sun, 05 Nov 2023 18:17:02 GMT)
Full text and
rfc822 format available.
Message #19 received at 66845 <at> debbugs.gnu.org (full text, mbox):
> 在 2023年11月5日,上午6:33,Juan Palacios <jpalaciosdev <at> gmail.com> 写道:
>
> El mié, 1 nov 2023 a las 3:45, Randy Taylor (<dev <at> rjt.dev>) escribió:
>>
>>> On Tuesday, October 31st, 2023 at 07:35, Juan Palacios <jpalaciosdev <at> gmail.com> wrote:
>>> Using cmake grammar from https://github.com/uyha/tree-sitter-cmake
>>>
>>> Reproduction:
>>> 1. emacs -q
>>> 2. C-x C-f test.cmake
>>> 3. M-x cmake-ts-mode
>>> 4. Insert the following text:
>>> if(TRUE)
>>> message("indent")
>>> endif()
>>> 5. Move the point to the beginning of the second line.
>>> 6. TAB
>>> 7. Notice that no indentation is performed.
>>>
>>> treesit-simple-indent-rules local value:
>>> ((cmake
>>> ((node-is ")")
>>> parent-bol 0)
>>> ((node-is "else_command")
>>> parent-bol 0)
>>> ((node-is "elseif_command")
>>> parent-bol 0)
>>> ((node-is "endforeach_command")
>>> parent-bol 0)
>>> ((node-is "endfunction_command")
>>> parent-bol 0)
>>> ((node-is "endif_command")
>>> parent-bol 0)
>>> ((parent-is "foreach_loop")
>>> parent-bol cmake-ts-mode-indent-offset)
>>> ((parent-is "function_def")
>>> parent-bol cmake-ts-mode-indent-offset)
>>> ((parent-is "if_condition")
>>> parent-bol cmake-ts-mode-indent-offset)
>>> ((parent-is "normal_command")
>>> parent-bol cmake-ts-mode-indent-offset)))
>>>
>>> treesit-explore-mode shows:
>>> (if_condition
>>> (if_command (if) (
>>> (argument_list
>>> (argument (unquoted_argument)))
>>> ))
>>> (body
>>> (normal_command (identifier) (
>>> (argument_list
>>> (argument
>>> (quoted_argument " (quoted_element) ")))
>>> )))
>>> (endif_command (endif) ( )))
>>>
>>
>> I've attached a patch fixing this while retaining compatibility with
>> older grammars. 2 new versions of the grammar, v0.3.0 and v0.4.0
>> (and anything beyond for now) wrap things in new nodes.
>
Hey Randy,
I just see this, sorry :-) I’ll have a look tonight or tomorrow.
Yuan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Tue, 07 Nov 2023 08:27:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 66845 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> On Oct 31, 2023, at 7:45 PM, Randy Taylor <dev <at> rjt.dev> wrote:
>
> On Tuesday, October 31st, 2023 at 07:35, Juan Palacios <jpalaciosdev <at> gmail.com> wrote:
>> Using cmake grammar from https://github.com/uyha/tree-sitter-cmake
>>
>> Reproduction:
>> 1. emacs -q
>> 2. C-x C-f test.cmake
>> 3. M-x cmake-ts-mode
>> 4. Insert the following text:
>> if(TRUE)
>> message("indent")
>> endif()
>> 5. Move the point to the beginning of the second line.
>> 6. TAB
>> 7. Notice that no indentation is performed.
>>
>> treesit-simple-indent-rules local value:
>> ((cmake
>> ((node-is ")")
>> parent-bol 0)
>> ((node-is "else_command")
>> parent-bol 0)
>> ((node-is "elseif_command")
>> parent-bol 0)
>> ((node-is "endforeach_command")
>> parent-bol 0)
>> ((node-is "endfunction_command")
>> parent-bol 0)
>> ((node-is "endif_command")
>> parent-bol 0)
>> ((parent-is "foreach_loop")
>> parent-bol cmake-ts-mode-indent-offset)
>> ((parent-is "function_def")
>> parent-bol cmake-ts-mode-indent-offset)
>> ((parent-is "if_condition")
>> parent-bol cmake-ts-mode-indent-offset)
>> ((parent-is "normal_command")
>> parent-bol cmake-ts-mode-indent-offset)))
>>
>> treesit-explore-mode shows:
>> (if_condition
>> (if_command (if) (
>> (argument_list
>> (argument (unquoted_argument)))
>> ))
>> (body
>> (normal_command (identifier) (
>> (argument_list
>> (argument
>> (quoted_argument " (quoted_element) ")))
>> )))
>> (endif_command (endif) ( )))
>>
>
> I've attached a patch fixing this while retaining compatibility with
> older grammars. 2 new versions of the grammar, v0.3.0 and v0.4.0
> (and anything beyond for now) wrap things in new nodes.
>
> Yuan,
> It's been awhile since I've touched any tree-sitter stuff so I'm
> probably missing something obvious, but it seems to me like the
> function I've added in the patch
> (cmake-ts-mode--argument-list-body-offset) is working around a bug
> somewhere? I'm not sure why the start of line_comment is considered
> parent-bol for indentation.
>
> For example, with this test cmake file: (test.cmake)
> if(TRUE)
> # Comment.
> message("indent")
> endif()
>
> We get:
> (source_file
> (if_condition
> (if_command (if) (
> (argument_list
> (argument (unquoted_argument)))
> ))
> (body (line_comment)
> (normal_command (identifier) (
> (argument_list
> (argument
> (quoted_argument " (quoted_element) ")))
> )))
> (endif_command (endif) ( ))))
>
> With cmake-ts-mode--argument-list-body-offset always returning
> cmake-ts-mode-indent-offset (which is what I would expect), the
> `parent-is "body"` rule will cause this indentation:
> if(TRUE)
> # Comment.
> message("indent")
> endif()
>
> Am I being silly or is there indeed something odd going on?<0001-Fix-cmake-ts-mode-indentation-Bug-66845.patch>
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.
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.
[Screenshot 2023-11-07 at 12.21.36 AM.png (image/png, inline)]
[Message part 3 (text/plain, inline)]
Yuan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Tue, 07 Nov 2023 17:23:01 GMT)
Full text and
rfc822 format available.
Message #25 received at 66845 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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.
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 (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Tue, 07 Nov 2023 20:13:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 66845 <at> debbugs.gnu.org (full text, mbox):
El mar, 7 nov 2023 a las 18:22, Randy Taylor (<dev <at> rjt.dev>) escribió:
>
> 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.
>
> Juan, thanks for testing the first patch. Please give this new one a whirl if you're able to.
This patch is working fine.
Thank you!
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Wed, 08 Nov 2023 02:54:01 GMT)
Full text and
rfc822 format available.
Message #31 received at 66845 <at> debbugs.gnu.org (full text, mbox):
> 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.
>
> 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.
Yuan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66845
; Package
emacs
.
(Wed, 08 Nov 2023 03:44:02 GMT)
Full text and
rfc822 format available.
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.
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Wed, 08 Nov 2023 12:35:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Juan Palacios <jpalaciosdev <at> gmail.com>
:
bug acknowledged by developer.
(Wed, 08 Nov 2023 12:35:02 GMT)
Full text and
rfc822 format available.
Message #39 received at 66845-done <at> debbugs.gnu.org (full text, mbox):
> Cc: Juan Palacios <jpalaciosdev <at> gmail.com>, 66845 <at> debbugs.gnu.org
> Date: Wed, 08 Nov 2023 03:42:37 +0000
> From: Randy Taylor <dev <at> rjt.dev>
>
> > 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?
Done, thanks.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Thu, 07 Dec 2023 12:24:07 GMT)
Full text and
rfc822 format available.
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.