bug#68493: Got to be a better way to customize c-ts-mode indentation
Tomas Nordin <[email protected]> Mon, 03 Aug 2026 21:19:29 +0000
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
--=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Bj=C3=B6rn Lindqvist <[email protected]> writes: > Den m=C3=A5n 3 aug. 2026 kl 14:46 skrev Tomas Nordin <[email protected]>: >> Is the following description this bug? Or should I talk more about it in >> some other or new report? >> >> Its about indentation of concatanated strings like this (in a c-buffer) >> >> char *lines =3D >> "line1\n" >> "line2\n" >> >> The above is what I "get" with c-mode (in emacs -Q). If I switch over to >> c-ts-mode and say C-x h and TAB, I get >> >> char *lines =3D >> "line1\n" >> "line2\n" >> >> Further literals will align with "line2\n". I would like it to be >> aligned as with c-mode. Is there a setting for this? >> >> This has been observed with >> >> GNU Emacs 31.0.90 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.49, c= airo version 1.18.4) of 2026-07-02 > > Hello Tomas, > > I can confirm the bug in 32.0.50. However, my c-ts-mode config I > posted on emacs-devel fixes it: > > https://gist.github.com/bjourne/31f53043c72728cb4d8b90feedd0625b > > You can take inspiration from that. Specifically, you need to prepend the > rule ((parent-is "concatenated_string") parent 0) to > treesit-simple-indent-rules. Thanks for inspiration. I spent time trying to understand this stuff better. After that time I don't understand it much better, but maybe a little bit. With shotgun programming I arrived at the attached patch. It fixes the problem I reported, and here are two examples where I get what I want: helpexit (argc, argv, 0, 2, "Usage: toks [--help] [<delims> [<startchar>]]\n" "Read lines from stdin and print tokens."); and char *lines =3D "line1\n" "line2\n"; The patch was made on top of todays emacs-31. I re-built the whole thing (patch applied) and will now run with it for some time and see if it holds. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=c-ts-mode.el.diff diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 5f064716a89..fa09cb21b34 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -503,7 +503,8 @@ c-ts-mode--simple-indent-rules "enum_specifier" "union_specifier" "function_declarator" - "template_declaration"))) + "template_declaration" + "concatenated_string"))) standalone-parent 0) ;; This is for the trailing-star stype: int * ;; func() --=-=-=--