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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 76676 in the body.
You can then email your comments to 76676 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to casouri <at> gmail.com, bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Sun, 02 Mar 2025 08:55:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eli Zaretskii <eliz <at> gnu.org>:
New bug report received and forwarded. Copy sent to casouri <at> gmail.com, bug-gnu-emacs <at> gnu.org. (Sun, 02 Mar 2025 08:55:03 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.1.50; C-M-b in c-ts-mode moves too far
Date: Sun, 02 Mar 2025 10:53:52 +0200
To reproduce:

  emacs -Q
  C-x C-f src/xdisp.c
  C-u 20722 M-g g

If xdisp.c is from the master branch, that should place you on the
closing brace at the end of the following fragment (else modify the
line number accordingly or just move point to that brace):

  /* Try to scroll by specified few lines.  */
  if ((0 < scroll_conservatively
       /* FIXME: the option is supposed to affect minibuffers, but we
	  test MINI_WINDOW_P, which can also catch uses of
	  mini-windows for displaying the echo area.  Do we need to
	  distinguish these two use cases?  */
       || (scroll_minibuffer_conservatively && MINI_WINDOW_P (w))
       || 0 < emacs_scroll_step
       || temp_scroll_step
       || NUMBERP (BVAR (current_buffer, scroll_up_aggressively))
       || NUMBERP (BVAR (current_buffer, scroll_down_aggressively)))
      && CHARPOS (startp) >= BEGV
      && CHARPOS (startp) <= ZV)
    {
      /* The function returns -1 if new fonts were loaded, 1 if
	 successful, 0 if not successful.  */
      int ss = try_scrolling (window, just_this_one_p,
			      ((scroll_minibuffer_conservatively
			        && MINI_WINDOW_P (w))
			       ? SCROLL_LIMIT + 1
			       : scroll_conservatively),
			      emacs_scroll_step,
			      temp_scroll_step, last_line_misfit);
      switch (ss)
	{
	case SCROLLING_SUCCESS:
	  goto done;

	case SCROLLING_NEED_LARGER_MATRICES:
	  goto need_larger_matrices;

	case SCROLLING_FAILED:
	  break;

	default:
	  emacs_abort ();
	}
    }

Now type C-M-b.  The expected result is that point moves to the
corresponding opening brace, as shown below:

  /* Try to scroll by specified few lines.  */
  if ((0 < scroll_conservatively
       /* FIXME: the option is supposed to affect minibuffers, but we
	  test MINI_WINDOW_P, which can also catch uses of
	  mini-windows for displaying the echo area.  Do we need to
	  distinguish these two use cases?  */
       || (scroll_minibuffer_conservatively && MINI_WINDOW_P (w))
       || 0 < emacs_scroll_step
       || temp_scroll_step
       || NUMBERP (BVAR (current_buffer, scroll_up_aggressively))
       || NUMBERP (BVAR (current_buffer, scroll_down_aggressively)))
      && CHARPOS (startp) >= BEGV
      && CHARPOS (startp) <= ZV)
    { <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      /* The function returns -1 if new fonts were loaded, 1 if
	 successful, 0 if not successful.  */

But in fact, point moves to the first character of 'if' before that:

  if ((0 < scroll_conservatively

Let me know if I can supply more information.

In GNU Emacs 30.1.50 (build 9, i686-pc-mingw32) of 2025-03-01 built on
 ELIZ-PC
Repository revision: 3998dea566aee807922e6edf8d1b20f3da89b4fc
Repository branch: emacs-30
Windowing system distributor 'Microsoft Corp.', version 10.0.26100
System Description: Microsoft Windows 10 Enterprise (v10.0.2009.26100.3194)

Configured using:
 'configure -C --prefix=/d/usr --with-wide-int
 --enable-checking=yes,glyphs --without-native-compilation 'CFLAGS=-O0
 -gdwarf-4 -g3''

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG LCMS2 LIBXML2 MODULES NOTIFY W32NOTIFY
PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP XPM ZLIB

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1252

Major mode: C/*

Minor modes in effect:
  bug-reference-prog-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date subr-x mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils cl-seq
c++-ts-mode c-ts-mode c-ts-common treesit vc-git diff-mode track-changes
easy-mmode vc vc-dispatcher bug-reference byte-opt gv bytecomp
byte-compile thingatpt cc-mode cc-fonts cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs cl-loaddefs cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel touch-screen dos-w32 ls-lisp
disp-table term/w32-win w32-win w32-vars term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads w32notify w32 lcms2 multi-tty
move-toolbar make-network-process emacs)

Memory information:
((conses 16 92841 16422) (symbols 48 10144 0) (strings 16 28304 2881)
 (string-bytes 1 808502) (vectors 16 15855)
 (vector-slots 8 166559 10406) (floats 8 29 64) (intervals 40 3862 76)
 (buffers 896 11))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Mon, 03 Mar 2025 07:45:01 GMT) Full text and rfc822 format available.

Message #8 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, 03 Mar 2025 09:27:14 +0200
> But in fact, point moves to the first character of 'if' before that:
>
>   if ((0 < scroll_conservatively
>
> Let me know if I can supply more information.
>
> In GNU Emacs 30.1.50 (build 9, i686-pc-mingw32)

This is already fixed in GNU Emacs 31.0.50.
Should this fix be backported into 30.1.50?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Mon, 03 Mar 2025 13:46:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 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, 03 Mar 2025 15:44:47 +0200
> From: Juri Linkov <juri <at> linkov.net>
> Cc: 76676 <at> debbugs.gnu.org,  Yuan Fu <casouri <at> gmail.com>
> Date: Mon, 03 Mar 2025 09:27:14 +0200
> 
> > But in fact, point moves to the first character of 'if' before that:
> >
> >   if ((0 < scroll_conservatively
> >
> > Let me know if I can supply more information.
> >
> > In GNU Emacs 30.1.50 (build 9, i686-pc-mingw32)
> 
> This is already fixed in GNU Emacs 31.0.50.

Thanks, good to know.

> Should this fix be backported into 30.1.50?

Can you point me to the commit(s) which fixed that?  If they are safe,
I will backport them.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Mon, 03 Mar 2025 17:58:02 GMT) Full text and rfc822 format available.

Message #14 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: 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, 03 Mar 2025 19:56:32 +0200
>> > But in fact, point moves to the first character of 'if' before that:
>> >
>> >   if ((0 < scroll_conservatively
>> >
>> > Let me know if I can supply more information.
>> >
>> > In GNU Emacs 30.1.50 (build 9, i686-pc-mingw32)
>> 
>> This is already fixed in GNU Emacs 31.0.50.
>
> Thanks, good to know.
>
>> Should this fix be backported into 30.1.50?
>
> Can you point me to the commit(s) which fixed that?  If they are safe,
> I will backport them.

There are too many commits during the previous 5 months.
Maybe easier would be to sync whole treesit.c, treesit.el
and ts-mode files to emacs-30?




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Mon, 03 Mar 2025 19:38:01 GMT) Full text and rfc822 format available.

Notification sent to Eli Zaretskii <eliz <at> gnu.org>:
bug acknowledged by developer. (Mon, 03 Mar 2025 19:38:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 76676-done <at> debbugs.gnu.org, casouri <at> gmail.com
Subject: Re: bug#76676: 30.1.50; C-M-b in c-ts-mode moves too far
Date: Mon, 03 Mar 2025 21:37:09 +0200
> From: Juri Linkov <juri <at> linkov.net>
> Cc: 76676 <at> debbugs.gnu.org,  casouri <at> gmail.com
> Date: Mon, 03 Mar 2025 19:56:32 +0200
> 
> >> > But in fact, point moves to the first character of 'if' before that:
> >> >
> >> >   if ((0 < scroll_conservatively
> >> >
> >> > Let me know if I can supply more information.
> >> >
> >> > In GNU Emacs 30.1.50 (build 9, i686-pc-mingw32)
> >> 
> >> This is already fixed in GNU Emacs 31.0.50.
> >
> > Thanks, good to know.
> >
> >> Should this fix be backported into 30.1.50?
> >
> > Can you point me to the commit(s) which fixed that?  If they are safe,
> > I will backport them.
> 
> There are too many commits during the previous 5 months.
> Maybe easier would be to sync whole treesit.c, treesit.el
> and ts-mode files to emacs-30?

No, that's too many non-trivial changes for my palate.  I thought you
knew which changeset on master fixed that, but if you don't, then the
fix will have to wait till Emacs 31.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Tue, 04 Mar 2025 23:17:02 GMT) Full text and rfc822 format available.

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

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 76676-done <at> debbugs.gnu.org, Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#76676: 30.1.50; C-M-b in c-ts-mode moves too far
Date: Tue, 4 Mar 2025 15:16:23 -0800

> On Mar 3, 2025, at 11:37 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Juri Linkov <juri <at> linkov.net>
>> Cc: 76676 <at> debbugs.gnu.org,  casouri <at> gmail.com
>> Date: Mon, 03 Mar 2025 19:56:32 +0200
>> 
>>>>> But in fact, point moves to the first character of 'if' before that:
>>>>> 
>>>>>  if ((0 < scroll_conservatively
>>>>> 
>>>>> Let me know if I can supply more information.
>>>>> 
>>>>> In GNU Emacs 30.1.50 (build 9, i686-pc-mingw32)
>>>> 
>>>> This is already fixed in GNU Emacs 31.0.50.
>>> 
>>> Thanks, good to know.
>>> 
>>>> Should this fix be backported into 30.1.50?
>>> 
>>> Can you point me to the commit(s) which fixed that?  If they are safe,
>>> I will backport them.
>> 
>> There are too many commits during the previous 5 months.
>> Maybe easier would be to sync whole treesit.c, treesit.el
>> and ts-mode files to emacs-30?
> 
> No, that's too many non-trivial changes for my palate.  I thought you
> knew which changeset on master fixed that, but if you don't, then the
> fix will have to wait till Emacs 31.
> 
> Thanks.

Yes, to add to that, I made some significant changes to how indentation works on master which requires changes in c-ts-common.el.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Mon, 17 Mar 2025 18:00:05 GMT) Full text and rfc822 format available.

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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Tue, 18 Mar 2025 07:31:03 GMT) Full text and rfc822 format available.

Message #28 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: Tue, 18 Mar 2025 09:20:59 +0200
[Message part 1 (text/plain, inline)]
>   (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.

Actually, it's better to toggle between the traditional behavior
and navigation by the 'sexp' thing:

  (defun treesit-toggle-sexp-mode ()
    (interactive)
    (setq-local treesit-sexp-type-regexp
                (unless treesit-sexp-type-regexp
                  (if (treesit-thing-defined-p 'sexp nil)
                      'sexp
                    #'treesit-node-named))
                forward-sexp-function
                (if (eq treesit-sexp-type-regexp 'sexp)
                    #'treesit-forward-sexp
                  #'treesit-forward-sexp-list)))

The only ts-mode where the 'sexp' thing is well defined is c-ts-mode with

  (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ","))))

All other ts-modes contain desperate attempts to emulate the
traditional behavior to navigate symbols with the 'sexp' thing.
But symbol navigation is now implemented as the default behavior.

So these ts-modes should be fixed based on the pattern in c-ts-mode.
Then after toggling to the sexp mode they will navigate all ts nodes
except nodes that define boundaries.

Here is an example how such fix will look for ruby-ts-mode:

[ruby-ts-mode-sexp-thing.patch (text/x-diff, inline)]
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index 1594f301641..39113d381c7 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -1167,52 +1167,15 @@ ruby-ts-mode
 
   (setq-local treesit-thing-settings
               `((ruby
-                 (sexp ,(cons (rx
-                               bos
-                               (or
-                                "class"
-                                "singleton_class"
-                                "module"
-                                "method"
-                                "singleton_method"
-                                "array"
-                                "hash"
-                                "parenthesized_statements"
-                                "method_parameters"
-                                "array_pattern"
-                                "hash_pattern"
-                                "if"
-                                "else"
-                                "then"
-                                "unless"
-                                "case"
-                                "case_match"
-                                "when"
-                                "while"
-                                "until"
-                                "for"
-                                "block"
-                                "do_block"
-                                "begin"
-                                "integer"
-                                "identifier"
-                                "self"
-                                "super"
-                                "constant"
-                                "simple_symbol"
-                                "hash_key_symbol"
-                                "symbol_array"
-                                "string"
-                                "string_array"
-                                "heredoc_body"
-                                "regex"
-                                "argument_list"
-                                "interpolation"
-                                "instance_variable"
-                                "global_variable"
-                                )
-                               eos)
-                              #'ruby-ts--sexp-p))
+                 (sexp (not (or (and named
+                                     ,(rx (or "program"
+                                              "body_statement")))
+                                (and anonymous
+                                     ,(rx (or "do" "begin"
+                                              "if" "unless"
+                                              "def" "end"
+                                              "{" "}" "[" "]"
+                                              "(" ")" "[" "]" "|"))))))
                  (list ,(cons (rx
                                bos
                                (or

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Tue, 18 Mar 2025 17:53:13 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 76676 <at> debbugs.gnu.org
Subject: Re: bug#76676: 30.1.50; C-M-b in c-ts-mode moves too far
Date: Tue, 18 Mar 2025 19:49:01 +0200
[Message part 1 (text/plain, inline)]
> The only ts-mode where the 'sexp' thing is well defined is c-ts-mode with
>
>   (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ","))))
>
> All other ts-modes contain desperate attempts to emulate the
> traditional behavior to navigate symbols with the 'sexp' thing.
> But symbol navigation is now implemented as the default behavior.
>
> So these ts-modes should be fixed based on the pattern in c-ts-mode.
> Then after toggling to the sexp mode they will navigate all ts nodes
> except nodes that define boundaries.

Ok, here is more complete patch with a small improvement in c-ts-mode,
and using the same pattern in java/css/ruby-ts-mode:

[treesit-toggle-sexp-mode.patch (text/x-diff, inline)]
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 46332cb1e4b..f5cd3f2067c 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -3310,6 +3317,24 @@ treesit-end-of-thing
     (when dest
       (goto-char dest))))
 
+(defun treesit-toggle-sexp-mode ()
+  "Toggle the mode of navigation for sexp commands."
+  (interactive)
+  (when (treesit-thing-defined-p 'list nil)
+    (setq-local treesit-sexp-type-regexp
+                (unless treesit-sexp-type-regexp
+                  (if (treesit-thing-defined-p 'sexp nil)
+                      'sexp
+                    #'treesit-node-named))
+                forward-sexp-function
+                (if treesit-sexp-type-regexp
+                    #'treesit-forward-sexp
+                  #'treesit-forward-sexp-list))
+    (message "Toggle to mode where sexp commands navigate %s"
+             (or (and treesit-sexp-type-regexp
+                      "treesit nodes")
+                 "syntax symbols and treesit lists"))))
+
 (defun treesit-beginning-of-defun (&optional arg)
   "Move backward to the beginning of a defun.
 
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index fa5f8567b60..285d38e6411 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -1194,7 +1194,11 @@ c-ts-mode--emacs-current-defun-name
 (defvar c-ts-mode--thing-settings
   `(;; It's more useful to include semicolons as sexp so
     ;; that users can move to the end of a statement.
-    (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ","))))
+    (sexp (not (or (and named
+                        ,(rx bos (or "translation_unit") eos))
+                   (and anonymous
+                        ,(rx (or "{" "}" "[" "]" "(" ")"
+                                 "," ";"))))))
     (list
      ,(regexp-opt '("preproc_params"
                     "preproc_if"
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index c4b2282b574..cd18d6d1e28 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -436,19 +436,12 @@ java-ts-mode
 
     (setq-local treesit-thing-settings
                 `((java
-                   (sexp ,(rx (or "annotation"
-                                  "parenthesized_expression"
-                                  "argument_list"
-                                  "identifier"
-                                  "modifiers"
-                                  "block"
-                                  "body"
-                                  "literal"
-                                  "access"
-                                  "reference"
-                                  "_type"
-                                  "true"
-                                  "false")))
+                   (sexp (not (or (and named
+                                       ,(rx bos (or "program") eos))
+                                  (and anonymous
+                                       ,(rx (or "{" "}" "[" "]"
+                                                "(" ")" "<" ">"
+                                                "," ";"))))))
                    (list ,(rx bos (or "inferred_parameters"
                                       "parenthesized_expression"
                                       "argument_list"
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index 1594f301641..e8fb0f62d46 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -1167,52 +1167,17 @@ ruby-ts-mode
 
   (setq-local treesit-thing-settings
               `((ruby
-                 (sexp ,(cons (rx
-                               bos
-                               (or
-                                "class"
-                                "singleton_class"
-                                "module"
-                                "method"
-                                "singleton_method"
-                                "array"
-                                "hash"
-                                "parenthesized_statements"
-                                "method_parameters"
-                                "array_pattern"
-                                "hash_pattern"
-                                "if"
-                                "else"
-                                "then"
-                                "unless"
-                                "case"
-                                "case_match"
-                                "when"
-                                "while"
-                                "until"
-                                "for"
-                                "block"
-                                "do_block"
-                                "begin"
-                                "integer"
-                                "identifier"
-                                "self"
-                                "super"
-                                "constant"
-                                "simple_symbol"
-                                "hash_key_symbol"
-                                "symbol_array"
-                                "string"
-                                "string_array"
-                                "heredoc_body"
-                                "regex"
-                                "argument_list"
-                                "interpolation"
-                                "instance_variable"
-                                "global_variable"
-                                )
-                               eos)
-                              #'ruby-ts--sexp-p))
+                 (sexp (not (or (and named
+                                     ,(rx bos (or "program"
+                                                  "body_statement"
+                                                  "then")
+                                          eos))
+                                (and anonymous
+                                     ,(rx (or "do" "begin"
+                                              "if" "unless"
+                                              "def" "end"
+                                              "{" "}" "[" "]"
+                                              "(" ")" "[" "]" "|"))))))
                  (list ,(cons (rx
                                bos
                                (or
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 02c3618d281..9d063646184 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1781,7 +1781,13 @@ css--extract-index-name
            res)))))))
 
 (defvar css--treesit-thing-settings
-  `((css (list
+  `((css (sexp
+          (not (or (and named
+                        ,(rx bos (or "stylesheet") eos))
+                   (and anonymous
+                        ,(rx (or "{" "}" "[" "]" "(" ")"
+                                 "," ";"))))))
+         (list
           ,(rx bos (or "keyframe_block_list"
                        "block"
                        "pseudo_class_arguments"

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76676; Package emacs. (Wed, 09 Apr 2025 18:25:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 76676 <at> debbugs.gnu.org
Subject: Re: bug#76676: 30.1.50; C-M-b in c-ts-mode moves too far
Date: Wed, 09 Apr 2025 21:22:49 +0300
>> The only ts-mode where the 'sexp' thing is well defined is c-ts-mode with
>>
>>   (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ","))))
>>
>> All other ts-modes contain desperate attempts to emulate the
>> traditional behavior to navigate symbols with the 'sexp' thing.
>> But symbol navigation is now implemented as the default behavior.
>>
>> So these ts-modes should be fixed based on the pattern in c-ts-mode.
>> Then after toggling to the sexp mode they will navigate all ts nodes
>> except nodes that define boundaries.
>
> Ok, here is more complete patch with a small improvement in c-ts-mode,
> and using the same pattern in java/css/ruby-ts-mode:

Now pushed to master.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 08 May 2025 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 38 days ago.

Previous Next


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