diff options
author | Yuan Fu <casouri@gmail.com> | 2023-02-05 20:22:52 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2023-02-09 16:51:25 -0800 |
commit | 51901736965f9a6f07938fa4399d14c9283437c5 (patch) | |
tree | 70d0bc455d9d99390029a6be572adc70ce7ecf4b /src/treesit.c | |
parent | 56960a6558b65ce9643684c09203709f015e1812 (diff) | |
download | emacs-51901736965f9a6f07938fa4399d14c9283437c5.tar.gz |
Add 'live' property to treesit-node-check (bug#61235)
* doc/lispref/parsing.texi (Accessing Node Information): Document.
* src/treesit.c (treesit_parser_live_p): New function.
(Ftreesit_node_check): Add 'live' property.
* test/src/treesit-tests.el (treesit-node-api): Add tests.
Diffstat (limited to 'src/treesit.c')
-rw-r--r-- | src/treesit.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/treesit.c b/src/treesit.c index cfa3721b5e7..01c7621c6ea 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -1475,6 +1475,15 @@ This symbol is the one used to create the parser. */) return XTS_PARSER (parser)->language_symbol; } +/* Return true if PARSER is not deleted and its buffer is live. */ +static bool +treesit_parser_live_p (Lisp_Object parser) +{ + CHECK_TS_PARSER (parser); + return ((!XTS_PARSER (parser)->deleted) && + (!NILP (Fbuffer_live_p (XTS_PARSER (parser)->buffer)))); +} + /*** Parser API */ DEFUN ("treesit-parser-root-node", @@ -1908,7 +1917,8 @@ DEFUN ("treesit-node-check", Ftreesit_node_check, Streesit_node_check, 2, 2, 0, doc: /* Return non-nil if NODE has PROPERTY, nil otherwise. -PROPERTY could be `named', `missing', `extra', `outdated', or `has-error'. +PROPERTY could be `named', `missing', `extra', `outdated', +`has-error', or `live'. Named nodes correspond to named rules in the language definition, whereas "anonymous" nodes correspond to string literals in the @@ -1924,7 +1934,10 @@ A node is "outdated" if the parser has reparsed at least once after the node was created. A node "has error" if itself is a syntax error or contains any syntax -errors. */) +errors. + +A node is "live" if its parser is not deleted and its buffer is +live. */) (Lisp_Object node, Lisp_Object property) { if (NILP (node)) return Qnil; @@ -1947,9 +1960,11 @@ errors. */) result = ts_node_is_extra (treesit_node); else if (EQ (property, Qhas_error)) result = ts_node_has_error (treesit_node); + else if (EQ (property, Qlive)) + result = treesit_parser_live_p (XTS_NODE (node)->parser); else signal_error ("Expecting `named', `missing', `extra', " - "`outdated', or `has-error', but got", + "`outdated', `has-error', or `live', but got", property); return result ? Qt : Qnil; } @@ -3448,6 +3463,7 @@ syms_of_treesit (void) DEFSYM (Qextra, "extra"); DEFSYM (Qoutdated, "outdated"); DEFSYM (Qhas_error, "has-error"); + DEFSYM (Qlive, "live"); DEFSYM (QCanchor, ":anchor"); DEFSYM (QCequal, ":equal"); |