1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 12:21:25 -08:00
emacs/etc
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
..
charsets Update copyright year to 2025 2025-01-02 18:39:42 +01:00
e Add auto-margin enable/disable to term 2025-03-02 16:01:13 -05:00
forms Update copyright year to 2025 2025-01-02 18:39:42 +01:00
gnus
images Merge from origin/emacs-30 2025-03-01 10:01:09 -05:00
nxml
org Update copyright year to 2025 2025-01-02 18:39:42 +01:00
refcards ; Fix copyright years of the Spanish translations 2025-03-04 03:08:31 +01:00
schema Update copyright year to 2025 2025-01-02 18:39:42 +01:00
srecode Update copyright year to 2025 2025-01-02 18:39:42 +01:00
themes Update modus-themes to their 4.7.0 version 2025-04-17 10:33:43 +03:00
tutorials Fix copyright years by hand 2025-01-02 18:44:48 +01:00
AUTHORS Update files for Emacs 30.1 2025-02-20 00:46:32 +01:00
CALC-NEWS Update copyright year to 2025 2025-01-02 18:39:42 +01:00
ChangeLog.1 ; Delete troff markers from ChangeLog files 2025-02-20 02:46:43 +01:00
compilation.txt Update copyright year to 2025 2025-01-02 18:39:42 +01:00
COPYING
copyright-assign.txt Add assignment form as etc/copyright-assign.txt 2024-06-23 00:24:31 +02:00
DEBUG Merge from origin/emacs-30 2025-05-03 06:26:31 -04:00
DEVEL.HUMOR ; Fix punctuation in etc/* 2024-07-27 01:51:47 +02:00
DISTRIB Update copyright year to 2025 2025-01-02 18:39:42 +01:00
edt-user.el Update copyright year to 2025 2025-01-02 18:39:42 +01:00
EGLOT-NEWS Eglot: improve diagnostic-reporting performance 2025-04-29 12:23:06 +01:00
emacs-buffer.gdb Update copyright year to 2025 2025-01-02 18:39:42 +01:00
emacs-mail.desktop
emacs.desktop
emacs.icon
emacs.metainfo.xml Provide Open Age Ratings Service metadata 2025-04-19 16:43:23 +03:00
emacs.service
emacs_lldb.py Update copyright year to 2025 2025-01-02 18:39:42 +01:00
emacsclient-mail.desktop Add 'server-eval-args-left' to server.el 2023-10-29 14:10:23 +02:00
emacsclient.desktop Make emacsclient handle org-protocol:// links 2023-09-18 12:54:22 +02:00
enriched.txt Update copyright year to 2025 2025-01-02 18:39:42 +01:00
ERC-NEWS ; Don't quote localp argument to define-erc-module 2025-01-22 16:07:55 -08:00
ETAGS.EBNF Update copyright year to 2025 2025-01-02 18:39:42 +01:00
ETAGS.README Update copyright year to 2025 2025-01-02 18:39:42 +01:00
future-bug ; Fix typos 2025-01-23 03:14:37 +01:00
gnus-tut.txt Update copyright year to 2025 2025-01-02 18:39:42 +01:00
grep.txt Update copyright year to 2025 2025-01-02 18:39:42 +01:00
HELLO Update copyright year to 2025 2025-01-02 18:39:42 +01:00
HISTORY Release Emacs 30.1 2025-02-23 17:30:57 +01:00
JOKES
MACHINES Delete duplicate note on ancient platforms 2025-01-05 05:32:01 +01:00
MH-E-NEWS Update copyright year to 2025 2025-01-02 18:39:42 +01:00
NEWS Add line-column tracking for tree-sitter 2025-05-03 22:14:03 -07:00
NEWS.1-17 Update copyright year to 2025 2025-01-02 18:39:42 +01:00
NEWS.18 Update copyright year to 2025 2025-01-02 18:39:42 +01:00
NEWS.19 ; Move time-stamp release info from symbol-releases.eld to NEWS 2025-03-23 10:39:52 -07:00
NEWS.20 ; Move time-stamp release info from symbol-releases.eld to NEWS 2025-03-23 10:39:52 -07:00
NEWS.21 ; Move time-stamp release info from symbol-releases.eld to NEWS 2025-03-23 10:39:52 -07:00
NEWS.22 Update copyright year to 2025 2025-01-02 18:39:42 +01:00
NEWS.23 Update copyright year to 2025 2025-01-02 18:39:42 +01:00
NEWS.24 Update copyright year to 2025 2025-01-02 18:39:42 +01:00
NEWS.25 Fix capitalization ELisp -> Elisp 2025-03-12 09:38:33 +08:00
NEWS.26 Fix capitalization ELisp -> Elisp 2025-03-12 09:38:33 +08:00
NEWS.27 Update copyright year to 2025 2025-01-02 18:39:42 +01:00
NEWS.28 Fix capitalization ELisp -> Elisp 2025-03-12 09:38:33 +08:00
NEWS.29 ; Grammar fixes for "native-compiled" 2025-02-28 20:20:55 +01:00
NEWS.30 Fix capitalization ELisp -> Elisp 2025-03-12 09:38:33 +08:00
NEXTSTEP Update copyright year to 2025 2025-01-02 18:39:42 +01:00
NXML-NEWS Update copyright year to 2025 2025-01-02 18:39:42 +01:00
ORG-NEWS ; Fix typos 2025-02-22 14:48:29 +01:00
org.gnu.emacs.defaults.gschema.xml Update copyright year to 2025 2025-01-02 18:39:42 +01:00
package-keyring.gpg * etc/package-keyring.gpg: Update expiration and add new key 2024-10-22 12:35:18 -04:00
PROBLEMS Remove ctags program 2025-03-22 11:57:29 -07:00
ps-prin0.ps Update copyright year to 2025 2025-01-02 18:39:42 +01:00
ps-prin1.ps Update copyright year to 2025 2025-01-02 18:39:42 +01:00
publicsuffix.txt ; * etc/publicsuffix.txt: Update from upstream. 2024-12-22 13:50:41 +02:00
README Update copyright year to 2025 2025-01-02 18:39:42 +01:00
rgb.txt Revert "Update etc/rgb.txt from X.Org upstream" 2023-10-16 08:56:53 +08:00
ses-example.ses Update copyright year to 2025 2025-01-02 18:39:42 +01:00
spook.lines
symbol-releases.eld ; Move time-stamp release info from symbol-releases.eld to NEWS 2025-03-23 10:39:52 -07:00
TERMS Update copyright year to 2025 2025-01-02 18:39:42 +01:00
TODO ; Replace "Elisp" with "Lisp" or "Emacs Lisp" in some places 2025-03-12 10:24:22 +08:00
w32-feature.el Update copyright year to 2025 2025-01-02 18:39:42 +01:00
yow.lines

This directory contains the architecture-independent files used by or
with Emacs.  This includes some text files of documentation for GNU
Emacs or of interest to Emacs users, and the file of dumped docstrings
for Emacs functions and variables.

COPYRIGHT AND LICENSE INFORMATION FOR IMAGE FILES

File: emacs.icon
  Author: Sun Microsystems, Inc
  Copyright (C) 1999, 2001-2025 Free Software Foundation, Inc.
  License: GNU General Public License version 3 or later (see COPYING)