1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-04 19:10:37 -08:00
Commit graph

1372 commits

Author SHA1 Message Date
Paul Eggert
481ad70d5c December 2025 spelling fixes
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-26 10:22:12 -08:00
Jacob S. Gordon
cff022f0c3 Add binary format specifications '%b' and '%B'
These produce the binary representation of a number.
'%#b' and '%#B' prefix with '0b' and '0B', respectively.
(bug#79990)
* etc/NEWS: Announce change.
* doc/lispref/strings.texi (Formatting Strings): Describe new format
specs and add to comment on reconstructing the value with 'read'.
* src/editfns.c (format): Update doc string.
(styled_format): Add support for '%b' and '%B'.  To remain
portable, avoid use of 'sprintf' by converting by hand.
* test/src/editfns-tests.el (format-binary-zero, format-binary-floats)
(format-binary-nonzero-integers): Add tests.
(read-large-integer): Add binary test cases.
Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>
2025-12-22 00:15:09 -08:00
Jens Schmidt
0aabe62b64 Improve handling of non-ASCII characters in 'transpose-regions'
* src/editfns.c (Ftranspose_regions): Separate code related to character
semantics from that related to byte semantics and in that way leverage
optimizations for regions of equal length with respect to both
semantics.  Move and update comments dating back to the initial
implementation.
* test/src/editfns-tests.el (editfns-tests--transpose-regions-tests)
(editfns-tests--transpose-regions-markups)
(editfns-tests--transpose-regions): New test and accompanying variables.
2025-12-20 13:23:29 -05:00
Mattias Engdegård
5e7a71d0f4 Don't emit print-circle refs for empty string and vector
The empty vector and string(s) are immutable, contain no references and
always read as the same objects.

* src/print.c (PRINT_CIRCLE_CANDIDATE_P): Turn macro into...
(print_circle_candidate_p): ...a function, and exclude [] and "".
* test/src/print-tests.el (print-circle): Add test case.
2025-12-04 17:52:14 +01:00
Mattias Engdegård
ef903e0f5a * test/src/data-tests.el (data-tests-ash-lsh): Test for bug#79876. 2025-11-29 19:41:16 +01:00
Eli Zaretskii
858d54d51d ; Fix cleanup in buffer-tests
* test/src/buffer-tests.el (test-restore-buffer-modified-p)
(test-buffer-chars-modified-ticks): Don't leave unsaved and
modified file buffers after the tests.
2025-11-16 11:08:11 +02:00
Mattias Engdegård
0c694624c3 * test/src/comp-tests.el (setcarcdr): Don't mutate literals. 2025-11-06 16:22:13 +01:00
Yuan Fu
b01435306a
Change tree-sitter query predicate names (bug#79687)
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-11-02 17:11:55 -08:00
Eli Zaretskii
23d8633579 Avoid face inheritance cycles
* src/xfaces.c (face_inheritance_cycle): New function.
(Finternal_set_lisp_face_attribute): Signal an error if the
':inherit' attribute of a face is modified in a way that will
cause it to inherit from itself.  (Bug#79672)

* test/src/xfaces-tests.el (xfaces-test-circular-inheritance): New
test.

* etc/NEWS: Announce the incompatible change.
2025-10-27 15:54:10 +02:00
Helmut Eller
48357dc612 Add a test for puthash
It's actually for a bug on the feature/igc branch.

* test/src/fns-tests.el (ft-puthash-weak): New test
(ft--puthash-weak): New helper.
2025-10-18 20:22:17 +02:00
Spencer Baugh
bea16dfe69 Respect keymaps in buffer text for clicks on displayed strings
When clicking on a string displayed by a display property, also
look at the text properties of the underlying buffer text for
keymaps, not just the displayed string.  The displayed string
takes precedence over the buffer text, but it doesn't replace
it.

Also, we should use the buffer's local map even for clicks on
the mode line.  (Otherwise, what's the point of the <mode-line>
event?)

* src/keymap.c (Fcurrent_active_maps): Consider displayed
string, then buffer text, then fall back to local
map.  (Bug#79505)

* test/src/keymap-tests.el
(keymap-test-keymaps-for-non-buffer-positions): Add more tests.
2025-10-18 12:48:41 +03:00
Helmut Eller
3e78f6487d Add some tests for weak hashtables
Also add ft- as shorthand for fns-tests-.

* test/src/fns-tests.el (ft-hash-table-weakness, ft-weak-key-removal)
(ft-weak-value-removal, ft-weak-and-removal, ft-weak-or-removal): New
tests.
(ft--test-weak-removal, ft--gc, ft--check-entries, ft--check-entry)
(ft--hash-table-entries, ft--populate-hashtable, ft--component-num)
(ft--parse-component, ft--dead-component, ft--format-component)
(ft--init-rng, ft--nentries): New helpers.
2025-10-17 10:06:16 +02:00
Spencer Baugh
443af6fe1d Allow creating a pipe process without a buffer
Previously, even passing :buffer nil to make-pipe-process would
create a buffer.  Now, if you explicitly call (make-pipe-process
:buffer nil), it will create a pipe process without a buffer,
just like all the other process creation functions.

* src/process.c (Fmake_pipe_process): Check for explicit :buffer
nil and don't make a buffer. (bug#79596)
* doc/lispref/processes.texi (Asynchronous Processes): Update.
* test/src/process-tests.el
(process-test-make-pipe-process-no-buffer): Add test.
2025-10-11 12:14:10 +03:00
Michael Albinus
979ddc0601 Fix failed tests on emba
* test/lisp/autorevert-tests.el (auto-revert-test05-global-notify)
(auto-revert-test07-auto-revert-several-buffers): Adapt tests.

* test/src/comp-resources/comp-test-funcs.el (foo): Define error symbol.
2025-09-18 14:56:05 +02:00
Mattias Engdegård
464216ca73 ; even less test log spam from load 2025-09-12 10:41:43 +02:00
Spencer Baugh
0e9cee2bf5 Ignore keymaps at point for positions outside the buffer
Correct a few edge cases where we used the keymaps at point when
looking up keymaps for an event position which is outside the
current buffer.  Namely:

- Clicking on a part of the mode line which is after the end of
  mode-line-format produces an event with non-nil posn-area but
  nil posn-string.

- Even if posn-string doesn't have a local keymap, we should
  still ignore the keymaps at point if posn-string is non-nil.

* src/keymap.c (Fcurrent_active_maps): Ignore keymaps at point
for more positions outside the buffer.  (bug#76620)
2025-09-09 18:02:24 -04:00
Mattias Engdegård
308e3ab1db Disallow string data resizing (bug#79784)
Only allow string mutation that is certain not to require string data to
be resized and reallocated: writing bytes into a unibyte string, and
changing ASCII to ASCII in a multibyte string.

This ensures that mutation will never transform a unibyte string to
multibyte, that the size of a string in bytes never changes, and that
the byte offsets of characters remain the same.  Most importantly, it
removes a long-standing obstacle to reform of string representation and
allow for future performance improvements.

* src/data.c (Faset): Disallow resizing string mutation.
* src/fns.c (clear_string_char_byte_cache):
* src/alloc.c (resize_string_data):  Remove.
* test/src/data-tests.el (data-aset-string): New test.
* test/lisp/subr-tests.el (subr--subst-char-in-string):
Skip error cases.
* test/src/alloc-tests.el (aset-nbytes-change):
Remove test that is no longer relevant.
* doc/lispref/strings.texi (Modifying Strings):
* doc/lispref/sequences.texi (Array Functions):
* doc/lispref/text.texi (Substitution):  Update manual.
* etc/NEWS: Announce.
2025-08-24 10:28:27 +02:00
Mattias Engdegård
c04553f655 Speed up JSON parsing by not maintaining line and column (bug#79192)
We use the current parsing position instead.  The line and column in the
error weren't used (nor very accurate to begin with) and the user can
easily compute them when needed.  The line number calculation is kept
just in case but deprecated, for removal in Emacs 32.

* src/json.c (struct json_parser, json_parser_init): Update parser state.
(json_signal_error): New position computation.
(json_skip_whitespace_internal): Remove.
(is_json_whitespace): New.
(json_skip_whitespace, json_skip_whitespace_if_possible)
(json_parse_unicode, json_parse_string, json_parse_number)
(json_parse_value): Simplify and rewrite for efficiency.
(count_chars, count_newlines)
(string_byte_to_pos, string_byte_to_line)
(buffer_byte_to_pos, buffer_byte_to_line): New.
(Fjson_parse_string, Fjson_parse_buffer): Adapt to new parser state.
* test/src/json-tests.el (json-tests--parse-string-error-pos)
(json-tests--parse-buffer-error-pos, json-parse-error-position): New.
* etc/NEWS: Note deprecation of line and column.
2025-08-21 16:42:45 +02:00
Eli Zaretskii
9985e71eb7 ; Stabilize a Windows-specific process-test
* test/src/process-tests.el (process-sentinel-interrupt-event):
Improve stability of results, and show all of the results.
2025-08-16 13:11:19 +03:00
Eli Zaretskii
406140df33 ; Skip a process-test that is unreliable on MS-Windows
* test/src/process-tests.el
(process-tests/multiple-threads-waiting): Skip on MS-Windows.
2025-08-16 12:04:59 +03:00
Eli Zaretskii
45d4b0a97c ; Fix thread-tests
* test/src/thread-tests.el (make-thread): Fix declaration.
(thread-set-buffer-disposition, thread-buffer-disposition):
Declare.  (Bug#76969)
2025-08-10 07:40:58 +03:00
Dmitry Gutov
07eb39f113 Allow thread's buffer to be killed, by default
* src/thread.c (Fmake_thread): Add new argument (bug#76969).
(thread_set_error): New function, extracted from thread-signal.
(Fthread_buffer_disposition): Add getter.
(Fthread_set_buffer_disposition): And setter.
(thread_check_current_buffer): Check the values of threads'
buffer_disposition.
(thread_all_before_buffer_killed): New function.
(init_threads): Set buffer_disposition to nil for the main thread.
(syms_of_threads): Add new symbols and define the error.

* src/thread.h (thread_state): New field buffer_disposition.
(thread_all_before_buffer_killed): Declare.

* src/buffer.c (Fkill_buffer): Call thread_check_current_buffer
one more time after all hooks and after that call
thread_all_before_buffer_killed.

* src/comp.c (ABI_VERSION): Increase the value.

* test/src/thread-tests.el (thread-buffer-disposition-t)
(thread-buffer-disposition-nil)
(thread-buffer-disposition-silently)
(thread-set-buffer-disposition)
(thread-set-buffer-disposition-main-thread): New tests.

* doc/lispref/threads.texi (Basic Thread Functions): Document
buffer-disposition in make-thread and its getter and setter.

* etc/NEWS: Add entry.
2025-08-09 22:40:07 +03:00
Manuel Giraud
42b990cd20 Fix some tests on OpenBSD
* test/lisp/eshell/em-script-tests.el
(em-script-test/batch-file/shebang): "env -S" is not supported.
* test/src/fns-tests.el (fns-tests-random): 'random' is
non-deterministic on OpenBSD.  (Bug#79190)
2025-08-07 17:43:58 +03:00
Mattias Engdegård
2d18878b96 Move keyboard input functions from lread.c to keyboard.c
These have nothing to do with the Lisp reader at all.

Suggested by Lynn Winebarger (bug#79035).

* src/lread.c (read_filtered_event, Fread_char, Fread_event)
(Fread_char_exclusive, Qascii_character): Move...
* src/keyboard.c: ...here.
* test/src/lread-tests.el (test-inhibit-interaction): Move...
* test/src/keyboard-tests.el (keyboard-inhibit-interaction): ...here.
2025-07-30 11:04:11 +02:00
Mattias Engdegård
33161e51e5 Check for end-of-file when reading character escapes (bug#79097)
* src/lread.c (read_char_escape): Add check.
* test/src/lread-tests.el (lread-char-escape-eof): New test.
2025-07-25 21:54:59 +02:00
Eli Zaretskii
7300f50007 ; Avoid lexical-binding warning in lread-tests
* test/src/lread-tests.el (lread-test-bug-31186)
(lread-tests--unescaped-char-literals): Avoid lexical-binding warning.
2025-07-19 20:50:57 +03:00
Mattias Engdegård
c184ea2441 ; silence some compiler warnings in tests
* test/lisp/savehist-tests.el (savehist-test-saved-variables):
(savehist-test-duplicated-saved-symbols):
* test/src/data-tests.el (binding-test-toplevel-values):
Suppress harmless warnings.
2025-07-19 17:02:28 +02:00
Mattias Engdegård
f4a9673f61 Speed up unintern, and fix symbol shorthand edge case (bug#79035)
Don't do a full lookup if the argument is a symbol, and only compute the
hash index once.  Fix a bug that occurred when there is another symbol
whose shorthand is equal to the true name of the symbol being removed.

* src/lread.c (Funintern): Rewrite for speed and correctness.
(oblookup_last_bucket_number, oblookup): Remove now unused variable.
* test/src/lread-tests.el (lread-unintern): New test.
2025-07-19 16:48:11 +02:00
Eli Zaretskii
ae560ae11c ; Fix last change. 2025-07-17 10:40:33 +03:00
Eli Zaretskii
29324fd0fa ; * test/src/fileio-tests.el (fileio-tests--read-directory): New test. 2025-07-17 10:26:17 +03:00
Eli Zaretskii
d0f96de277 ; Fix 'threads-join-error' test
* test/src/thread-tests.el (threads-thread-sleeps): New helper
function.
(threads-join-error): Fix to work as intended, and remove the
'unstable' tag.  (Bug#40823)
2025-07-14 15:48:45 +03:00
Mattias Engdegård
52b96d3a7e * src/fns.c (Flength): Fix char table length off-by-one bug. 2025-07-11 16:36:27 +02:00
Andrea Corallo
48a5917681 Nativecomp don't materialize non-materializable objects (bug#78606)
The native compiler should not try to generate in rendered code
immediate floats produced by the constrain on the '=' operator.

* test/src/comp-tests.el (comp-test-78606-1): Add test.
* test/src/comp-resources/comp-test-funcs.el (comp-test-78606-1-f): New
function.
* src/comp.c (emit_mvar_rval): Check if an immediate is materializable.
* lisp/emacs-lisp/comp.el (comp-ctxt): Add 'non-materializable-objs-h'
slot.
(comp--fwprop-insn): Update call.
* lisp/emacs-lisp/comp-cstr.el (comp-cstr-=): Add parameter.
2025-07-09 17:32:07 +02:00
Mattias Engdegård
d13693ef4e Read non-ASCII chars from unibyte string sources as raw bytes
Previously, latin-1 was incorrectly assumed (bug#70988).

* src/lread.c (readchar): Convert to raw byte.
* test/src/lread-tests.el (lread-unibyte-string-source): New test.
2025-07-07 11:30:07 +02:00
Mattias Engdegård
f2f7675621 Print non-ASCII chars in unibyte symbols as raw bytes
Previously, latin-1 was incorrectly assumed (bug#70988).

* src/print.c (print_object): Call the correct function.
* test/src/print-tests.el (print-unibyte-symbols): New test.
2025-07-07 11:30:07 +02:00
Mattias Engdegård
553a6c407f Read characters from functions as multibyte
Previously, latin-1 was incorrectly assumed (bug#70988).

* src/lread.c (readchar): Set multibyte flag.
* test/src/lread-tests.el (lread-function-source): New test.
2025-07-07 11:30:07 +02:00
Stefan Monnier
b93d49a378 (Ftranspose_regions): Fix bug#76124
* src/editfns.c (Ftranspose_regions): Be careful that ELisp code could
move the gap from under our feet.

* test/src/editfns-tests.el (editfns-tests--bug76124): New test.
2025-07-06 19:15:51 -04:00
Pip Cet
6b19eb53c5 Avoid extra output in Vprin1_to_string_buffer (bug#78842)
print_error_message can throw after producing some output, so use
unwind-protect to ensure prin1-to-string-buffer is cleared.

* src/print.c (erase_prin1_to_string_buffer): New.
(Ferror_message_string): Use it to catch errors thrown in
'print_error_message'.
* test/src/print-tests.el (error-message-string-circular): Expand
test.
2025-06-28 10:46:08 +00:00
Stefan Monnier
6c0bbf0f92 (Finsert_file_contents): Refine commit d07af40d88
* src/fileio.c (Finsert_file_contents): Inhibit ask-supersession
only if we're VISITing in a non-narrowed buffer (bug#78866).

* test/src/fileio-tests.el (ert--tests-dir): New var.
(fileio-tests--insert-file-contents-supersession): New test.
2025-06-27 23:11:39 -04:00
Juri Linkov
789a6b9693 Fix usage of 'treesit-defun-type-regexp' in treesit-tests.
* test/src/treesit-tests.el (treesit--ert-test-defun-navigation):
Replace 'treesit-defun-type-regexp' with
'(or treesit-defun-type-regexp 'defun)' that fixes the tests
for ts-modes that set up the 'defun' thing instead of
'treesit-defun-type-regexp'.
2025-06-25 19:45:54 +03:00
Andrea Corallo
f38e969e47 Make nativecomp don't error when encountering undeclared types (bug#6573)
* test/src/comp-resources/comp-test-funcs.el (comp-test-76573-1-f): New
function.
* lisp/emacs-lisp/comp-cstr.el (comp-supertypes): Don't error if 'type'
is unknown.
2025-06-17 09:22:32 +02:00
Zach Shaftel
009cdc8ae0 Fix segfault in profiler-cpu-log and profiler-memory-log (bug#78763)
* src/profiler.c (export_log): Check if a log has been allocated first,
and return nil if it hasn't.
(Fprofiler_cpu_log, Fprofiler_memory_log): Doc fix.
* test/src/profiler-tests.el (profiler-tests-cpu-profiler)
(profiler-tests-memory-profiler): New tests.
2025-06-14 17:54:06 +03:00
Sean Whitton
f699b6e4f4 Gather variable binding tests in data-tests.el
* test/lisp/emacs-lisp/lisp-tests.el (c-e-x, c-e-l):
Move to data-tests.el.
(core-elisp-tests-2-window-configurations): Rename ...
(core-elisp-tests-1-window-configurations): ... to this.
(core-elisp-tests-3-backquote): Rename ...
(core-elisp-tests-2-backquote): ... to this.
(core-elisp-tests-1-defvar-in-let)
(core-elisp-tests-4-toplevel-values): Move and rename ...
* test/src/data-tests.el (binding-test-defvar-in-let)
(binding-test-toplevel-values): ... to these.
(c-e-x, c-e-l): Moved from data-tests.el.
2025-05-30 11:41:19 +01:00
Pip Cet
d14fc6b75f Fix unsafe SDATA usage in print.c (bug#78590)
* src/print.c (print_string_1): Renamed from 'print_string', with an
extra argument to disable nonascii escaping.
(print_string): New function.
(print_object): Use 'print_string_1', not 'strout'.
2025-05-28 19:22:57 +00:00
Eli Zaretskii
8b67e566b9 Fix filelock-tests on MS-Windows
* test/src/filelock-tests.el (filelock-tests-file-locked-p-spoiled)
(filelock-tests-unlock-spoiled)
(filelock-tests-kill-buffer-spoiled): Don't special-case
MS-Windows, as it was evidently fixed to signal the same error as
Posix systems.
2025-05-12 15:08:20 +03:00
Eli Zaretskii
7d84ffc2de Add test for file time-stamp granularity on MS-Windows
* test/src/fileio-tests.el
(fileio-tests-w32-time-stamp-granularity): New test.
2025-05-11 15:47:17 +03:00
Eli Zaretskii
cc6e604da6 ; More fixes for treesit tests
* test/src/treesit-tests.el (treesit-parse-string)
(treesit-parser-tracking-line-column-p)
(treesit-tracking-line-column-p, treesit--linecol-at)
(treesit--linecol-cache-set, treesit--linecol-cache)
(treesit-languages-require-line-column-tracking): Declare.
2025-05-05 15:16:43 +03:00
Eli Zaretskii
b84e306be7 ; Fix recently added treesit tests
* test/src/treesit-tests.el (treesit-linecol-basic)
(treesit-linecol-search-back-across-newline)
(treesit-linecol-col-same-line): Skip tests if tree-sitter is not
available.
2025-05-05 15:07:28 +03:00
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
Stefan Monnier
9048fcf22c (decode_coding): Avoid nested *-change-functions (bug#78042)
* src/coding.c (decode_coding): Avoid nested *-change-functions (bug#78042).

* test/src/editfns-tests.el (sanity-check-change-functions-before)
(sanity-check-change-functions-after): Record notifications in
`sanity-check-change-functions-op`.
(sanity-check-change-functions-with-op): Don't rely on
`sanity-check-change-functions-op` always holding only the `op`.
(sanity-check-change-functions-errors): Include the sequence of
notifications in the error info.
(editfns-tests--before/after-change-functions): Add tests for (bug#78042).
2025-05-02 17:06:09 -04:00