diff options
Diffstat (limited to 'src/treesit.c')
-rw-r--r-- | src/treesit.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/treesit.c b/src/treesit.c index 21c61a35e70..45efa429f9a 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -1786,6 +1786,13 @@ treesit_check_node (Lisp_Object obj) CHECK_TS_NODE (obj); if (!treesit_node_uptodate_p (obj)) xsignal1 (Qtreesit_node_outdated, obj); + + /* Technically a lot of node functions can work without the + associated buffer being alive, but I doubt there're any real + use-cases for that; OTOH putting the buffer-liveness check here is + simple, clean, and safe. */ + if (!treesit_node_buffer_live_p (obj)) + xsignal1 (Qtreesit_node_buffer_killed, obj); } /* Checks that OBJ is a positive integer and it is within the visible @@ -1806,6 +1813,14 @@ treesit_node_uptodate_p (Lisp_Object obj) return XTS_NODE (obj)->timestamp == XTS_PARSER (lisp_parser)->timestamp; } +bool +treesit_node_buffer_live_p (Lisp_Object obj) +{ + struct buffer *buffer + = XBUFFER (XTS_PARSER (XTS_NODE (obj)->parser)->buffer); + return BUFFER_LIVE_P (buffer); +} + DEFUN ("treesit-node-type", Ftreesit_node_type, Streesit_node_type, 1, 1, 0, doc: /* Return the NODE's type as a string. @@ -3549,6 +3564,8 @@ syms_of_treesit (void) "treesit-load-language-error"); DEFSYM (Qtreesit_node_outdated, "treesit-node-outdated"); + DEFSYM (Qtreesit_node_buffer_killed, + "treesit-node-buffer-killed"); DEFSYM (Quser_emacs_directory, "user-emacs-directory"); DEFSYM (Qtreesit_parser_deleted, "treesit-parser-deleted"); @@ -3577,6 +3594,9 @@ syms_of_treesit (void) define_error (Qtreesit_node_outdated, "This node is outdated, please retrieve a new one", Qtreesit_error); + define_error (Qtreesit_node_buffer_killed, + "The buffer associated with this node is killed", + Qtreesit_error); define_error (Qtreesit_parser_deleted, "This parser is deleted and cannot be used", Qtreesit_error); |