bug#61314: 29.0.60; c-ts-mode: Multiline comment indentation broken if starting with a '-'

Eli Zaretskii <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> From: Yuan Fu <[email protected]>
> Date: Sun, 16 Aug 2026 23:39:57 -0700
> Cc: Nussbaum Ferdinand <[email protected]>,
>  [email protected]
> 
> > On Aug 15, 2026, at 6:28 AM, Eli Zaretskii <[email protected]> wrote:
> > 
> >> Cc: "[email protected]" <[email protected]>
> >> From: "Nussbaum  Ferdinand" <[email protected]>
> >> Date: Wed, 5 Aug 2026 21:09:38 +0000
> >> 
> >> I can reproduce this bug on 31.0.91. IIUC the fix relied on the default value of adaptive-fill-regexp which was
> >> changed in 67977ae5974e54d34034aa7990cf22dd162c179b.
> > 
> > Yuan, could you please look into this ASAP?
> 
> Thanks, this patch will fix this new problem. The code here expects prev-adaptive-prefix to have a match group for the prefix (the “-” in the “ - item2”), and uses that match group to find the position of the beginning of the prefix, and a recent change to prev-adaptive-prefix removed that match group.
> 
> CC’ing Mattias to see if we want to revert the removal of that match group in prev-adaptive-prefix. BUT regardless of whether we want to add the match group back, we probably should apply this patch, because with the patch, the indentation logic is more robust and doesn’t break if someone changes prev-adaptive-prefix and removes the match group themselves.

Let's actually CC Mattias 😉.

> From cb3c3ac5376035dc9b4b28703f1f0eabb462001f Mon Sep 17 00:00:00 2001
> From: Yuan Fu <[email protected]>
> Date: Sun, 16 Aug 2026 23:27:03 -0700
> Subject: [PATCH] Fix prev-adaptive-prefix anchor (bug#61314)
> 
> * lisp/treesit.el (treesit-simple-indent-presets):
> Replace (match-beginning 1) with (skip-syntax-forward "-"), both
> returns the position of the beginning of the prefix, but
> skip-syntax-forward always works regardless whether
> adaptive-fill-regexp has a match group for the prefix.
> ---
>  lisp/treesit.el | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/lisp/treesit.el b/lisp/treesit.el
> index 7fa7df08194..1273e43b2fe 100644
> --- a/lisp/treesit.el
> +++ b/lisp/treesit.el
> @@ -2559,9 +2559,11 @@ treesit-simple-indent-presets
>                           ;; has a prefix, indent to the beginning of
>                           ;; prev line's prefix rather than the end of
>                           ;; prev line's prefix. (Bug#61314).
> -                         (or (and this-line-has-prefix
> -                                  (match-beginning 1))
> -                             (match-end 0)))))))
> +                         (if this-line-has-prefix
> +                             (progn
> +                               (skip-syntax-forward "-")
> +                               (point))
> +                           (match-end 0)))))))
>          (cons 'grand-parent
>                (lambda (_n parent &rest _)
>                  (treesit-node-start (treesit-node-parent parent))))
> -- 
> 2.39.5 (Apple Git-154)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.