bug#81533: c-ts-mode: Improved block comment indentation
Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]> Sun, 02 Aug 2026 10:26:02 -0400
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
>> I was unhappy with the way c-ts-mode indents block comments so I >> fixed it. :) Two examples, with <T> marking the point's >> position when pressing TAB. Here "second" should align to "first": >> >> int foo; /* first >> <T>second */ >> >> int foo; /* first >> >> <T>second */ >> >> The attached patch modifies the c-ts-mode block comment indentation >> rules so that >> >> 1) lines beginning with "*" are aligned to the first "*", >> 2) lines following the first or blank lines are indented three spaces, >> 3) and other lines are aligned to the previous line. "when pressing TAB" is one case, "when calling `indent-according-to-mode`" is another. The first is free to mess up because the users are right there to see the problem and fix it, but the second needs to be more conservative because it's also used in cases where the users may not see the result. The way `indent-line-function` is designed to handle this is that the function should return `noindent` when the language's syntax is of no help, such as when "indenting" the inside of a string or of a comment. The rule (1) sounds right, but rules (2) and (3) should simply refrain from modifying the line and return `noindent`. In the case of `indent-for-tab-command`, this is currently then handled by calling `indent-relative` which will do what you describe in case (3), tho not in case (2). Maybe we could/should tweak that. >> The rules work for like 99% of all block comments and is how both >> Emacs and CPython overwhelmingly indents them. [ It took me a while to understand what you meant here. I was confused by the idea of CPython indenting anything. ] > Thanks. Yuan and Stefan, any comments? These issues are basically language-independent so I'm not happy with the current code: these issues should be handled once for all tree-sitter modes. In SMIE, rule (1) is implemented by `smie-indent-comment-continue` and then `smie-indent-comment-inside` covers the remaining cases (2 and 3). === Stefan