diff options
| author | Yuan Fu | 2022-09-24 19:35:11 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-09-24 21:11:30 -0700 |
| commit | eba65824364474bde89bdce5f57a772d74a2c409 (patch) | |
| tree | db18cd4296be31f085e586923a7666c7100af3c9 /lisp | |
| parent | c957832cbf3e87e5a25f7c2bdb70abd959391d98 (diff) | |
| download | emacs-eba65824364474bde89bdce5f57a772d74a2c409.tar.gz emacs-eba65824364474bde89bdce5f57a772d74a2c409.zip | |
Add the treesit-search functions that supplant the removed ones
The signatures also changed.
treesit-traverse-depth-first -> treesit-search-subtree
treesit-traverse-breadth-first ->
treesit-traverse-forward -> treesit-search-forward
treesit-search-forward -> treesit-search-forward-goto
treesit-search-beginning/end -> treesit-search-forward-goto
-> treesit-induce-sparse-tree
* doc/lispref/parsing.texi (Retrieving Node): Add relevant manual
sections.
* lisp/treesit.el (treesit-search-forward-goto): New function.
* src/treesit.c (ts_traverse_sibling_helper)
(ts_traverse_match_predicate)
(ts_search_dfs)
(ts_search_forward)
(treesit-search-subtree)
(treesit-search-forward)
(ts_build_sparse_tree)
(Ftreesit_induce_sparse_tree): Add functions.
* test/src/treesit-tests.el (treesit-node-supplemental): Add comments.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/treesit.el | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 2defd83dc6f..9bdff83da89 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -722,9 +722,27 @@ indentation (target) is in green, current indentation is in red." | |||
| 722 | 722 | ||
| 723 | ;;; Search | 723 | ;;; Search |
| 724 | 724 | ||
| 725 | 725 | (defun treesit-search-forward-goto | |
| 726 | 726 | (start predicate side &optional all backward up) | |
| 727 | 727 | "Search for node in the parse tree and move point to it. | |
| 728 | |||
| 729 | Start traversing the tree from node START, and match PREDICATE with | ||
| 730 | each node along the way (except START). PREDICATE can be either a | ||
| 731 | regexp that matches against each node's type, or a function that takes | ||
| 732 | a node and returns nil/non-nil for match/no match. | ||
| 733 | |||
| 734 | If a node matches, move to that node and return the node, | ||
| 735 | otherwise return nil. SIDE controls whether we move to the start | ||
| 736 | or end of the matches node, it can be either \\='start or | ||
| 737 | \\='end. | ||
| 738 | |||
| 739 | ALL, BACKWARD, and UP are the same as in `treesit-search-forward'." | ||
| 740 | (when-let ((node (treesit-search-forward | ||
| 741 | start predicate all backward up))) | ||
| 742 | (pcase side | ||
| 743 | ('start (goto-char (treesit-node-start node))) | ||
| 744 | ('end (goto-char (treesit-node-end node)))) | ||
| 745 | node)) | ||
| 728 | 746 | ||
| 729 | ;;; Debugging | 747 | ;;; Debugging |
| 730 | 748 | ||