]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/treesit.el: New variables for 'down-list' and 'up-list'.
authorJuri Linkov <juri@linkov.net>
Wed, 21 May 2025 06:31:45 +0000 (09:31 +0300)
committerEshel Yaron <me@eshelyaron.com>
Tue, 27 May 2025 14:26:25 +0000 (16:26 +0200)
(treesit-sexp-type-down-list, treesit-sexp-type-up-list):
New buffer-local variables.
(treesit-down-list): Use 'treesit-sexp-type-down-list'.
(treesit-up-list): Use 'treesit-sexp-type-up-list'.

* lisp/progmodes/elixir-ts-mode.el (elixir-ts-mode):
Set 'treesit-sexp-type-down-list' and
'treesit-sexp-type-up-list' to 'list'.

(cherry picked from commit 822b6cca1e1f80ab6bd28d03f29d288cc6f6ad0e)

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

index 7edf42c24895bbb1089c142479049e0508c29de1..b98a1fb96e81c235ef39e8878460dce543828d4e 100644 (file)
@@ -792,9 +792,15 @@ Return nil if NODE is not a defun node or doesn't have a name."
                    heex-ts--font-lock-feature-list)))
 
     (treesit-major-mode-setup)
+
     (setq-local syntax-propertize-function #'elixir-ts--syntax-propertize)
+
     ;; Enable the 'sexp' navigation by default
-    (treesit-cycle-sexp-type)))
+    (setq-local forward-sexp-function #'treesit-forward-sexp
+                treesit-sexp-type-regexp 'sexp
+                ;; But still use 'list' for `down-list' and `up-list'
+                treesit-sexp-type-down-list 'list
+                treesit-sexp-type-up-list 'list)))
 
 (derived-mode-add-parents 'elixir-ts-mode '(elixir-mode))
 
index c3e17a8dc9cca3525bb973325ca6adf1da9ad936..163ed1907436d5a31dd8c2f5939c944ff6af3bca 100644 (file)
@@ -2973,6 +2973,14 @@ 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'.
+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'.
+This is used by `treesit-up-list'.")
+
 ;; Avoid interpreting the symbol `list' as a function.
 (put 'list 'treesit-thing-symbol t)
 
@@ -3118,7 +3126,9 @@ redefined by the variable `down-list-function'.
 
 ARG is described in the docstring of `down-list'."
   (interactive "^p")
-  (let* ((pred (or treesit-sexp-type-regexp 'list))
+  (let* ((pred (or treesit-sexp-type-down-list
+                   treesit-sexp-type-regexp
+                   'list))
          (arg (or arg 1))
          (cnt arg)
          (inc (if (> arg 0) 1 -1)))
@@ -3134,7 +3144,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 treesit-sexp-type-regexp)
+        (or (when (and (null (or treesit-sexp-type-down-list
+                                 treesit-sexp-type-regexp))
                        default-pos
                        (or (null child)
                            (if (> arg 0)
@@ -3159,7 +3170,9 @@ redefined by the variable `up-list-function'.
 
 ARG is described in the docstring of `up-list'."
   (interactive "^p")
-  (let* ((pred (or treesit-sexp-type-regexp 'list))
+  (let* ((pred (or treesit-sexp-type-up-list
+                   treesit-sexp-type-regexp
+                   'list))
          (arg (or arg 1))
          (treesit--parser-overlay-offset -1)
          (cnt arg)
@@ -3187,7 +3200,8 @@ ARG is described in the docstring of `up-list'."
                             (treesit-node-at (point) (car parsers)) pred)
                     parsers (cdr parsers)))))
 
-        (or (when (and (null treesit-sexp-type-regexp)
+        (or (when (and (null (or treesit-sexp-type-up-list
+                                 treesit-sexp-type-regexp))
                        default-pos
                        (or (null parent)
                            (if (> arg 0)