Function: treesit-parser-set-included-ranges
treesit-parser-set-included-ranges is a function defined in treesit.c.
Signature
(treesit-parser-set-included-ranges PARSER RANGES)
Documentation
Limit PARSER to RANGES.
RANGES is a list of (BEG . END), each (BEG . END) defines a region in
which the parser should operate. Regions must not overlap, and the
regions should come in order in the list. Signal
treesit-set-range-error if the argument is invalid, or something
else went wrong. If RANGES is nil, the PARSER is to parse the whole
buffer.
DO NOT modify RANGES after passing it to this function, as RANGES is saved to PARSER internally.
Other relevant functions are documented in the treesit group.
Shortdoc
;; treesit
(treesit-parser-set-included-ranges parser '((1 . 4) (5 . 8)))
Source Code
// Defined in /usr/src/emacs/src/treesit.c
{
treesit_check_parser (parser);
if (!NILP (ranges))
CHECK_CONS (ranges);
if (!NILP (Fequal (XTS_PARSER (parser)->last_set_ranges, ranges)))
return Qnil;
treesit_check_range_argument (ranges);
treesit_initialize ();
/* Before we parse, catch up with narrowing/widening. */
treesit_check_buffer_size (XBUFFER (XTS_PARSER (parser)->buffer));
treesit_sync_visible_region (parser);
XTS_PARSER (parser)->last_set_ranges = ranges;
bool success;
if (NILP (ranges))
{
/* If RANGES is nil, make parser to parse the whole document.
To do that we give tree-sitter a 0 length. */
success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser,
NULL , 0);
}
else
{
uint32_t len = 0;
TSRange *treesit_ranges = treesit_make_ts_ranges (ranges, parser, &len);
success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser,
treesit_ranges, len);
xfree (treesit_ranges);
}
if (!success)
xsignal2 (Qtreesit_range_invalid,
build_string ("Something went wrong when setting ranges"),
ranges);
XTS_PARSER (parser)->need_reparse = true;
return Qnil;
}