Paul Eggert [Sat, 12 Jul 2025 21:31:18 +0000 (14:31 -0700)]
insert-file-contents file end EOF fixes
* src/fileio.c (Finsert_file_contents):
When counting bytes at file end, don’t trust lseek to seek
to the end of the file. Instead, read a bit after lseeking,
to make sure we get to the end, give up if we don’t get to EOF.
This works around problems on /proc filesystems
where lseek pretends the file is empty.
Update file_size_hint when reaching EOF.
Paul Eggert [Sat, 12 Jul 2025 21:22:02 +0000 (14:22 -0700)]
Fix insert-file-contents integer overflows
* src/fileio.c (Finsert_file_contents): Change ‘total’ from
ptrdiff_t to off_t since it might not fit in ptrdiff_t.
Check for overflow when estimating the insertion size.
Paul Eggert [Sat, 12 Jul 2025 20:56:55 +0000 (13:56 -0700)]
Remove ineffective overflow check
* src/fileio.c (Finsert_file_contents): Remove check for overflow.
The overflow is not possible, and the check was incorrectly
written and would not have caught it anyway.
Paul Eggert [Sat, 12 Jul 2025 19:36:56 +0000 (12:36 -0700)]
insert-file-contents initial offset fix
* src/fileio.c (Finsert_file_contents): Don’t assume that a
newly-opened file is at offset 0, even if it is a regular file.
This might not be true for files like /dev/stdin.
Paul Eggert [Sat, 12 Jul 2025 19:13:32 +0000 (12:13 -0700)]
Refactor negative file size checking
* src/fileio.c (Finsert_file_contents): Check for negative file
sizes earlier, as it’s easy, avoids some unnecessary work, and
will simplify later changes.
Paul Eggert [Sat, 12 Jul 2025 17:03:26 +0000 (10:03 -0700)]
Improve inserted file coding system finding
* src/fileio.c (Finsert_file_contents): When inserting a file into
a nonempty buffer, improve the heuristic for determining the
file’s coding system by not trusting lseek+SEEK_END, which is
unreliable in /proc or when the file is mutating.
Paul Eggert [Fri, 11 Jul 2025 23:32:31 +0000 (16:32 -0700)]
Improve insert-file-contents on non-regular files
This is part of a fix for Bug#77315,
and improves on the fix for Bug#71258.
* src/fileio.c (Finsert_file_contents): Do not pretend that
directories are regular files. Instead, signal an error when
attempting to read from them in the usual case where the OS
prohibits that; and otherwise read from them. However, when
visiting a directory report an error right away rather than
waiting until later, as this function is documented to not allow
visiting non-regular files. Nest the struct stat into a small
code block, to keep the code simpler and so that the compiler can
see what parts are used and can issue better diagnostics if
uninitialized storage is accessed. Be more skeptical of st_size,
when the file is not regular.
Paul Eggert [Fri, 11 Jul 2025 22:33:26 +0000 (15:33 -0700)]
Fix (find-file "/dev/null")
* lisp/files.el (find-file-noselect-1): When the file exists,
propagate any errors signaled by insert-file-contents,
instead of propagating them only when the file is unreadable.
This way, (find-file "/dev/null") gives a sensible diagnostic
"not a regular file" instead of the nonsense
"Maximum buffer size exceeded".
Paul Eggert [Wed, 22 Jan 2025 19:06:06 +0000 (11:06 -0800)]
Don’t trust st_size when scanning file head+tail
* src/fileio.c (Finsert_file_contents): Do not look at st_size
when scanning the file’s head and tail for a coding system comment.
Instead, just use read and SEEK_END and don’t worry if the latter fails.
st_size and lseek might not work in a /proc file system.
Paul Eggert [Wed, 22 Jan 2025 19:06:06 +0000 (11:06 -0800)]
copy-file no longer trusts st_size
In copy-file, do not trust st_size, since it might change as we run,
or we might be in a /proc system where it is unreliable anyway.
Also, fix some other unlikely copy-file bugs while we’re here.
* src/fileio.c (Fcopy_file): Use O_TRUNC when opening a
destination that already exists. This saves us the trouble
of having to call ftruncate with a possibly-bogus st_size;
the old motivation for using ftruncate is no longer compelling.
Do not assume ptrdiff_t is as wide as ssize_t; although this is
true on all known platforms, it’s easy to not assume it.
Don’t trust st_size. Prefer SSIZE_MAX to TYPE_MAXIMUM (ssize_t).
Always read+write, regardless of whether copy_file_range failed.
Paul Eggert [Sun, 13 Jul 2025 15:46:24 +0000 (08:46 -0700)]
READ_BUF_SIZE → sizeof read_buf
* src/fileio.c (Finsert_file_contents): Minor refactoring.
This should help future patches which distinguish read_buf’s size
from other uses of READ_BUF_SIZE which may change.
Paul Eggert [Sun, 13 Jul 2025 01:14:26 +0000 (18:14 -0700)]
insert-file-contents errno confusion
* src/fileio.c (read_non_regular): Return negation of
errno on failure, instead of -1.
(Finsert_file_contents): Signal with correct errno when a read fails.
Stefan Monnier [Mon, 14 Jul 2025 03:14:53 +0000 (23:14 -0400)]
org-persist.el: Silence fewer warnings and fix found warning
* lisp/org/org-persist.el: Minor cleanup.
(org-persist-directory, org-persist-remote-files)
(org-persist-default-expiry): Remove redundant `:group` arg.
(org-persist-collection-let): Document lack of hygiene.
Remove `with-no-warnings`.
(org-persist--find-index): Reindent, and simplify initialization of `r`.
(org-persist-associated-files:generic): Move before first use.
Alan Mackenzie [Sun, 13 Jul 2025 20:28:51 +0000 (20:28 +0000)]
Preserve source position of macro calls in macro expansions
This allows the byte compiler to give correct positions, those
of the invoking forms, when an error or warning is caused by
the innards of the invoked macros.
This fixes bug#73725 and bug#73746.
* lisp/emacs-lisp/macroexp.el (macroexp--posify-form-1)
(macroexp--posify-form): New functions.
(macroexp-preserve-posification): New macro.
(macroexp--compiler-macro, macroexp-macroexpand): Use the new
macro to preserve a calling form's position.
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form): Use the new
macro to preserve source positions.
* test/lisp/emacs-lisp/bytecomp-resources/bad-error-position.el
* test/lisp/emacs-lisp/bytecomp-resources/bad-error-position-2.el:
New test files.
* test/lisp/emacs-lisp/bytecomp-tests.el: Two new tests using
the new test files.
Michael Albinus [Sun, 13 Jul 2025 13:48:54 +0000 (15:48 +0200)]
tramp-file-name-with-method can be set connection-local
* doc/misc/tramp.texi (Ad-hoc multi-hops):
tramp-file-name-with-method can be set connection-local.
* etc/NEWS: tramp-file-name-with-method can be set connection-local.
Presentational fixes and improvements.
* lisp/net/tramp-cmds.el (tramp-get-file-name-with-method): New defun.
(with-tramp-file-name-with-method, tramp-file-name-with-sudo): Use it.
(tramp-dired-find-file-with-sudo): Fix docstring.
Sean Whitton [Sun, 13 Jul 2025 11:50:22 +0000 (12:50 +0100)]
New global minor mode vc-auto-revert-mode
* lisp/vc/vc-hooks.el (auto-revert-mode): Declare.
(vc-auto-revert-mode): New global minor mode.
(vc-turn-on-auto-revert-mode-for-tracked-files): New function.
* lisp/vc/vc-dispatcher.el (auto-revert-mode)
(auto-revert-buffers): Declare.
(vc-resynch-window): Don't call vc-revert-buffer-internal when
auto-revert-mode will revert the buffer. Call
auto-revert-buffers to ensure that this reversion happens in a
timely manner.
* lisp/vc/vc.el (vc-register): Apply vc-auto-revert-mode to
buffers visiting newly registered files.
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Improve the generated docstring.
* doc/emacs/vc1-xtra.texi (VC Auto-Reverting):
* etc/NEWS: Document the new minor mode.
Sean Whitton [Sun, 13 Jul 2025 11:30:43 +0000 (12:30 +0100)]
vc-register: Fix setting backup-inhibited
* lisp/vc/vc.el (vc-register): Delete unreachable code trying to
use 'buffer-file-name' as one of the file names. Properly set
'backup-inhibited' in any file-visiting buffers.
Sean Whitton [Fri, 11 Jul 2025 08:58:20 +0000 (09:58 +0100)]
VC: Fix displaying the async command buffer during async checkins
* lisp/vc/vc-dispatcher.el (vc--display-async-command-buffer):
New function, factored out of vc-do-async-command.
(vc-do-async-command): Use it.
(vc-finish-logentry): Bind vc--inhibit-async-window when running
the log operation, then call vc--display-async-command-buffer
again ourselves after performing other window changes.
Sean Whitton [Fri, 11 Jul 2025 08:30:19 +0000 (09:30 +0100)]
Apply vc-use-incoming-outgoing-prefixes to vc-dir-mode-map too
* lisp/vc/vc-dir.el (vc-use-incoming-outgoing-prefixes):
* lisp/vc/vc-hooks.el: Apply vc-use-incoming-outgoing-prefixes
to the corresponding bindings in vc-dir-mode-map, too.
Speed up low-level parts of the reader and refactor
Inspect the given 'readcharfun' source once, before using it, instead of
for each character read. This moves a bunch of branches away from the
critical path, with separate functions for different source types.
Replace some preprocessor macros with functions.
* src/lread.c (READCHAR, UNREAD, READCHAR_REPORT_MULTIBYTE)
(FROM_FILE_P): Remove; use corresponding functions instead.
All callers adapted.
(source_t): New struct that takes the place of the `readcharfun` and
`readbyte` arguments in many places.
(init_source)
(source_buffer_get, source_buffer_unget)
(source_marker_get, source_marker_unget)
(source_string_get, source_string_unget)
(source_file_get, source_file_unget)
(source_function_get, source_function_unget)
(from_file_p, unreadbyte_from_file):
New.
(readbyte_from_stdio): Replace `readbyte_from_file`.
(readchar, unreadchar): Rewrite.
(lisp_file_lexical_cookie, readevalloop, read_internal_start):
Create a source_t for use during reading. All signatures and functions
called adapted.
(read_char_escape): Remove check for an error that can no longer occur.
Juri Linkov [Thu, 10 Jul 2025 06:40:51 +0000 (09:40 +0300)]
Cache only the last string in 'tab-bar-format-align-right' (bug#78953)
* lisp/tab-bar.el (tab-bar--align-right-cache):
Rename from 'tab-bar--align-right-hash'.
(tab-bar-format-align-right): Use it to store
the string in the car, and the width in the cdr.
Yuan Fu [Fri, 23 May 2025 00:57:37 +0000 (17:57 -0700)]
Eldoc: Run eldoc-display-functions with original buffer (bug#78530)
Also bump eldoc version so Eglot can require the new version
later.
* lisp/emacs-lisp/eldoc.el (eldoc--invoke-strategy): Run the
hook with the original buffer as the current buffer. This way
we're certain that the buffer-local value of
'eldoc-display-functions' is used.
(eldoc-display-functions): Update docstring.
Pip Cet [Wed, 9 Jul 2025 15:16:07 +0000 (15:16 +0000)]
Call eieio--class-* accessors only on eieio classes (bug#78786)
* lisp/emacs-lisp/eieio-core.el (eieio-oref, eieio-oref-default):
(eieio-oset, eieio-oset-default): Don't look for class slots except in
eieio classes.
* test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
(eieio-test-defstruct-slot-value): New test.
Martin Rudalics [Wed, 9 Jul 2025 07:52:01 +0000 (09:52 +0200)]
Handle invalid frame_or_window slots in tty input events (Bug#78966)
* src/frame.c (make_terminal_frame): Initialize terminal's
top_frame slot if it has not been set up yet (Bug#78966).
* src/keyboard.c (kbd_buffer_get_event): Do not assume that the
event's frame_or_window slot always produces a valid frame
(Bug#78966).
(tty_read_avail_input): Try to make sure that the input event we
create has a valid frame_or_window slot (Bug#78966). Add assertion
to that purpose.
Yuan Fu [Wed, 9 Jul 2025 06:15:58 +0000 (23:15 -0700)]
Ditch the async range update in tree-sitter (bug#78402)
Right now in treesit-outline-search -> treesit-navigate-thing, a
freshly created tree-sitter node becomes outdated within the
function. I'm not sure _exactly_ how it happend, but it might
look like this: we first get a node from, say, html parser, then
get another node from, say, liquid parser. Creating the node
from liquid parser causes a reparse which updated the range of
the html parser, which rendered the html node outdated.
There're several problems with the current design, let's start
with the most obvious one: we add
treesit--font-lock-mark-ranges-to-fontify as a notifier of the
primar parser in treesit-major-mode-setup. Now, if a ts major
mode inherits another major mode, treesit-major-mode-setup will
be called twice, once in the parent mode and once in the child
node, and two parsers will have the notifier. But
treesit--font-lock-mark-ranges-to-fontify is designed to run
only once.
I believe this bug, together with some mysterious async
execution order, led to the problems we saw in the bug report.
My solution is to just make everything synchronous.
So I added treesit-parser-changed-regions, and modified
treesit--font-lock-mark-ranges-to-fontify to use it. Now we
don't need to add the notifier to the primary parser anymore.
I also applied the tree-sitter-outline change we discussed in
the bug report. (Change to treesit-outline-search, and remove
treesit--after-change.)
* lisp/treesit.el:
(treesit--font-lock-mark-ranges-to-fontify): Remove the unused
PARSER arg.
(treesit--pre-redisplay): Make use of
treesit-parser-changed-regions.
(treesit-outline-search): Call treesit--pre-redisplay in the
beginning.
(treesit--after-change): Remove function.
(treesit-major-mode-setup): Don't add notifier to primary parser.
Yuan Fu [Wed, 9 Jul 2025 06:14:20 +0000 (23:14 -0700)]
Add a synchronous way to get parser change ranges (bug#78402)
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.
Juri Linkov [Wed, 9 Jul 2025 06:28:05 +0000 (09:28 +0300)]
Fix tab-bar-format-align-right to not call tab-bar-format-global twice
* lisp/tab-bar.el (tab-bar-format-align-right): Add optional arg 'rest'
to handle it specially in 'tab-bar-format-list'. Use the value from 'rest'
instead of calling format functions twice by 'tab-bar-format-list'.
(tab-bar-format-list): When 'format-list' contains the item
'tab-bar-format-align-right', collect the rest of formatted items
and call 'tab-bar-format-align-right' explicitly with the collected
list (bug#78953).
Abstract the buffering in the reader with a struct and plain functions
instead of rather unhygienic preprocessor macros.
* src/lread.c (READ_AND_BUFFER, INVALID_SYNTAX_WITH_BUFFER):
Removed, replaced with...
(readbuf_t, readbuf_grow, add_char_to_buffer, read_and_buffer)
(invalid_syntax_with_buffer): ...these new functions and struct.
(read0): Use new code instead of old preprocessor macros.
Sean Whitton [Mon, 7 Jul 2025 14:44:34 +0000 (15:44 +0100)]
Resolve FIXME regarding running vc-checkin-hook
Running vc-checkin-hook needs to be delayed in the case of an
async checkin. As a quick fix we had been relying on the
backend checkin functions to run the hook in the async case.
This restores handling running the hook in generic code even for
the async case.
* lisp/vc/vc.el (vc-checkin): Always pass vc-checkin-hook to
vc-start-logentry. Return the result of calling the backend
'checkin-patch' or 'checkin' function to vc-finish-logentry.
* lisp/vc/vc-dispatcher.el (vc-finish-logentry): If the log
operation returns a cons of the form (async . #<process ...>),
use vc-exec-after to delay vc-resynch-buffer and hooks until the
async process completes. Approach suggested by Dmitry Gutov.
* lisp/vc/vc-git.el (vc-git-checkin):
* lisp/vc/vc-hg.el (vc-hg-checkin): For an async checkin, return
a cons (async . #<process ...>) containing the async checkin
process. No longer run vc-checkin-hook.
* lisp/vc/vc.el (with-vc-properties): Return the result of
evaluating FORM.
* lisp/vc/vc-dispatcher.el (vc-exec-after): Change to PROC's
buffer before calling vc-set-mode-line-busy-indicator.
Turn compiler macro defalias messages into warnings
* lisp/emacs-lisp/bytecomp.el (byte-compile-file-form-defalias):
Turn messages into warnings to make them more visible to the user and
provide a source location (bug#78792).
Jim Porter [Wed, 25 Jun 2025 05:50:22 +0000 (22:50 -0700)]
Use short revisions by default when navigating to revisions
* lisp/vc/vc-annotate.el (vc-annotate-revision-previous-to-line)
(vc-annotate-show-diff-revision-at-line-internal)
(vc-annotate-warp-revision): Let-bind 'vc-use-short-revision'
around calls to 'previous-revision' and 'next-revision'.
Jim Porter [Fri, 4 Jul 2025 23:23:45 +0000 (16:23 -0700)]
Show "readable" status in the EWW mode line
* lisp/net/eww.el (eww-display-html): Check whether a readable form of
the document exists; if not, don't set ':readable' to t.
(eww-readable): Check whether a readable form of the document exists; if
not, warn the user and don't add to history.
(eww-readable-dom): Return nil if no readable form exists.
(eww-mode): Check the ':readable' property of 'eww-data' to show
"readable" state in the mode line.
* test/lisp/net/eww-tests.el
(eww-test/readable/default-readable/non-readable-page): New test
(bug#78958).
Sean Whitton [Sun, 6 Jul 2025 12:43:24 +0000 (13:43 +0100)]
vc-checkin: Check whether the fileset or patches have changed
* lisp/vc/vc-dispatcher.el (vc-finish-logentry): Delay popping
to vc-parent-buffer until after calling the log operation.
That way if the log operation exits early, the current buffer
remains *vc-log*.
(vc-dir-marked-files, dired-get-marked-files): Declare.
(vc-dispatcher--explicit-marks-p): New function.
* lisp/vc/vc.el (vc-checkin): Check the user isn't likely to be
surprised by what is included in the checkin. Specifically,
check whether the fileset or patches implied by vc-parent-buffer
are unchanged.
* doc/emacs/maintaining.texi (VC With A Merging VCS): Explain
how the fileset or patch string is fixed once *vc-log* pops up.
Michael Albinus [Sun, 6 Jul 2025 12:41:02 +0000 (14:41 +0200)]
Adapt filenotify-tests.el for Emba
* test/infra/gitlab-ci.yml (.filenotify-gio-template): Enable also
for scheduled jobs.
* test/lisp/filenotify-tests.el (file-notify--test-cleanup):
Fix docstring.
(file-notify--deftest-remote): Use `file-notify--test-cleanup'.
(file-notify-test03-events, file-notify-test05-file-validity)
(file-notify-test06-dir-validity)
(file-notify-test07-many-events)
(file-notify-test09-watched-file-in-watched-dir): Adapt tests.
(file-notify-test03-events-remote)
(file-notify-test04-autorevert-remote)
(file-notify-test07-many-events-remote)
(file-notify-test09-watched-file-in-watched-dir-remote): Do not
tag as :unstable.