print_c_string ("-outdated>", printcharfun);
return;
}
+ if (!treesit_node_buffer_live_p (obj))
+ {
+ print_c_string ("-in-killed-buffer>", printcharfun);
+ break;
+ }
printchar (' ', printcharfun);
/* Now the node must be up-to-date, and calling functions like
Ftreesit_node_start will not signal. */
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
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.
"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");
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);