bug#81533: c-ts-mode: Improved block comment indentation
Eli Zaretskii <[email protected]>
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
> Date: Mon, 3 Aug 2026 23:17:03 +0200 > Cc: Yuan Fu <[email protected]>, [email protected], > Eli Zaretskii <[email protected]> > From: Björn A. Lindqvist <[email protected]> > > Hello Stefan! > > Den sön 2 aug. 2026 kl 20:02 skrev Stefan Monnier > <[email protected]>: > > My comment was just meant to state the direction in which I think we > > should move to better integrate with the rest of the infrastructure. > > I agree, but leave that job for you guys. :) I just want to scratch my > own itch: block comment indentation in c-ts-mode. > > > >> The rule (1) sounds right, but rules (2) and (3) should simply refrain > > >> from modifying the line and return `noindent`. > > > Why indent lines prefixed with "*" be indented but not other lines? > > > > Yeah, it's not great, it's a heuristic that will sometimes fail, > > If indenting is right 99.5% of the time I think we can let the 0.5% > suffer. The needs of the many outweigh the needs of the few. > > > > You could make the function public so that other modes could add it to > > > their default rules: > > > > > > ((parent-is "comment") parent c-ts-mode-common-block-comment-offset) > > > > Indeed. But then its name shouldn't start with "c-ts-", it shouldn't > > hard code "*", and it should live in another file. > > That's a way to "handle [it] once for all tree-sitter modes". > > The previous c-ts-mode block comment indentation code called three > functions: c-ts-common-looking-at-star, > c-ts-common-comment-start-after-first-star, and > c-ts-common-comment-2nd-line-matcher. Hard coding "star" in function > names is clearly worse than hard coding the "*" character so I belive > my patch is -- if not a step in the right direction -- at least not a > step in the wrong direction. :) > > Conceivably, other ts progmodes, such as php-ts-mode, that call those > three functions could call c-ts-mode-common-block-comment-offset > instead. But I didn't change them because I didn't want to create an > uber long patch and because I'm not 100% familiar with those languages > conventions for block comments. > > > Side note about your patch: `line-number-at-pos` takes time proportional > > to the size of the buffer (well, proportional to (point), actually, but > > you get the ... point 🙂), so calling it twice just to check if two > > buffer positions are on consecutive lines is very inefficient. > > Better use things like Yuan, would you mind reviewing this patch and commenting on it? > Thanks! Attached is a new patch with those issues fixed. I was about to install this, but this patch breaks the c-ts-mode tests: Test c-ts-mode-test-indentation backtrace: signal(ert-test-failed (("Mismatch in test \"Multiline Block Comment ert-fail(("Mismatch in test \"Multiline Block Comments 2 (bug#60270) ert-test--erts-test(((code lambda nil (c-ts-mode) (setq-local indent ert-test-erts-file("d:/gnu/git/emacs/trunk/test/lisp/progmodes/c-ts- #f(lambda () [t] (let* ((fn-0 #'treesit-ready-p) (args-1 (condition- #f(compiled-function () #<bytecode 0x1ea918ef364892c1>)() handler-bind-1(#f(compiled-function () #<bytecode 0x1ea918ef364892c1 ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test ert-run-test(#s(ert-test :name c-ts-mode-test-indentation :documenta ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m ert-run-tests((not (or (tag :unstable) (tag :nativecomp))) #f(compil ert-run-tests-batch((not (or (tag :unstable) (tag :nativecomp)))) ert-run-tests-batch-and-exit((not (or (tag :unstable) (tag :nativeco eval((ert-run-tests-batch-and-exit '(not (or (tag :unstable) (tag :n command-line-1(("-L" ";." "-l" "ert" "--eval" "(setq treesit-extra-l command-line() normal-top-level() Test c-ts-mode-test-indentation condition: (ert-test-failed ("Mismatch in test \"Multiline Block Comments 2 (bug#60270)\", file d:/gnu/git /emacs/trunk/test/lisp/progmodes/c-ts-mode-resources/indent.erts" "/*\n some comment\n */\n" "/*\n some comment\n */\n")) FAILED 2/4 c-ts-mode-test-indentation (0.207103 sec) at lisp/progmodes/c-ts-mode-tests.el:26 Could you please amend the code or the test to avoid the breakage, and then resubmit? Also, these changes are close to the limit of what we are able to accept from you without the copyright-assignment agreement. If you agree to start the assignment paperwork at this time, I will send you the form to fill and the instructions to go with it. Thanks.