summaryrefslogtreecommitdiff
path: root/src/treesit.c
AgeCommit message (Collapse)Author
2026-05-23Fold calls to fix_position into treesit_check_position (bug#80830)Yuan Fu
* src/treesit.c (treesit_check_position): Return the validated value. (Ftreesit_node_first_child_for_pos): (Ftreesit_node_descendant_for_range): (Ftreesit_query_capture): (Ftreesit__linecol_at): Fold calls to fix_position into treesit_check_position in treesit.c.
2026-05-23Be more careful about size multiplicationPaul Eggert
* src/alloc.c (xcalloc): New function. * src/dispnew.c (save_current_matrix): * src/fns.c (Finternal__hash_table_histogram): * src/nsfns.m (Fns_display_monitor_attributes_list): * src/pgtkfns.c (Fpgtk_display_monitor_attributes_list): * src/pgtkselect.c (pgtk_own_selection): * src/profiler.c (make_log): * src/sfnt.c (sfnt_poly_edges_exact): * src/xfns.c (x_get_monitor_attributes_xinerama) (x_get_monitor_attributes_xrandr, Fx_display_monitor_attributes_list): Use it instead of multiplying by hand, conceivably with overflow. * src/profiler.c (make_log): Check for overflow in internal size calculations. Use xnmalloc instead of multiply + xmalloc. * src/sfnt.c (xzalloc) [TEST]: Remove, replacing with ... (xicalloc) [TEST]: ... this new function. All callers changed. (eassert) [TEST]: New macro. * src/treesit.c (treesit_calloc_wrapper): Remove, replacing its use with xcalloc.
2026-04-30; * src/treesit.c (treesit_pred_with_guard): Fix style conventions.Eli Zaretskii
2026-04-29In tree-sitter, signal if predicate function causes reparseYuan Fu
A reparse will make the TSTreeCursor or TSNode to possibly point to freed memory (because the TSTree they point to is freed.) * src/treesit.c (treesit_pred_with_guard): New function. (treesit_predicate_pred): (treesit_eval_predicates): (Ftreesit_query_capture): (treesit_traverse_match_predicate): (treesit_build_sparse_tree): Add guard that signals if buffer is changed when calling predicate function. (Qtreesit_buffer_changed): New symbol.
2026-04-25; Move treesit-languages-require-line-column-tracking to treesit.c.Yuan Fu
* lisp/treesit.el: Remove it. * src/treesit.c (syms_of_treesit): Add it.
2026-04-19* src/treesit.c (Ftreesit__linecol_at): Add treesit_check_position.Yuan Fu
2026-04-19Fix tree-sitter variable nameYuan Fu
* lisp/treesit.el: (treesit-languages-require-line-column-tracking): This is what treesit.c uses. * src/treesit.c: Fix comment typo.
2026-04-17; * src/treesit.c (compute_new_linecol_by_change): Fix comment.Yuan Fu
2026-04-16Make sure range (1, 1) doesn't capture anything (bug#80798)Yuan Fu
* src/treesit.c (Ftreesit_query_capture): Return Qnil if querying (1, 1).
2026-04-16Accept marker as position in treesit.c functions (bug#80830)Yuan Fu
* src/treesit.c (treesit_check_positive_integer): Remove. (treesit_check_position): (Ftreesit_node_first_child_for_pos): (Ftreesit_node_descendant_for_range): (Ftreesit_query_capture): (Ftreesit__linecol_at): Use fix_position. * test/src/treesit-tests.el: (treesit-query-marker-position): Test.
2026-04-04Fix treesit-query-capture's NODE-ONLY paramYuan Fu
Before the fix, if user uses the NODE-ONLY option, we don't keep the capture names in the results, then predicates won't work because they can't reference capture names. * src/treesit.c (query_capture_remove_capture_name): New function. (Ftreesit_query_capture): Use the new function to remove capture names AFTER running the predicate. * test/src/treesit-tests.el: (treesit-query-node-only-and-grouped): New test.
2026-03-12Replace remaining uses of Qwrong_type_argumentBasil L. Contovounesios
For discussion, see: https://lists.gnu.org/r/emacs-devel/2026-03/msg00306.html * src/comp.c (helper_GET_SYMBOL_WITH_POSITION): Use symbol-with-pos-p, not wrong-type-argument, in the wrong-type-argument error predicate slot. * src/data.c (Fbare_symbol): * src/print.c (print_bind_overrides): * src/treesit.c (Ftreesit_parser_create, treesit_resolve_node): Prefer wrong_type_argument over xsignal2.
2026-02-18; Fix last change in treesit.cEli Zaretskii
* src/treesit.c (ts_tree_cursor_copy) [WINDOWSNT]: Define and load from the DLL if 'ts_tree_cursor_goto_previous_sibling' is not available. This fixes the MS-Windows build broken by the last change here. (Bug#80108)
2026-02-17Change back tree-sitter version requirement (bug#80108)Yuan Fu
Now we use treesit_traverse_sibling_helper when it exists, and use the old code otherwise. So we still support older tree-sitter versions. * configure.ac (LIBSYSTEMD_CFLAGS): Add back old config checking for the malloc function. Add another check for ts_tree_cursor_goto_previous_sibling. * src/treesit.c: (treesit_traverse_sibling_helper): Add back the old code that doesn't require ts_tree_cursor_goto_previous_sibling.
2026-01-28; Fix MS-Windows build broken by recent treesit.c changesEli Zaretskii
* src/treesit.c (ts_tree_cursor_copy) [WINDOWSNT]: Remove, as it is no longer used. (ts_tree_cursor_goto_previous_sibling) [WINDOWSNT]: Add. (Bug#80108)
2026-01-28Fix tree-sitter traversal slowness (bug#80108)Yuan Fu
* configure.ac (LIBSYSTEMD_CFLAGS): Increase minimal required tree-sitter version to 0.20.10. * src/treesit.c (treesit_traverse_sibling_helper): When traversing forward, use the new function ts_tree_cursor_goto_previous_sibling.
2026-01-02; Fix documentation of recent treesit changesEli Zaretskii
* etc/NEWS: * src/treesit.c (Ftreesit_query_eagerly_compiled_p): * doc/lispref/parsing.texi (Pattern Matching): Fix documentation of the recent treesit-related changes. (Bug#80108)
2026-01-01Compile queries in treesit-f-l-recompute-features (bug#80108)Yuan Fu
The direct cause of the problem in the bug report is that when user runs treesit-font-lock-recompute-features to add the emacs-devel feature in c-ts-mode's mode hook, the added query for emacs-devel aren't compiled. This change consists of two parts: 1. The immediate fix: validate and compile queries in treesit-font-lock-recompute-features. 2. To make it more fool-proof, change treesit-font-lock-rules back to compile the queries and make treesit--compile-query-with-cache support compiled queries. This way, as long as the query goes through treesit-font-lock-rules, it'll be compiled eventually and not cause slow-down. I had to add some c-level functions, but they're kind of overdue anyway, so I don't have any problem adding them to the API. * lisp/treesit.el (treesit--compile-query-with-cache): Support compiled queries. (treesit-font-lock-rules): Compile the queries (but not eagerly). (treesit-font-lock-recompute-features): Validate and compile queries. (treesit-major-mode-setup): Remove call to treesit-validate-and-compile-font-lock-rules since it's now called in treesit-font-lock-recompute-features. * src/treesit.c (Ftreesit_query_eagerly_compiled_p): (Ftreesit_query_source): New functions. * doc/lispref/parsing.texi (Pattern Matching): Add manual entries for the new functions.
2026-01-01; Add 2026 to copyright years.Sean Whitton
2025-12-26December 2025 spelling fixesPaul Eggert
Some of the fixes are to continue to use American rather than British spelling. * doc/misc/modus-themes.org (my-modus-themes-engraved-faces): Fix misspelled ‘:foreground’s. * etc/themes/modus-themes.el (modus-themes-faces): Fix misspelled ‘modus-themes-bold’. * lisp/emacs-lisp/rx.el (rx--normalize-char-pattern): Rename from rx--normalise-char-pattern. (rx--optimize-or-args): Rename from rx--optimise-or-args. * lisp/frame.el (frame--special-parameters): Fix misspelled "right-divider-width". * lisp/net/tramp.el (tramp-fingerprint-prompt-regexp): Use American spelling “centered”, to match current libfprintf. * lisp/org/org-fold-core.el (org-fold-core--optimize-for-huge-buffers): Rename from org-fold-core--optimise-for-huge-buffers. (org-fold-core-update-optimization): Rename from org-fold-core-update-optimisation, leaving an alias behind. (org-fold-core-remove-optimization): Rename from org-fold-core-remove-optimisation, leaving an alias behind. * lisp/org/org.el (org-advertized-archive-subtree): This alias is now obsolete. * lisp/play/zone.el (zone-ignored-buffers): Fix misspelling of ‘zone--buffer-encrypted-p’. * lisp/progmodes/csharp-mode.el (csharp-ts-mode-faces): Fix misspelling of ‘csharp’ group. * lisp/vc/vc.el (vc-clonable-backends-custom-type): Rename from vc-cloneable-backends-custom-type, leaving an alias behind. * test/lisp/emacs-lisp/bytecomp-tests.el: (bytecomp-tests--warn-arity-non-compiled-callee): Rename from bytecomp-tests--warn-arity-noncompiled-callee. (bytecomp-test-defface-spec): Reword a deliberate misspelling of “default” that is so common I don’t want it to pollute the spelling dictionary. * test/lisp/emacs-lisp/package-vc-tests.el: (package-vc-tests-preserve-artifacts): Rename from package-vc-tests-preserve-artifacts. * test/lisp/eshell/em-prompt-tests.el: (em-prompt-test/forward-backward-paragraph-1): Reword a deliberate misspelling of “goodbye” that is so common I don’t want it to pollute the spelling dictionary.
2025-12-08Fix some C symbol extern visibilityPaul Eggert
Make some C symbols static if they don’t need to be extern. Also, remove a couple of functions that were discovered to be unused as a result of this process, and mark two extern functions intended to be usable from GDB. * src/buffer.c (previous_overlay_change): * src/composite.c (composition_lisp_table): * src/fileio.c (file_name_directory): * src/frame.c (check_tty): * src/insdel.c (adjust_markers_for_insert): * src/keyboard.c (unread_switch_frame, read_char) (requeued_events_pending_p): * src/sysdep.c (renameat_noreplace) [!HAVE_ANDROID]: * src/textconv.c (get_conversion_field) [!HAVE_ANDROID]: * src/treesit.c (TREESIT_BOB_LINECOL, TREESIT_TS_POINT_1_0) (treesit_buf_tracks_linecol_p, make_treesit_parser) (make_treesit_node): * src/xdisp.c (x_y_to_hpos_vpos): * src/xfaces.c (load_color) [!MSDOS]: * src/xfns.c (x_real_pos_and_offsets): * src/xterm.c (x_dnd_do_unsupported_drop): Now static. Move up if necessary. * src/coding.c (utf8_string_p): * src/keyboard.c (detect_input_pending_ignore_squeezables): Remove; unused. * src/frame.c (gui_set_alpha): * src/textconv.c (start_batch_edit, end_batch_edit, commit_text) (finish_composing_text, set_composing_text) (set_composing_region, textconv_set_point_and_mark) (delete_surrounding_text, request_point_update) (textconv_barrier, replace_text, get_extracted_text) (get_surrounding_text): * src/xdisp.c (gui_union_rectangles): * src/xterm.c (xi_frame_selected_for): Define only if needed. * src/treesit.c (treesit_debug_print_parser_list) (treesit_debug_print_linecol): Declare EXTERNALLY_VISIBLE. * src/xdisp.c (x_y_to_column_row): New function, defined only if needed. All external callers to x_y_to_hpos_vpos changed.
2025-11-30Use treesit-extra-load-path for more values of treesit-auto-install-grammarJuri Linkov
* lisp/treesit.el (treesit-auto-install-grammar): Use the first writable directory from 'treesit-extra-load-path' for values 'always', 'ask', 'ask-dir' (bug#79862). * src/treesit.c (syms_of_treesit): Extend docstring.
2025-11-28* lisp/cus-start.el: Make 'treesit-extra-load-path' customizable.Juri Linkov
* lisp/treesit.el (treesit-auto-install-grammar): Add the value 'ask-dir'. (treesit-ensure-installed): When 'treesit-auto-install-grammar' is 'ask' or 'ask-dir', ask for the directory to install the grammar library using the first writable directory of 'treesit-extra-load-path' as default. Also add the provided directory to 'treesit-extra-load-path' afterwards. * src/treesit.c (treesit-extra-load-path): In the docstring mention the fact that the first directory is special (bug#79862).
2025-11-02Change tree-sitter query predicate names (bug#79687)Yuan Fu
Latest tree-sitter library throws a syntax error if the predicate names in a query don't end with question mark. So we made the following change: :equal changed to :eq? :match changed to :match? :pred changed to :pred? Old names are transparently converted to new names when expanding patterns. :match predicate can now take the regexp and the node in any order: it'll figure out which is which automatically. This way it works with current Emacs convention (regexp first), as well as tree-sitter's match convention (regexp second). * doc/lispref/parsing.texi (Pattern Matching): Update manuel to use new predicate names. * src/treesit.c: (Ftreesit_pattern_expand): (Ftreesit_query_expand): (treesit_predicate_match): (treesit_eval_predicates): (syms_of_treesit): Use new predicate names. * test/src/treesit-tests.el (treesit-query-api): Update test.
2025-10-17Support Tree-sitter version 0.26 and laterEli Zaretskii
* src/treesit.c (init_treesit_functions) [TREE_SITTER_LANGUAGE_VERSION >= 15]: Define prototype for, and load 'ts_language_abi_version' instead of the deprecated (and removed in tree-sitter 0.26) 'ts_language_version'. (ts_language_abi_version) [TREE_SITTER_LANGUAGE_VERSION >= 15]: Define on WINDOWSNT, instead of 'ts_language_version'. (treesit_language_abi_version): New compatibility function. (treesit_load_language, Ftreesit_language_abi_version): Use 'treesit_language_abi_version' instead of 'ts_language_version'. (Bug#79627)
2025-08-14New user option 'treesit-enabled-modes' (bug#79180)Juri Linkov
* lisp/treesit.el (treesit-enabled-modes): New user option. * src/treesit.c (treesit-major-mode-remap-alist): New variable. * lisp/progmodes/c-ts-mode.el: * lisp/progmodes/csharp-mode.el: * lisp/progmodes/java-ts-mode.el: * lisp/progmodes/js.el: * lisp/progmodes/json-ts-mode.el: * lisp/progmodes/ruby-ts-mode.el: * lisp/progmodes/sh-script.el: * lisp/textmodes/css-mode.el: * lisp/textmodes/mhtml-ts-mode.el: * lisp/textmodes/toml-ts-mode.el: Add ts-mode mapping to 'treesit-major-mode-remap-alist' for ts-modes that already have the corresponding non-ts mode association in 'auto-mode-alist'. * lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode-maybe): * lisp/progmodes/dockerfile-ts-mode.el (dockerfile-ts-mode-maybe): * lisp/progmodes/elixir-ts-mode.el (elixir-ts-mode-maybe): * lisp/progmodes/go-ts-mode.el (go-ts-mode-maybe) (go-mod-ts-mode-maybe, go-work-ts-mode-maybe): * lisp/progmodes/heex-ts-mode.el (heex-ts-mode-maybe): * lisp/progmodes/lua-ts-mode.el (lua-ts-mode-maybe): * lisp/progmodes/php-ts-mode.el (php-ts-mode-maybe): * lisp/progmodes/rust-ts-mode.el (rust-ts-mode-maybe): * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode-maybe) (tsx-ts-mode-maybe): * lisp/textmodes/markdown-ts-mode.el (markdown-ts-mode-maybe): * lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode-maybe): Add a wrapper function to 'auto-mode-alist' for ts-modes that have no corresponding non-ts mode. Also add a mapping to 'treesit-major-mode-remap-alist' for the case when a non-ts mode is installed from an external source to be able to customize it with 'treesit-enabled-modes'.
2025-07-08Add a synchronous way to get parser change ranges (bug#78402)Yuan Fu
This commit only adds the new function, the fix for the bug is in the next commit. * doc/lispref/parsing.texi (Using Parser): Add docs. * lisp/treesit.el (treesit): Add shortdoc. * src/treesit.c (treesit_get_affected_ranges): New function extracted from treesit_call_after_change_functions. (treesit_call_after_change_functions): Extract out. (treesit_ensure_parsed): Return affected regions. (Ftreesit_parser_changed_regions): New function that returns the affected regions.
2025-07-05Merge from origin/emacs-30Eli Zaretskii
3f7787c9794 ; * lisp/replace.el (query-replace-help): Fix help text (... b10596a6303 ; * lisp/emacs-lisp/warnings.el (warning-display-at-botto... 060f964906b Handle ts_node_type return NULL (bug#78938) 5bdacbe460a Improve documentation of 'warning-display-at-bottom' 30dae2ad239 Handle the case when ts_node_type returns NULL (bug#78938) 985ad1da76d ; * lisp/emacs-lisp/bytecomp.el (compilation-safety): Doc... de18407f513 ; * doc/lispref/functions.texi (Mapping Functions): Fix w...
2025-07-04Handle ts_node_type return NULL (bug#78938)Yuan Fu
* src/treesit.c (treesit_traverse_match_predicate): Handle the case when ts_node_type returns NULL. (Ftreesit_node_type): Add some comment.
2025-07-03Handle the case when ts_node_type returns NULL (bug#78938)Yuan Fu
* src/treesit.c (Ftreesit_node_type): Handle NULL.
2025-06-14Merge from origin/emacs-30Eli Zaretskii
df3fb94f091 Insert missing step to make use of directory tracking OSC... 1bed2949583 * lisp/keymap.el (keymap-set): Refer to 'key-description'... 941158fc133 Support new tree-sitter grammar filename format (bug#78754) 888f846d377 Fix crash when evaluating "(signal nil 5)" (bug#78738) 51b9e92ab8e Merge branch 'emacs-30' of git.savannah.gnu.org:/srv/git/... c0a913ea4f3 ; * doc/lispref/modes.texi (Font Lock Basics): Remove old... 37de076017a Adapt emba integration (don't merge)
2025-06-14; Fix warnings in MinGW buildsEli Zaretskii
* src/w32fns.c (msh_mousewheel): Declare. * src/treesit.c (treesit_debug_print_linecol): Fix format specifiers. * lib-src/pop.c (pfn_getaddrinfo, pfn_freeaddrinfo): Now static.
2025-06-10Support new tree-sitter grammar filename format (bug#78754)Yuan Fu
Previously Emacs only looks for filenames like libtree-sitter-json.so.0.0. Now Emacs also look for filenames like libtree-sitter-json.so.15.0. * src/treesit.c: (treesit_load_language_push_for_each_suffix): Add versioned candidate to candidate list too.
2025-06-05Improve documentation of treesit "thing"Eli Zaretskii
* src/treesit.c (syms_of_treesit): * lisp/treesit.el (treesit-cycle-sexp-type): (treesit-thing-at, treesit-thing-at-point): Doc fixes. * doc/lispref/parsing.texi (User-defined Things): Improve documentation of treesit "thing" and related functions; add cross-references and indexing.
2025-05-18Improve reporting of language-grammar library ABI version mismatchEli Zaretskii
* lisp/treesit.el (treesit-ready-p): More accurate wording of message when grammar library fails to load. * src/treesit.c (treesit_load_language): Improve message when reporting library ABI version mismatch. Suggested by Soham Gumaste <sohamg2@gmail.com>.
2025-05-03Add line-column tracking for tree-sitterYuan Fu
Add line-column tracking for tree-sitter parsers. Copied from comments in treesit.c: Technically we had to send tree-sitter the line and column position of each edit. But in practice we just send it dummy values, because tree-sitter doesn't use it for parsing and mostly just carries the line and column positions around and return it when e.g. reporting node positions[1]. This has been working fine until we encountered grammars that actually utilizes the line and column information for parsing (Haskell)[2]. [1] https://github.com/tree-sitter/tree-sitter/issues/445 [2] https://github.com/tree-sitter/tree-sitter/issues/4001 So now we have to keep track of line and column positions and pass valid values to tree-sitter. (It adds quite some complexity, but only linearly; one can ignore all the linecol stuff when trying to understand treesit code and then come back to it later.) Eli convinced me to disable tracking by default, and only enable it for languages that needs it. So the buffer starts out not tracking linecol. And when a parser is created, if the language is in treesit-languages-require-line-column-tracking, we enable tracking in the buffer, and enable tracking for the parser. To simplify things, once a buffer starts tracking linecol, it never disables tracking, even if parsers that need tracking are all deleted; and for parsers, tracking is determined at creation time, if it starts out tracking/non-tracking, it stays that way, regardless of later changes to treesit-languages-require-line-column-tracking. To make calculating line/column positons fast, we store linecol caches for begv, point, and zv in the buffer (buf->ts_linecol_cache_xxx); and in the parser object, we store linecol cache for visible beg/end of that parser. In buffer editing functions, we need the linecol for start/old_end/new_end, those can be calculated by scanning newlines (treesit_linecol_of_pos) from the buffer point cache, which should be always near the point. And we usually set the calculated linecol of new_end back to the buffer point cache. We also need to calculate linecol for the visible_beg/end for each parser, and linecol for the buffer's begv/zv, these positions are usually far from point, so we have caches for all of them (in either the parser object or the buffer). These positions are far from point, so it's inefficient to scan newlines from point to there to get up-to-date linecol for them; but in the same time, because they're far and outside the changed region, we can calculate their change in line and column number by simply counting how much newlines are added/removed in the changed region (compute_new_linecol_by_change). * doc/lispref/parsing.texi (Using Parser): Mention line-column tracking in manual. * etc/NEWS: Add news. * lisp/treesit.el: (treesit-languages-need-line-column-tracking): New variable. * src/buffer.c: Include treesit.h (for TREESIT_EMPTY_LINECOL). (Fget_buffer_create): (Fmake_indirect_buffer): Initialize new buffer fields. (Fbuffer_swap_text): Add new buffer fields. * src/buffer.h (ts_linecol): New struct. (buffer): New buffer fields. (BUF_TS_LINECOL_BEGV): (BUF_TS_LINECOL_POINT): (BUF_TS_LINECOL_ZV): (SET_BUF_TS_LINECOL_BEGV): (SET_BUF_TS_LINECOL_POINT): (SET_BUF_TS_LINECOL_ZV): New inline functions. * src/casefiddle.c (casify_region): Record linecol info. * src/editfns.c (Fsubst_char_in_region): (Ftranslate_region_internal): (Ftranspose_regions): Record linecol info. * src/insdel.c (insert_1_both): (insert_from_string_1): (insert_from_gap_1): (insert_from_buffer): (replace_range): (del_range_2): Record linecol info. * src/treesit.c (TREESIT_BOB_LINECOL): (TREESIT_EMPTY_LINECOL): (TREESIT_TS_POINT_1_0): New constants. (treesit_debug_print_linecol): (treesit_buf_tracks_linecol_p): (restore_restriction_and_selective_display): (treesit_count_lines): (treesit_debug_validate_linecol): (treesit_linecol_of_pos): (treesit_make_ts_point): (Ftreesit_tracking_line_column_p): (Ftreesit_parser_tracking_line_column_p): New functions. (treesit_tree_edit_1): Accept real TSPoint and pass to tree-sitter. (compute_new_linecol_by_change): New function. (treesit_record_change_1): Rename from treesit_record_change, handle linecol if tracking is enabled. (treesit_linecol_maybe): New function. (treesit_record_change): New wrapper around treesit_record_change_1 that handles some boilerplate and sets buffer state. (treesit_sync_visible_region): Handle linecol if tracking is enabled. (make_treesit_parser): Setup parser's linecol cache if tracking is enabled. (Ftreesit_parser_create): Enable tracking if the parser's language requires it. (Ftreesit__linecol_at): (Ftreesit__linecol_cache_set): (Ftreesit__linecol_cache): New functions for debugging and testing. (syms_of_treesit): New variable Vtreesit_languages_require_line_column_tracking. * src/treesit.h (Lisp_TS_Parser): New fields. (TREESIT_BOB_LINECOL): (TREESIT_EMPTY_LINECOL): New constants. * test/src/treesit-tests.el (treesit-linecol-basic): (treesit-linecol-search-back-across-newline): (treesit-linecol-col-same-line): (treesit-linecol-enable-disable): New tests. * src/lisp.h: Declare display_count_lines. * src/xdisp.c (display_count_lines): Remove static keyword.
2025-03-13Fix treesit-parser-create behavior regarding indirect buffersYuan Fu
The previous fix fixed the problem that treesit-parser-create always use the current buffer, but that introduce another subtle problem: if an indirect buffer creates a parser, the parser saves the base buffer rather than the indirect buffer. In Emacs 29, if you create a parser in an indirect buffer, the parser saves the indirect buffer. This change of behavior breaks some existing use-cases for people using indirect buffer with tree-sitter. In Emacs 31, indirect buffers and base buffer get their own parser list, so this problem doesn't exist anymore. The fix is only for Emacs 30. * src/treesit.c (Ftreesit_parser_create): Use the buffer that's given to treesit-parser-create, even if it's an indirect buffer.
2025-03-11Remove parent-node field from tree-sitter parsersYuan Fu
* src/treesit.c (make_treesit_parser): Remove field. (Ftreesit_parser_parent_node): (Ftreesit_parser_set_parent_node): Remove * src/treesit.h (Lisp_TS_Parser): Remove field.
2025-03-06Avoid defining unneeded variables on Cygw32Kazuhiro Ito
lisp/term/w32-win.el contained definitions of variables which were not used on Cygw32. It is now to split into two files, common part and Windows native build specific part. The latter is a new file, lisp/term/w32-nt.el. * src/image.c (Qlibpng_version, Qlibgif_version) (Qlibjpeg_version): Don't define on Cygw32 build. * src/treesit.c (Qtree_sitter__library_abi): Ditto. * lisp/term/w32-win.el (dynamic-library-alist, libpng-version) (libgif-version, libjpeg-version, libgnutls-version) (tree-sitter--library-abi, gui-backend-set-selection) (gui-backend-get-selection, gui-backend-selection-owner-p) (gui-selection-exists-p): Moved to lisp/term/w32-nt.el. * lisp/term/w32-nt.el: New file, separated Windows native build specific part from lisp/term/w32-win.el. * lisp/loadup.el: Load term/w32-nt.el on Windows native build. (Bug#75926)
2025-03-01Merge from origin/emacs-30Eli Zaretskii
2dbf7d0b1b2 Use character position for ranges in treesit_sync_visible...
2025-02-28; Fix documentation of recent treesit changesEli Zaretskii
* src/treesit.c (Ftreesit_query_capture) (Ftreesit_parser_embed_level, Ftreesit_parser_set_embed_level) (Ftreesit_parser_set_parent_node): * lisp/treesit.el (treesit-query-range) (treesit-query-range-by-language, treesit-range-settings) (treesit-range-rules, treesit--parser-at-level) (treesit--update-ranges-non-local, treesit--update-ranges-local) (treesit--update-range-1): Fix wording and typos in doc strings. * doc/lispref/parsing.texi (Pattern Matching): Fix wording.
2025-02-27Enable treesit-query-capture to return grouped capturesYuan Fu
This is needed for creating embedded parsers for embedded code blocks of which language cannot be known ahead of time. E.g., markdown and org mode's code block. * src/treesit.c (Ftreesit_query_capture): Add parameter GROUPED.
2025-02-27Add tree-sitter-parser-embed-level and parent-nodeYuan Fu
Add parser properties embed-level and parent-node. They'll be help us implement arbitrarily nested embeded parser, and navigation across embedded and host parsers, respectively. * src/treesit.c: (Ftreesit_parser_embed_level): (Ftreesit_parser_set_embed_level): (Ftreesit_parser_parent_node): (Ftreesit_parser_set_parent_node): New functions.
2025-02-23Use character position for ranges in treesit_sync_visible_regionYuan Fu
* src/treesit.c (treesit_sync_visible_region): Use character position instead of byte position when comparing to ranges, because the ranges are in character position.
2025-02-01Merge branch 'scratch/no-purespace' into 'master'Stefan Kangas
2025-01-29Fix tree-sitter language remappingYuan Fu
* src/treesit.c (resolve_language_symbol): Move forward. (treesit_ensure_query_compiled): Resolve language remapping here. (Ftreesit_parser_list): Don't resolve language remaping here, because there's no need: parsers now carries the remapped language. (Ftreesit_query_compile): Don't resolve language remapping here, because we resolve language remapping when actually compiling the query. Also we want the query to carry the unmapped language.
2025-01-29; Fix Cygw32 build (bug#75926)Eli Zaretskii
(cherry picked from commit cb62a47896bb21420a709c655034e8acfcb08082)
2025-01-29; Fix Cygw32 buildEli Zaretskii
2025-01-20; Fix last changeEli Zaretskii
* src/treesit.c (Ftreesit_parser_create): Fix comment wording. * doc/lispref/parsing.texi (Using Parser): Fix wording and markup.
2025-01-19Make treesit-language-remap-alist completely transparent (bug#72388)Yuan Fu
* doc/lispref/parsing.texi (Using Parser): Update manual. * src/treesit.c (Ftreesit_parser_create): Use the LANGUAGE argument given as the language for the parser, not the actual language.