1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00
emacs/doc/lispref
Yuan Fu 1897da0b59
Add line-column tracking for tree-sitter
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-05-03 22:14:03 -07:00
..
abbrevs.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
anti.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
back.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
backups.texi Add inhibit-auto-revert macro 2025-02-04 14:09:52 +01:00
book-spine.texi
buffers.texi Move documentation of this-command buffer display condition entry 2025-05-02 12:49:35 +08:00
ChangeLog.1 ; Delete troff markers from ChangeLog files 2025-02-20 02:46:43 +01:00
commands.texi Merge from origin/emacs-30 2025-03-24 10:41:45 +08:00
compile.texi ; Grammar fixes for "native-compiled" 2025-02-28 20:20:55 +01:00
control.texi Add static-when, static-unless like static-if 2025-03-07 22:22:30 -08:00
customize.texi ; Fix cross-references in Texinfo manuals 2025-01-19 08:23:23 +02:00
debugging.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
display.texi Disable clearing echo-area when 'inhibit-message' is non-nil 2025-04-13 10:44:55 +03:00
doclicense.texi
edebug.texi (lexical-binding): Allow changing the default value (bug#74145) 2025-02-18 15:37:50 -05:00
elisp.texi Further amendments of child frame handling and documentation 2025-03-26 09:04:49 +01:00
elisp_type_hierarchy.jpg Run admin/syncdoc-type-hierarchy.el 2024-04-23 15:39:28 +02:00
elisp_type_hierarchy.txt Run admin/syncdoc-type-hierarchy.el 2024-04-23 15:39:28 +02:00
errors.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
eval.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
files.texi Improve documentation of 'file-name-concat' 2025-02-06 10:42:04 +02:00
frames.texi ; Improve the documentation of a recent commit 2025-04-19 09:11:57 +03:00
functions.texi ; Fix a merge snafu. 2025-03-29 08:54:30 -04:00
gpl.texi
hash.texi New function 'hash-table-contains-p' 2025-03-29 14:59:36 +01:00
help.texi Lisp Reference Manual: Index standard symbol properties. 2025-01-12 20:16:00 -08:00
hooks.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
index.texi
internals.texi Don't overwrite non-local exit symbol and data (Bug#65796). 2025-02-28 01:45:35 +01:00
intro.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
keymaps.texi Merge from savannah/emacs-30 2025-03-16 20:14:48 +08:00
lay-flat.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
lists.texi Avoid double spaces around abbrevations in Texinfo 2025-01-24 23:10:23 +01:00
loading.texi ; Grammar fixes for "native-compiled" 2025-02-28 20:20:55 +01:00
macros.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
Makefile.in Update copyright year to 2025 2025-01-02 18:39:42 +01:00
maps.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
markers.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
minibuf.texi Add optional PREDICATE argument to read-directory-name 2025-02-13 08:32:28 +01:00
modes.texi Merge from origin/emacs-30 2025-04-30 07:14:23 -04:00
nonascii.texi Fix the values and documentation of 'printable-chars' table 2025-02-28 16:22:30 +02:00
numbers.texi Merge from origin/emacs-30 2025-03-01 09:59:08 -05:00
objects.texi ; Improve type specifier documentation 2025-03-25 23:44:01 +01:00
os.texi Merge from origin/emacs-30 2025-04-30 07:14:23 -04:00
package.texi ; Don't document package-x.el 2025-03-02 05:09:37 +01:00
parsing.texi Add line-column tracking for tree-sitter 2025-05-03 22:14:03 -07:00
peg.texi peg.texi: Fix bug#76555 even a bit more 2025-03-27 08:59:33 -04:00
positions.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
processes.texi Remove ctags program 2025-03-22 11:57:29 -07:00
README Update copyright year to 2025 2025-01-02 18:39:42 +01:00
records.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
searching.texi Fix the values and documentation of 'printable-chars' table 2025-02-28 16:22:30 +02:00
sequences.texi Lisp Reference Manual: Index standard symbol properties. 2025-01-12 20:16:00 -08:00
spellfile Make 'purecopy' an obsolete function alias for 'identity' 2024-12-12 22:48:21 +01:00
streams.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
strings.texi Fix clear-string crash with text properties 2025-01-15 23:16:19 +01:00
symbols.texi Merge from origin/emacs-30 2025-02-01 07:40:19 -05:00
syntax.texi Avoid double spaces around abbrevations in Texinfo 2025-01-24 23:10:23 +01:00
text.texi Merge from savannah/emacs-30 2025-04-18 16:30:39 -07:00
threads.texi Update copyright year to 2025 2025-01-02 18:39:42 +01:00
tips.texi Merge from origin/emacs-30 2025-04-12 08:57:38 -04:00
two-volume-cross-refs.txt Update copyright year to 2025 2025-01-02 18:39:42 +01:00
two-volume.make Update copyright year to 2025 2025-01-02 18:39:42 +01:00
variables.texi ; Improve documentation of incf and decf 2025-03-19 21:29:50 +01:00
windows.texi Move documentation of this-command buffer display condition entry 2025-05-02 12:49:35 +08:00

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Copyright (C) 2001-2025 Free Software Foundation, Inc.  -*- outline -*-
See the end of the file for license conditions.


README for the Emacs Lisp Reference Manual.

* This directory contains the texinfo source files for the Emacs Lisp
Reference Manual.

* Report bugs in the Lisp Manual (or in Emacs) using M-x report-emacs-bug.
To ask questions, use the help-gnu-emacs mailing list.

* The Emacs Lisp Reference Manual is quite large.  It totals around
1100 pages in smallbook format; the info files total around 3.0 megabytes.

* You can format this manual for Info, for printing hardcopy using TeX,
or for HTML.

* You can buy nicely printed copies from the Free Software Foundation.
Buying a manual from the Free Software Foundation helps support our GNU
development work.  See <https://shop.fsf.org/>.
(At time of writing, this manual is out of print.)

* The master file for formatting this manual for Tex is called 'elisp.texi'.
It contains @include commands to include all the chapters that make up
the manual.

* This distribution contains a Makefile that you can use with GNU Make.

** To make an Info file, you need to install Texinfo, then run 'make info'.

** Use 'make elisp.pdf' or 'make elisp.html' to create PDF or HTML versions.


This file is part of GNU Emacs.

GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.