GNU bug report logs - #76676
30.1.50; C-M-b in c-ts-mode moves too far

Previous Next

Package: emacs;

Reported by: Eli Zaretskii <eliz <at> gnu.org>

Date: Sun, 2 Mar 2025 08:55:02 UTC

Severity: normal

Found in version 30.1.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #25 received at 76676 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Yuan Fu <casouri <at> gmail.com>, 76676 <at> debbugs.gnu.org
Subject: Re: bug#76676: 30.1.50; C-M-b in c-ts-mode moves too far
Date: Mon, 17 Mar 2025 19:56:20 +0200
> Now type C-M-b.  The expected result is that point moves to the
> corresponding opening brace, as shown below:
>
> [...]
>
> But in fact, point moves to the first character of 'if' before that:
>
>   if ((0 < scroll_conservatively

IME half the time C-M-b needs to move to the opening brace,
and other half the time to the first character of 'if'.

When need to operate on the block enclosed inside braces, then
C-M-b is expected to move where it moved traditionally in c-mode.

But often need to take advantage of the tree-sitter grammars
and to operate directly on its nodes, e.g. select the whole
'if' condition with its body to move to another place.

We still need to address this discrepancy between these two modes.
So I tried to create a parallel set of commands: one of them
using the current sexp/list navigation, and another using
any treesit nodes.  But the problem that this requires
more duplication such as adding treesit-mark-named-thing
to work like mark-sexp, etc.

Then I realized it should be sufficient to have just one
very short command to toggle the current mode.  And here it is:

  (defun treesit-toggle-named-thing ()
    (interactive)
    (setq-local treesit-sexp-type-regexp
      (unless treesit-sexp-type-regexp #'treesit-node-named)))

For the example above it toggles between moving to the
first character of 'if' and moving to the opening brace.




This bug report was last modified 39 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.