]> git.eshelyaron.com Git - emacs.git/commitdiff
Add 'treesit-sexp-thing' to use instead of 'treesit-sexp-type-regexp'.
authorJuri Linkov <juri@linkov.net>
Thu, 12 Jun 2025 17:22:42 +0000 (20:22 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 18 Jun 2025 08:12:30 +0000 (10:12 +0200)
* lisp/treesit.el (treesit-sexp-thing): New variable to use
instead of 'treesit-sexp-type-regexp'.
(treesit-sexp-thing-down-list): Rename from 'treesit-sexp-type-down-list'.
(treesit-sexp-thing-up-list): Rename from 'treesit-sexp-type-up-list'.
(treesit-forward-sexp, treesit--forward-list-with-default)
(treesit-down-list, treesit-up-list): Update references to the
above variables.
(treesit-cycle-sexp-thing): Rename from 'treesit-cycle-sexp-type'.

* lisp/progmodes/elixir-ts-mode.el (elixir-ts-mode): Update same variables.

* lisp/progmodes/heex-ts-mode.el (heex-ts-mode): Set these variables
instead of calling the function that sets them.

* lisp/progmodes/python.el (python-ts-mode): Check if variables
'treesit-sentence-type-regexp' and 'treesit-sexp-type-regexp' are bound.

https://lists.gnu.org/archive/html/emacs-devel/2025-06/msg00182.html
(cherry picked from commit 76f422da26b09a5d2646c0597871423f019a9573)

lisp/progmodes/elixir-ts-mode.el
lisp/progmodes/heex-ts-mode.el
lisp/progmodes/python.el
lisp/treesit.el

index b98a1fb96e81c235ef39e8878460dce543828d4e..d1a78ca10188736c43df8c8e59fe65cfa9e80886 100644 (file)
@@ -797,10 +797,10 @@ Return nil if NODE is not a defun node or doesn't have a name."
 
     ;; Enable the 'sexp' navigation by default
     (setq-local forward-sexp-function #'treesit-forward-sexp
-                treesit-sexp-type-regexp 'sexp
+                treesit-sexp-thing 'sexp
                 ;; But still use 'list' for `down-list' and `up-list'
-                treesit-sexp-type-down-list 'list
-                treesit-sexp-type-up-list 'list)))
+                treesit-sexp-thing-down-list 'list
+                treesit-sexp-thing-up-list 'list)))
 
 (derived-mode-add-parents 'elixir-ts-mode '(elixir-mode))
 
index cf3fad4af1053dfd31948a14ff44c4b31b1cb938..08c9019e6bc28ff06df078f8acaa6adedd8314a5 100644 (file)
@@ -255,8 +255,10 @@ Return nil if NODE is not a defun node or doesn't have a name."
                           `((elixir ,@elixir-ts--thing-settings)))))
 
     (treesit-major-mode-setup)
+
     ;; Enable the 'sexp' navigation by default
-    (treesit-cycle-sexp-type)))
+    (setq-local forward-sexp-function #'treesit-forward-sexp
+                treesit-sexp-thing 'sexp)))
 
 (derived-mode-add-parents 'heex-ts-mode '(heex-mode))
 
index 66f911ac697c51cae6ac3fe69990ea968317ccc1..3941a73e044c57a778aca5b7ec68e460b960b7f6 100644 (file)
@@ -7262,18 +7262,20 @@ implementations: `python-mode' and `python-ts-mode'."
     (setq-local treesit-defun-name-function
                 #'python--treesit-defun-name)
 
-    (setq-local treesit-sentence-type-regexp
-                (regexp-opt '("statement"
-                              "clause")))
-
-    (setq-local treesit-sexp-type-regexp
-                (regexp-opt '("expression"
-                              "string"
-                              "call"
-                              "operator"
-                              "identifier"
-                              "integer"
-                              "float")))
+    (when (boundp 'treesit-sentence-type-regexp)
+      (setq-local treesit-sentence-type-regexp
+                  (regexp-opt '("statement"
+                                "clause"))))
+
+    (when (boundp 'treesit-sexp-type-regexp)
+      (setq-local treesit-sexp-type-regexp
+                  (regexp-opt '("expression"
+                                "string"
+                                "call"
+                                "operator"
+                                "identifier"
+                                "integer"
+                                "float"))))
 
     (treesit-major-mode-setup)
 
index 1d06efb2e6d8f89d8a4b70f4b17c582af2aceda7..dae9a3bc57582b30e761a7890323a5c898e08fe5 100644 (file)
@@ -2976,12 +2976,16 @@ delimits medium sized statements in the source code.  It is,
 however, smaller in scope than sentences.  This is used by
 `treesit-forward-sexp' and friends.")
 
-(defvar-local treesit-sexp-type-down-list nil
-  "A regexp that matches the sexp nodes for `down-list'.
+(defvar-local treesit-sexp-thing nil
+  "A thing that matches the sexp nodes for `forward-sexp'.
+This is used by `treesit-forward-sexp' and `treesit-forward-list'.")
+
+(defvar-local treesit-sexp-thing-down-list nil
+  "A thing that matches the sexp nodes for `down-list'.
 This is used by `treesit-down-list'.")
 
-(defvar-local treesit-sexp-type-up-list nil
-  "A regexp that matches the sexp nodes for `up-list'.
+(defvar-local treesit-sexp-thing-up-list nil
+  "A thing that matches the sexp nodes for `up-list'.
 This is used by `treesit-up-list'.")
 
 ;; Avoid interpreting the symbol `list' as a function.
@@ -3015,7 +3019,7 @@ across lists, whereas uses `forward-sexp-default-function' to move
 across atoms (such as symbols or words) inside the list."
   (interactive "^p")
   (let ((arg (or arg 1))
-        (pred (or treesit-sexp-type-regexp 'sexp))
+        (pred (or treesit-sexp-thing 'sexp))
         (node-at-point
          (treesit-node-at (point) (treesit-language-at (point)))))
     (or (when (and node-at-point
@@ -3042,7 +3046,7 @@ Fall back to DEFAULT-FUNCTION as long as it doesn't cross
 the boundaries of the list.
 
 ARG is described in the docstring of `forward-list'."
-  (let* ((pred (or treesit-sexp-type-regexp 'list))
+  (let* ((pred (or treesit-sexp-thing 'list))
          (arg (or arg 1))
          (treesit--parser-overlay-offset (if (> arg 0) 0 -1))
          (cnt arg)
@@ -3129,8 +3133,8 @@ redefined by the variable `down-list-function'.
 
 ARG is described in the docstring of `down-list'."
   (interactive "^p")
-  (let* ((pred (or treesit-sexp-type-down-list
-                   treesit-sexp-type-regexp
+  (let* ((pred (or treesit-sexp-thing-down-list
+                   treesit-sexp-thing
                    'list))
          (arg (or arg 1))
          (cnt arg)
@@ -3147,8 +3151,8 @@ ARG is described in the docstring of `down-list'."
                         (treesit-thing-prev (point) pred)))
              (child (when sibling
                       (treesit-node-child sibling (if (> arg 0) 0 -1)))))
-        (or (when (and (null (or treesit-sexp-type-down-list
-                                 treesit-sexp-type-regexp))
+        (or (when (and (null (or treesit-sexp-thing-down-list
+                                 treesit-sexp-thing))
                        default-pos
                        (or (null child)
                            (if (> arg 0)
@@ -3173,8 +3177,8 @@ redefined by the variable `up-list-function'.
 
 ARG is described in the docstring of `up-list'."
   (interactive "^p")
-  (let* ((pred (or treesit-sexp-type-up-list
-                   treesit-sexp-type-regexp
+  (let* ((pred (or treesit-sexp-thing-up-list
+                   treesit-sexp-thing
                    'list))
          (arg (or arg 1))
          (treesit--parser-overlay-offset -1)
@@ -3203,8 +3207,8 @@ ARG is described in the docstring of `up-list'."
                             (treesit-node-at (point) (car parsers)) pred)
                     parsers (cdr parsers)))))
 
-        (or (when (and (null (or treesit-sexp-type-up-list
-                                 treesit-sexp-type-regexp))
+        (or (when (and (null (or treesit-sexp-thing-up-list
+                                 treesit-sexp-thing))
                        default-pos
                        (or (null parent)
                            (if (> arg 0)
@@ -3223,7 +3227,7 @@ ARG is described in the docstring of `up-list'."
                             (point) (point))))))
       (setq cnt (- cnt inc)))))
 
-(defun treesit-cycle-sexp-type (&optional interactive)
+(defun treesit-cycle-sexp-thing (&optional interactive)
   "Cycle the type of navigation for sexp and list commands.
 This type affects navigation commands such as `treesit-forward-sexp',
 `treesit-forward-list', `treesit-down-list', `treesit-up-list'.
@@ -3243,19 +3247,19 @@ treesit-based modes."
   (interactive "p")
   (if (not (treesit-thing-defined-p 'list (treesit-language-at (point))))
       (user-error "No `list' thing is defined in `treesit-thing-settings'")
-    (setq-local treesit-sexp-type-regexp
-                (unless treesit-sexp-type-regexp
+    (setq-local treesit-sexp-thing
+                (unless treesit-sexp-thing
                   (if (treesit-thing-defined-p
                        'sexp (treesit-language-at (point)))
                       'sexp
                     #'treesit-node-named))
                 forward-sexp-function
-                (if treesit-sexp-type-regexp
+                (if treesit-sexp-thing
                     #'treesit-forward-sexp
                   #'treesit-forward-sexp-list))
     (when interactive
-      (message "Cycle sexp type to navigate %s"
-               (or (and treesit-sexp-type-regexp
+      (message "Cycle sexp thing to navigate %s"
+               (or (and treesit-sexp-thing
                         "treesit nodes")
                    "syntax symbols and treesit lists")))))