diff options
| author | Eli Zaretskii | 2022-10-17 10:54:55 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2022-10-17 10:54:55 +0300 |
| commit | 260e47e9a3c9b3baecef81e69c218989dc0cd7a4 (patch) | |
| tree | f491a6a6adcf626423797c5103a74d8cd650e569 /src | |
| parent | c6dce90d7e57486db687606bffd92d580a7d25ca (diff) | |
| download | emacs-260e47e9a3c9b3baecef81e69c218989dc0cd7a4.tar.gz emacs-260e47e9a3c9b3baecef81e69c218989dc0cd7a4.zip | |
; Fix doc strings in treesit.c
* src/treesit.c (Ftreesit_language_version)
(Ftreesit_parser_create, Ftreesit_parser_delete)
(Ftreesit_parser_language, Ftreesit_parser_set_included_ranges)
(Ftreesit_parser_included_ranges, Ftreesit_node_start)
(Ftreesit_node_end, Ftreesit_node_parent, Ftreesit_node_child)
(Ftreesit_node_check, Ftreesit_node_field_name_for_child)
(Ftreesit_node_child_by_field_name, Ftreesit_node_next_sibling)
(Ftreesit_node_prev_sibling, Ftreesit_node_first_child_for_pos)
(Ftreesit_node_descendant_for_range, Ftreesit_pattern_expand)
(Ftreesit_query_expand, Ftreesit_query_compile)
(Ftreesit_query_capture, Ftreesit_search_subtree)
(Ftreesit_search_forward, Ftreesit_induce_sparse_tree)
(syms_of_treesit): Doc string fixes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 172 |
1 files changed, 94 insertions, 78 deletions
diff --git a/src/treesit.c b/src/treesit.c index 1170a2fa7b4..10af37981b4 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -611,8 +611,12 @@ DEFUN ("treesit-language-version", | |||
| 611 | Ftreesit_language_version, | 611 | Ftreesit_language_version, |
| 612 | Streesit_language_version, | 612 | Streesit_language_version, |
| 613 | 0, 1, 0, | 613 | 0, 1, 0, |
| 614 | doc: /* Return the language version of tree-sitter library. | 614 | doc: /* Return the language ABI version of the tree-sitter library. |
| 615 | If MIN-COMPATIBLE is non-nil, return the minimal compatible version. */) | 615 | |
| 616 | By default, report the latest ABI version supported by the library for | ||
| 617 | loading language support modules. The library is backward-compatible | ||
| 618 | with language modules which use older ABI versions; if MIN-COMPATIBLE | ||
| 619 | is non-nil, return the oldest compatible ABI version. */) | ||
| 616 | (Lisp_Object min_compatible) | 620 | (Lisp_Object min_compatible) |
| 617 | { | 621 | { |
| 618 | if (NILP (min_compatible)) | 622 | if (NILP (min_compatible)) |
| @@ -1104,10 +1108,12 @@ DEFUN ("treesit-parser-create", | |||
| 1104 | 1, 3, 0, | 1108 | 1, 3, 0, |
| 1105 | doc: /* Create and return a parser in BUFFER for LANGUAGE. | 1109 | doc: /* Create and return a parser in BUFFER for LANGUAGE. |
| 1106 | 1110 | ||
| 1107 | The parser is automatically added to BUFFER's `treesit-parser-list'. | 1111 | The parser is automatically added to BUFFER's parser list, as |
| 1108 | LANGUAGE is a language symbol. If BUFFER is nil, use the current | 1112 | returned by `treesit-parser-list'. |
| 1109 | buffer. If BUFFER already has a parser for LANGUAGE, return that | 1113 | LANGUAGE is a language symbol. If BUFFER is nil or omitted, it |
| 1110 | parser. If NO-REUSE is non-nil, always create a new parser. */) | 1114 | defaults to the current buffer. If BUFFER already has a parser for |
| 1115 | LANGUAGE, return that parser, but if NO-REUSE is non-nil, always | ||
| 1116 | create a new parser. */) | ||
| 1111 | (Lisp_Object language, Lisp_Object buffer, Lisp_Object no_reuse) | 1117 | (Lisp_Object language, Lisp_Object buffer, Lisp_Object no_reuse) |
| 1112 | { | 1118 | { |
| 1113 | ts_initialize (); | 1119 | ts_initialize (); |
| @@ -1158,7 +1164,8 @@ parser. If NO-REUSE is non-nil, always create a new parser. */) | |||
| 1158 | DEFUN ("treesit-parser-delete", | 1164 | DEFUN ("treesit-parser-delete", |
| 1159 | Ftreesit_parser_delete, Streesit_parser_delete, | 1165 | Ftreesit_parser_delete, Streesit_parser_delete, |
| 1160 | 1, 1, 0, | 1166 | 1, 1, 0, |
| 1161 | doc: /* Delete PARSER from its buffer. */) | 1167 | doc: /* Delete PARSER from its buffer's parser list. |
| 1168 | See `treesit-parser-list' for the buffer's parser list. */) | ||
| 1162 | (Lisp_Object parser) | 1169 | (Lisp_Object parser) |
| 1163 | { | 1170 | { |
| 1164 | ts_check_parser (parser); | 1171 | ts_check_parser (parser); |
| @@ -1213,7 +1220,7 @@ DEFUN ("treesit-parser-buffer", | |||
| 1213 | DEFUN ("treesit-parser-language", | 1220 | DEFUN ("treesit-parser-language", |
| 1214 | Ftreesit_parser_language, Streesit_parser_language, | 1221 | Ftreesit_parser_language, Streesit_parser_language, |
| 1215 | 1, 1, 0, | 1222 | 1, 1, 0, |
| 1216 | doc: /* Return parser's language symbol. | 1223 | doc: /* Return PARSER's language symbol. |
| 1217 | This symbol is the one used to create the parser. */) | 1224 | This symbol is the one used to create the parser. */) |
| 1218 | (Lisp_Object parser) | 1225 | (Lisp_Object parser) |
| 1219 | { | 1226 | { |
| @@ -1269,11 +1276,11 @@ DEFUN ("treesit-parser-set-included-ranges", | |||
| 1269 | 2, 2, 0, | 1276 | 2, 2, 0, |
| 1270 | doc: /* Limit PARSER to RANGES. | 1277 | doc: /* Limit PARSER to RANGES. |
| 1271 | 1278 | ||
| 1272 | RANGES is a list of (BEG . END), each (BEG . END) confines a range in | 1279 | RANGES is a list of (BEG . END), each (BEG . END) defines a region in |
| 1273 | which the parser should operate in. Each range must not overlap, and | 1280 | which the parser should operate. Regions must not overlap, and the |
| 1274 | each range should come in order. Signal `treesit-set-range-error' | 1281 | regions should come in order in the list. Signal `treesit-set-range-error' |
| 1275 | if the argument is invalid, or something else went wrong. If RANGES | 1282 | if the argument is invalid, or something else went wrong. If RANGES |
| 1276 | is nil, set PARSER to parse the whole buffer. */) | 1283 | is nil, the PARSER is to parse the whole buffer. */) |
| 1277 | (Lisp_Object parser, Lisp_Object ranges) | 1284 | (Lisp_Object parser, Lisp_Object ranges) |
| 1278 | { | 1285 | { |
| 1279 | ts_check_parser (parser); | 1286 | ts_check_parser (parser); |
| @@ -1340,7 +1347,8 @@ DEFUN ("treesit-parser-included-ranges", | |||
| 1340 | Streesit_parser_included_ranges, | 1347 | Streesit_parser_included_ranges, |
| 1341 | 1, 1, 0, | 1348 | 1, 1, 0, |
| 1342 | doc: /* Return the ranges set for PARSER. | 1349 | doc: /* Return the ranges set for PARSER. |
| 1343 | See `treesit-parser-set-ranges'. If no range is set, return nil. */) | 1350 | See `treesit-parser-set-ranges'. If no ranges are set for PARSER, |
| 1351 | return nil. */) | ||
| 1344 | (Lisp_Object parser) | 1352 | (Lisp_Object parser) |
| 1345 | { | 1353 | { |
| 1346 | ts_check_parser (parser); | 1354 | ts_check_parser (parser); |
| @@ -1413,7 +1421,7 @@ If NODE is nil, return nil. */) | |||
| 1413 | 1421 | ||
| 1414 | DEFUN ("treesit-node-start", | 1422 | DEFUN ("treesit-node-start", |
| 1415 | Ftreesit_node_start, Streesit_node_start, 1, 1, 0, | 1423 | Ftreesit_node_start, Streesit_node_start, 1, 1, 0, |
| 1416 | doc: /* Return the NODE's start position. | 1424 | doc: /* Return the NODE's start position in its buffer. |
| 1417 | If NODE is nil, return nil. */) | 1425 | If NODE is nil, return nil. */) |
| 1418 | (Lisp_Object node) | 1426 | (Lisp_Object node) |
| 1419 | { | 1427 | { |
| @@ -1433,7 +1441,7 @@ If NODE is nil, return nil. */) | |||
| 1433 | 1441 | ||
| 1434 | DEFUN ("treesit-node-end", | 1442 | DEFUN ("treesit-node-end", |
| 1435 | Ftreesit_node_end, Streesit_node_end, 1, 1, 0, | 1443 | Ftreesit_node_end, Streesit_node_end, 1, 1, 0, |
| 1436 | doc: /* Return the NODE's end position. | 1444 | doc: /* Return the NODE's end position in its buffer. |
| 1437 | If NODE is nil, return nil. */) | 1445 | If NODE is nil, return nil. */) |
| 1438 | (Lisp_Object node) | 1446 | (Lisp_Object node) |
| 1439 | { | 1447 | { |
| @@ -1469,7 +1477,7 @@ If NODE is nil, return nil. */) | |||
| 1469 | DEFUN ("treesit-node-parent", | 1477 | DEFUN ("treesit-node-parent", |
| 1470 | Ftreesit_node_parent, Streesit_node_parent, 1, 1, 0, | 1478 | Ftreesit_node_parent, Streesit_node_parent, 1, 1, 0, |
| 1471 | doc: /* Return the immediate parent of NODE. | 1479 | doc: /* Return the immediate parent of NODE. |
| 1472 | Return nil if there isn't any. If NODE is nil, return nil. */) | 1480 | Return nil if NODE has no parent. If NODE is nil, return nil. */) |
| 1473 | (Lisp_Object node) | 1481 | (Lisp_Object node) |
| 1474 | { | 1482 | { |
| 1475 | if (NILP (node)) return Qnil; | 1483 | if (NILP (node)) return Qnil; |
| @@ -1489,7 +1497,7 @@ DEFUN ("treesit-node-child", | |||
| 1489 | Ftreesit_node_child, Streesit_node_child, 2, 3, 0, | 1497 | Ftreesit_node_child, Streesit_node_child, 2, 3, 0, |
| 1490 | doc: /* Return the Nth child of NODE. | 1498 | doc: /* Return the Nth child of NODE. |
| 1491 | 1499 | ||
| 1492 | Return nil if there isn't any. If NAMED is non-nil, look for named | 1500 | Return nil if there is no Nth child. If NAMED is non-nil, look for named |
| 1493 | child only. NAMED defaults to nil. If NODE is nil, return nil. */) | 1501 | child only. NAMED defaults to nil. If NODE is nil, return nil. */) |
| 1494 | (Lisp_Object node, Lisp_Object n, Lisp_Object named) | 1502 | (Lisp_Object node, Lisp_Object n, Lisp_Object named) |
| 1495 | { | 1503 | { |
| @@ -1519,6 +1527,7 @@ DEFUN ("treesit-node-check", | |||
| 1519 | doc: /* Return non-nil if NODE has PROPERTY, nil otherwise. | 1527 | doc: /* Return non-nil if NODE has PROPERTY, nil otherwise. |
| 1520 | 1528 | ||
| 1521 | PROPERTY could be `named', `missing', `extra', `has-changes', or `has-error'. | 1529 | PROPERTY could be `named', `missing', `extra', `has-changes', or `has-error'. |
| 1530 | |||
| 1522 | Named nodes correspond to named rules in the language definition, | 1531 | Named nodes correspond to named rules in the language definition, |
| 1523 | whereas "anonymous" nodes correspond to string literals in the | 1532 | whereas "anonymous" nodes correspond to string literals in the |
| 1524 | language definition. | 1533 | language definition. |
| @@ -1564,7 +1573,7 @@ DEFUN ("treesit-node-field-name-for-child", | |||
| 1564 | Streesit_node_field_name_for_child, 2, 2, 0, | 1573 | Streesit_node_field_name_for_child, 2, 2, 0, |
| 1565 | doc: /* Return the field name of the Nth child of NODE. | 1574 | doc: /* Return the field name of the Nth child of NODE. |
| 1566 | 1575 | ||
| 1567 | Return nil if not any child or no field is found. | 1576 | Return nil if there's no Nth child, or if it has no field. |
| 1568 | If NODE is nil, return nil. */) | 1577 | If NODE is nil, return nil. */) |
| 1569 | (Lisp_Object node, Lisp_Object n) | 1578 | (Lisp_Object node, Lisp_Object n) |
| 1570 | { | 1579 | { |
| @@ -1614,7 +1623,7 @@ DEFUN ("treesit-node-child-by-field-name", | |||
| 1614 | Ftreesit_node_child_by_field_name, | 1623 | Ftreesit_node_child_by_field_name, |
| 1615 | Streesit_node_child_by_field_name, 2, 2, 0, | 1624 | Streesit_node_child_by_field_name, 2, 2, 0, |
| 1616 | doc: /* Return the child of NODE with FIELD-NAME. | 1625 | doc: /* Return the child of NODE with FIELD-NAME. |
| 1617 | Return nil if there isn't any. If NODE is nil, return nil. */) | 1626 | Return nil if there is no such child. If NODE is nil, return nil. */) |
| 1618 | (Lisp_Object node, Lisp_Object field_name) | 1627 | (Lisp_Object node, Lisp_Object field_name) |
| 1619 | { | 1628 | { |
| 1620 | if (NILP (node)) | 1629 | if (NILP (node)) |
| @@ -1639,7 +1648,7 @@ DEFUN ("treesit-node-next-sibling", | |||
| 1639 | Streesit_node_next_sibling, 1, 2, 0, | 1648 | Streesit_node_next_sibling, 1, 2, 0, |
| 1640 | doc: /* Return the next sibling of NODE. | 1649 | doc: /* Return the next sibling of NODE. |
| 1641 | 1650 | ||
| 1642 | Return nil if there isn't any. If NAMED is non-nil, look for named | 1651 | Return nil if there is no next sibling. If NAMED is non-nil, look for named |
| 1643 | siblings only. NAMED defaults to nil. If NODE is nil, return nil. */) | 1652 | siblings only. NAMED defaults to nil. If NODE is nil, return nil. */) |
| 1644 | (Lisp_Object node, Lisp_Object named) | 1653 | (Lisp_Object node, Lisp_Object named) |
| 1645 | { | 1654 | { |
| @@ -1665,8 +1674,9 @@ DEFUN ("treesit-node-prev-sibling", | |||
| 1665 | Streesit_node_prev_sibling, 1, 2, 0, | 1674 | Streesit_node_prev_sibling, 1, 2, 0, |
| 1666 | doc: /* Return the previous sibling of NODE. | 1675 | doc: /* Return the previous sibling of NODE. |
| 1667 | 1676 | ||
| 1668 | Return nil if there isn't any. If NAMED is non-nil, look for named | 1677 | Return nil if there is no previous sibling. If NAMED is non-nil, look |
| 1669 | siblings only. NAMED defaults to nil. If NODE is nil, return nil. */) | 1678 | for named siblings only. NAMED defaults to nil. If NODE is nil, |
| 1679 | return nil. */) | ||
| 1670 | (Lisp_Object node, Lisp_Object named) | 1680 | (Lisp_Object node, Lisp_Object named) |
| 1671 | { | 1681 | { |
| 1672 | if (NILP (node)) return Qnil; | 1682 | if (NILP (node)) return Qnil; |
| @@ -1690,12 +1700,12 @@ siblings only. NAMED defaults to nil. If NODE is nil, return nil. */) | |||
| 1690 | DEFUN ("treesit-node-first-child-for-pos", | 1700 | DEFUN ("treesit-node-first-child-for-pos", |
| 1691 | Ftreesit_node_first_child_for_pos, | 1701 | Ftreesit_node_first_child_for_pos, |
| 1692 | Streesit_node_first_child_for_pos, 2, 3, 0, | 1702 | Streesit_node_first_child_for_pos, 2, 3, 0, |
| 1693 | doc: /* Return the first child of NODE on POS. | 1703 | doc: /* Return the first child of NODE for buffer position POS. |
| 1694 | 1704 | ||
| 1695 | Specifically, return the first child that extends beyond POS. POS is | 1705 | Specifically, return the first child that extends beyond POS. |
| 1696 | a position in the buffer. Return nil if there isn't any. If NAMED is | 1706 | Return nil if there is no such child. |
| 1697 | non-nil, look for named children only. NAMED defaults to nil. Note that | 1707 | If NAMED is non-nil, look for named children only. NAMED defaults to nil. |
| 1698 | this function returns an immediate child, not the smallest | 1708 | Note that this function returns an immediate child, not the smallest |
| 1699 | (grand)child. If NODE is nil, return nil. */) | 1709 | (grand)child. If NODE is nil, return nil. */) |
| 1700 | (Lisp_Object node, Lisp_Object pos, Lisp_Object named) | 1710 | (Lisp_Object node, Lisp_Object pos, Lisp_Object named) |
| 1701 | { | 1711 | { |
| @@ -1730,11 +1740,12 @@ this function returns an immediate child, not the smallest | |||
| 1730 | DEFUN ("treesit-node-descendant-for-range", | 1740 | DEFUN ("treesit-node-descendant-for-range", |
| 1731 | Ftreesit_node_descendant_for_range, | 1741 | Ftreesit_node_descendant_for_range, |
| 1732 | Streesit_node_descendant_for_range, 3, 4, 0, | 1742 | Streesit_node_descendant_for_range, 3, 4, 0, |
| 1733 | doc: /* Return the smallest node that covers BEG to END. | 1743 | doc: /* Return the smallest node that covers buffer positions BEG to END. |
| 1734 | 1744 | ||
| 1735 | The returned node is a descendant of NODE. POS is a position. Return | 1745 | The returned node is a descendant of NODE. |
| 1736 | nil if there isn't any. If NAMED is non-nil, look for named child | 1746 | Return nil if there is no such node. |
| 1737 | only. NAMED defaults to nil. If NODE is nil, return nil. */) | 1747 | If NAMED is non-nil, look for named child only. NAMED defaults to nil. |
| 1748 | If NODE is nil, return nil. */) | ||
| 1738 | (Lisp_Object node, Lisp_Object beg, Lisp_Object end, Lisp_Object named) | 1749 | (Lisp_Object node, Lisp_Object beg, Lisp_Object end, Lisp_Object named) |
| 1739 | { | 1750 | { |
| 1740 | if (NILP (node)) return Qnil; | 1751 | if (NILP (node)) return Qnil; |
| @@ -1815,8 +1826,7 @@ PATTERN can be | |||
| 1815 | _ | 1826 | _ |
| 1816 | \"TYPE\" | 1827 | \"TYPE\" |
| 1817 | 1828 | ||
| 1818 | Consult Info node `(elisp)Pattern Matching' form detailed | 1829 | See Info node `(elisp)Pattern Matching' for detailed explanation. */) |
| 1819 | explanation. */) | ||
| 1820 | (Lisp_Object pattern) | 1830 | (Lisp_Object pattern) |
| 1821 | { | 1831 | { |
| 1822 | if (EQ (pattern, intern_c_string (":anchor"))) | 1832 | if (EQ (pattern, intern_c_string (":anchor"))) |
| @@ -1865,8 +1875,7 @@ A PATTERN in QUERY can be | |||
| 1865 | _ | 1875 | _ |
| 1866 | \"TYPE\" | 1876 | \"TYPE\" |
| 1867 | 1877 | ||
| 1868 | Consult Info node `(elisp)Pattern Matching' form detailed | 1878 | See Info node `(elisp)Pattern Matching' for detailed explanation. */) |
| 1869 | explanation. */) | ||
| 1870 | (Lisp_Object query) | 1879 | (Lisp_Object query) |
| 1871 | { | 1880 | { |
| 1872 | return Fmapconcat (intern_c_string ("treesit-pattern-expand"), | 1881 | return Fmapconcat (intern_c_string ("treesit-pattern-expand"), |
| @@ -2056,15 +2065,15 @@ DEFUN ("treesit-query-compile", | |||
| 2056 | Streesit_query_compile, 2, 3, 0, | 2065 | Streesit_query_compile, 2, 3, 0, |
| 2057 | doc: /* Compile QUERY to a compiled query. | 2066 | doc: /* Compile QUERY to a compiled query. |
| 2058 | 2067 | ||
| 2059 | Querying a compiled query is much faster than an uncompiled one. | 2068 | Querying with a compiled query is much faster than an uncompiled one. |
| 2060 | LANGUAGE is the language this query is for. | 2069 | LANGUAGE is the language this query is for. |
| 2061 | 2070 | ||
| 2062 | If EAGER is non-nil, immediately load LANGUAGE and compile the query. | 2071 | If EAGER is non-nil, immediately load LANGUAGE and compile the query. |
| 2063 | Otherwise defer until the query is first used. | 2072 | Otherwise defer the compilation until the query is first used. |
| 2064 | 2073 | ||
| 2065 | Signals treesit-query-error if QUERY is malformed or something else | 2074 | Signals treesit-query-error if QUERY is malformed or something else |
| 2066 | goes wrong. (This of course would only happen if EAGER is non-nil.) | 2075 | goes wrong. (This only happens if EAGER is non-nil.) |
| 2067 | You can use `treesit-query-validate' to debug the query. */) | 2076 | You can use `treesit-query-validate' to validate and debug a query. */) |
| 2068 | (Lisp_Object language, Lisp_Object query, Lisp_Object eager) | 2077 | (Lisp_Object language, Lisp_Object query, Lisp_Object eager) |
| 2069 | { | 2078 | { |
| 2070 | if (NILP (Ftreesit_query_p (query))) | 2079 | if (NILP (Ftreesit_query_p (query))) |
| @@ -2104,21 +2113,24 @@ assigned to the node in PATTERN. NODE is the captured node. | |||
| 2104 | 2113 | ||
| 2105 | QUERY is either a string query, a sexp query, or a compiled query. | 2114 | QUERY is either a string query, a sexp query, or a compiled query. |
| 2106 | See Info node `(elisp)Pattern Matching' for how to write a query in | 2115 | See Info node `(elisp)Pattern Matching' for how to write a query in |
| 2107 | either string or s-expression form. When using repeatedly, a compiled | 2116 | either string or sexp form. When using repeatedly, a compiled query |
| 2108 | query is much faster than a string or sexp one, so it is recommend to | 2117 | is much faster than a string or sexp one, so it is recommend to |
| 2109 | compile your queries if it will be used over and over. | 2118 | compile your query if it will be used repeatedly. |
| 2110 | 2119 | ||
| 2111 | BEG and END, if both non-nil, specifies the range in which the query | 2120 | BEG and END, if both non-nil, specify the region of buffer positions |
| 2112 | is executed. If NODE-ONLY is non-nil, return a list of nodes. | 2121 | in which the query is executed. |
| 2113 | 2122 | ||
| 2114 | Besides a node, NODE can also be a parser, then the root node of that | 2123 | If NODE-ONLY is non-nil, return a list of nodes. |
| 2115 | parser is used; NODE can be a language symbol, then the root node of a | 2124 | |
| 2125 | Besides a node, NODE can also be a parser, in which case the root node | ||
| 2126 | of that parser is used. | ||
| 2127 | NODE can also be a language symbol, in which case the root node of a | ||
| 2116 | parser for that language is used. If such a parser doesn't exist, it | 2128 | parser for that language is used. If such a parser doesn't exist, it |
| 2117 | is created. | 2129 | is created. |
| 2118 | 2130 | ||
| 2119 | Signals treesit-query-error if QUERY is malformed or something else | 2131 | Signal `treesit-query-error' if QUERY is malformed or something else |
| 2120 | goes wrong. You can use `treesit-query-validate' to debug the | 2132 | goes wrong. You can use `treesit-query-validate' to validate and debug |
| 2121 | query. */) | 2133 | the query. */) |
| 2122 | (Lisp_Object node, Lisp_Object query, | 2134 | (Lisp_Object node, Lisp_Object query, |
| 2123 | Lisp_Object beg, Lisp_Object end, Lisp_Object node_only) | 2135 | Lisp_Object beg, Lisp_Object end, Lisp_Object node_only) |
| 2124 | { | 2136 | { |
| @@ -2403,16 +2415,16 @@ ts_search_forward (TSNode *start, Lisp_Object pred, Lisp_Object parser, | |||
| 2403 | DEFUN ("treesit-search-subtree", | 2415 | DEFUN ("treesit-search-subtree", |
| 2404 | Ftreesit_search_subtree, | 2416 | Ftreesit_search_subtree, |
| 2405 | Streesit_search_subtree, 2, 5, 0, | 2417 | Streesit_search_subtree, 2, 5, 0, |
| 2406 | doc: /* Traverse the parse tree depth-first. | 2418 | doc: /* Traverse the parse tree of NODE depth-first using PREDICATE. |
| 2407 | 2419 | ||
| 2408 | Traverse the subtree of NODE, and match PREDICATE with each node along | 2420 | Traverse the subtree of NODE, and match PREDICATE with each node along |
| 2409 | the way. PREDICATE is a regexp string that matches against each | 2421 | the way. PREDICATE is a regexp string that matches against each |
| 2410 | node's type case-insensitively, or a function that takes a node and | 2422 | node's type case-insensitively, or a function that takes a node and |
| 2411 | returns nil/non-nil. | 2423 | returns nil/non-nil. |
| 2412 | 2424 | ||
| 2413 | By default, only traverse named nodes, if ALL is non-nil, traverse all | 2425 | By default, only traverse named nodes, but if ALL is non-nil, traverse |
| 2414 | nodes. If BACKWARD is non-nil, traverse backwards. If LIMIT is | 2426 | all nodes. If BACKWARD is non-nil, traverse backwards. If LIMIT is |
| 2415 | non-nil, we only traverse that number of levels down in the tree. | 2427 | non-nil, only traverse nodes up to that number of levels down in the tree. |
| 2416 | 2428 | ||
| 2417 | Return the first matched node, or nil if none matches. */) | 2429 | Return the first matched node, or nil if none matches. */) |
| 2418 | (Lisp_Object node, Lisp_Object predicate, Lisp_Object all, | 2430 | (Lisp_Object node, Lisp_Object predicate, Lisp_Object all, |
| @@ -2448,20 +2460,20 @@ Return the first matched node, or nil if none matches. */) | |||
| 2448 | DEFUN ("treesit-search-forward", | 2460 | DEFUN ("treesit-search-forward", |
| 2449 | Ftreesit_search_forward, | 2461 | Ftreesit_search_forward, |
| 2450 | Streesit_search_forward, 2, 5, 0, | 2462 | Streesit_search_forward, 2, 5, 0, |
| 2451 | doc: /* Search for node in the parse tree. | 2463 | doc: /* Search for node matching PREDICATE in the parse tree of START. |
| 2452 | 2464 | ||
| 2453 | Start traversing the tree from node START, and match PREDICATE with | 2465 | Start traversing the tree from node START, and match PREDICATE with |
| 2454 | each node along the way (except START). PREDICATE is a regexp string | 2466 | each node (except START itself) along the way. PREDICATE is a regexp |
| 2455 | that matches against each node's type case-insensitively, or a | 2467 | string that matches against each node's type case-insensitively, or a |
| 2456 | function that takes a node and returns nil/non-nil. | 2468 | function that takes a node and returns non-nil if it matches. |
| 2457 | 2469 | ||
| 2458 | By default, only search for named nodes, if ALL is non-nil, search for | 2470 | By default, only search for named nodes, but if ALL is non-nil, search |
| 2459 | all nodes. If BACKWARD is non-nil, search backwards. | 2471 | for all nodes. If BACKWARD is non-nil, search backwards. |
| 2460 | 2472 | ||
| 2461 | Return the first matched node, or nil if none matches. | 2473 | Return the first matched node, or nil if none matches. |
| 2462 | 2474 | ||
| 2463 | For a tree like the below where START is marked 1, traverse as | 2475 | For a tree like below, where START is marked by 1, traverse in the |
| 2464 | numbered: | 2476 | order of numbers: |
| 2465 | 16 | 2477 | 16 |
| 2466 | | | 2478 | | |
| 2467 | 3--------4-----------8 | 2479 | 3--------4-----------8 |
| @@ -2472,8 +2484,8 @@ numbered: | |||
| 2472 | | | | | | | 2484 | | | | | | |
| 2473 | 10 11 13 14 15 | 2485 | 10 11 13 14 15 |
| 2474 | 2486 | ||
| 2475 | If UP is non-nil, only traverse to siblings and parents. In that | 2487 | If UP is non-nil, only traverse siblings and parents of START. In that |
| 2476 | case, only 1 3 4 8 16 would be traversed. */) | 2488 | case, only the nodes 1, 3, 4, 8, and 16 would be traversed. */) |
| 2477 | (Lisp_Object start, Lisp_Object predicate, Lisp_Object all, | 2489 | (Lisp_Object start, Lisp_Object predicate, Lisp_Object all, |
| 2478 | Lisp_Object backward, Lisp_Object up) | 2490 | Lisp_Object backward, Lisp_Object up) |
| 2479 | { | 2491 | { |
| @@ -2550,7 +2562,7 @@ DEFUN ("treesit-induce-sparse-tree", | |||
| 2550 | Streesit_induce_sparse_tree, 2, 4, 0, | 2562 | Streesit_induce_sparse_tree, 2, 4, 0, |
| 2551 | doc: /* Create a sparse tree of ROOT's subtree. | 2563 | doc: /* Create a sparse tree of ROOT's subtree. |
| 2552 | 2564 | ||
| 2553 | Basically, take the subtree under ROOT, and comb it so only the nodes | 2565 | This takes the subtree under ROOT, and combs it so only the nodes |
| 2554 | that match PREDICATE are left, like picking out grapes on the vine. | 2566 | that match PREDICATE are left, like picking out grapes on the vine. |
| 2555 | PREDICATE is a regexp string that matches against each node's type | 2567 | PREDICATE is a regexp string that matches against each node's type |
| 2556 | case-insensitively. | 2568 | case-insensitively. |
| @@ -2570,17 +2582,20 @@ PREDICATE is "is letter", the returned tree is the one on the right. | |||
| 2570 | | | | | 2582 | | | | |
| 2571 | e 5 e | 2583 | e 5 e |
| 2572 | 2584 | ||
| 2573 | If PROCESS-FN is non-nil, instead of returning the matched nodes, pass | 2585 | If PROCESS-FN is non-nil, it should be a function of one argument. In |
| 2574 | each node to PROCESS-FN use the return value instead. If non-nil, | 2586 | that case, instead of returning the matched nodes, pass each node to |
| 2575 | LIMIT is the number of levels to go down from ROOT. | 2587 | PROCESS-FN, and use its return value instead. |
| 2588 | |||
| 2589 | If non-nil, LIMIT is the number of levels to go down the tree from ROOT. | ||
| 2576 | 2590 | ||
| 2577 | Each node in the returned tree looks like (NODE . (CHILD ...)). The | 2591 | Each node in the returned tree looks like (NODE . (CHILD ...)). The |
| 2578 | root of this tree might be nil, if ROOT doesn't match PREDICATE. If | 2592 | root of this tree might be nil, if ROOT doesn't match PREDICATE. |
| 2579 | no node matches PRED, return nil. | 2593 | |
| 2594 | If no node matches PREDICATE, return nil. | ||
| 2580 | 2595 | ||
| 2581 | PREDICATE can also be a function that takes a node and returns | 2596 | PREDICATE can also be a function that takes a node and returns |
| 2582 | nil/non-nil, but it is slower and more memory consuming than | 2597 | nil/non-nil, but it is slower and more memory consuming than using |
| 2583 | regexp. */) | 2598 | a regexp. */) |
| 2584 | (Lisp_Object root, Lisp_Object predicate, Lisp_Object process_fn, | 2599 | (Lisp_Object root, Lisp_Object predicate, Lisp_Object process_fn, |
| 2585 | Lisp_Object limit) | 2600 | Lisp_Object limit) |
| 2586 | { | 2601 | { |
| @@ -2700,23 +2715,24 @@ By default, Emacs assumes the dynamic library for LANG is | |||
| 2700 | libtree-sitter-LANG.EXT, where EXT is the OS specific extension for | 2715 | libtree-sitter-LANG.EXT, where EXT is the OS specific extension for |
| 2701 | dynamic libraries. Emacs also assumes that the name of the C function | 2716 | dynamic libraries. Emacs also assumes that the name of the C function |
| 2702 | the library provides is tree_sitter_LANG. If that is not the case, | 2717 | the library provides is tree_sitter_LANG. If that is not the case, |
| 2703 | add an entry | 2718 | you can add an entry |
| 2704 | 2719 | ||
| 2705 | (LANG LIBRARY-BASE-NAME FUNCTION-NAME) | 2720 | (LANG LIBRARY-BASE-NAME FUNCTION-NAME) |
| 2706 | 2721 | ||
| 2707 | to this list, where LIBRARY-BASE-NAME is the filename of the dynamic | 2722 | to this list, where LIBRARY-BASE-NAME is the filename of the dynamic |
| 2708 | library without extension, FUNCTION-NAME is the function provided by | 2723 | library without the file-name extension, and FUNCTION-NAME is the |
| 2709 | the library. */); | 2724 | function provided by the library. */); |
| 2710 | Vtreesit_load_name_override_list = Qnil; | 2725 | Vtreesit_load_name_override_list = Qnil; |
| 2711 | 2726 | ||
| 2712 | DEFVAR_LISP ("treesit-extra-load-path", | 2727 | DEFVAR_LISP ("treesit-extra-load-path", |
| 2713 | Vtreesit_extra_load_path, | 2728 | Vtreesit_extra_load_path, |
| 2714 | doc: | 2729 | doc: |
| 2715 | /* Extra load paths of tree-sitter language definitions. | 2730 | /* Additional directories to look for tree-sitter language definitions. |
| 2731 | The value should be a list of directories. | ||
| 2716 | When trying to load a tree-sitter language definition, | 2732 | When trying to load a tree-sitter language definition, |
| 2717 | Emacs looks at directories in this variable, | 2733 | Emacs first looks in the directories mentioned in in this variable, |
| 2718 | `user-emacs-directory'/tree-sitter, and system default locations for | 2734 | then in the `tree-sitter' subdirectory of `user-emacs-directory', and |
| 2719 | dynamic libraries, in that order. */); | 2735 | then in the system default locations for dynamic libraries, in that order. */); |
| 2720 | Vtreesit_extra_load_path = Qnil; | 2736 | Vtreesit_extra_load_path = Qnil; |
| 2721 | 2737 | ||
| 2722 | defsubr (&Streesit_language_available_p); | 2738 | defsubr (&Streesit_language_available_p); |