* lisp/treesit.el: New variables for 'down-list' and 'up-list'.

(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'.
This commit is contained in:
Juri Linkov 2025-05-21 09:31:45 +03:00
parent 87fa5f565d
commit 822b6cca1e
2 changed files with 25 additions and 5 deletions

View 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))

View file

@ -2981,6 +2981,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)
@ -3126,7 +3134,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)))
@ -3142,7 +3152,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)
@ -3167,7 +3178,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)
@ -3195,7 +3208,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)