From: Juri Linkov Date: Wed, 21 May 2025 06:31:45 +0000 (+0300) Subject: * lisp/treesit.el: New variables for 'down-list' and 'up-list'. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2683afddd2e3c2dfd19854c539b11fbbd9578809;p=emacs.git * 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'. (cherry picked from commit 822b6cca1e1f80ab6bd28d03f29d288cc6f6ad0e) --- diff --git a/lisp/progmodes/elixir-ts-mode.el b/lisp/progmodes/elixir-ts-mode.el index 7edf42c2489..b98a1fb96e8 100644 --- a/lisp/progmodes/elixir-ts-mode.el +++ b/lisp/progmodes/elixir-ts-mode.el @@ -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)) diff --git a/lisp/treesit.el b/lisp/treesit.el index c3e17a8dc9c..163ed190743 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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)