Commit graph

50622 commits

Author SHA1 Message Date
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
Mattias Engdegård
e9deec70da Remove the variable load-convert-to-unibyte
It has been ineffective since 2002.
Suggested by Lynn Winebarger.

* src/lread.c (Fload, readevalloop_1, readevalloop, Feval_buffer)
(Feval_region, syms_of_lread): Remove the variable and its propagation.
* etc/NEWS: Announce.
2025-07-19 15:12:52 +02:00
Alvaro Ramirez
813013691a Add "Send to..." context menu item to mouse.el
* lisp/send-to.el: New package implements sending files/region.

* lisp/mouse.el (context-menu-send-to): Add "Send to..." context menu.

* lisp/term/ns-win.el (ns-send-items): Expose native macOS send API.

* src/nsfns.m (ns-send-items): Implement native macOS sending.

* etc/NEWS: Announce the new feature.
2025-07-19 14:15:55 +02:00
Stefan Monnier
f8b9d80ec6 comp.el: Fix minor corner-case annoyances
* lisp/emacs-lisp/comp.el (comp--native-compile): Avoid `%s`
on objects that may not have names.
* src/data.c (Ffset): Don't compute trampoline for no-op `fset`.
2025-07-17 12:36:57 -04:00
Paul Eggert
15570b7b95 Don’t optimize insert-file-contents for GNU
* src/fileio.c (Finsert_file_contents):
Remove a microoptimization for GNU/Linux and Android.
2025-07-16 23:21:23 -07:00
Paul Eggert
e450a7802c insert-file-contents small gap bug
Problem reported by Zhengyi Fu (Bug#79031).
* src/fileio.c (Finsert_file_contents): Do not read more than
requested, even when the gap is so small that we use a local buffer.
2025-07-16 11:45:23 -07:00
Paul Eggert
92dee45c5e insert-file-contents likely-end memory objects
* src/fileio.c (Finsert_file_contents): Treat memory objects like
regular files when inferring likely end.  Simplify likely end
computation.
2025-07-16 11:45:23 -07:00
Paul Eggert
8a1d368b62 Port insert-file-contents dir behavior to Unix
* src/fileio.c (Finsert_file_contents): Port better to traditional
Unix platforms like Solaris, where in some cases 'read' can
succeed on directories.
2025-07-16 11:45:23 -07:00
Michael Albinus
e4db6aa545 ; * src/xdisp.c: Fix typo. 2025-07-16 08:47:23 +02:00
Paul Eggert
42548c25f7 Fix insert-file-contents overlap check
In commit 61a8ce0280 I mistakenly
focused on overlap in the buffer.  The code also needs to check
for overlap in the inserted file data.
Problem reported by Gerd Möllmann (Bug#79020).
* src/fileio.c (Finsert_file_contents): Prevent overlap in both
the buffer head and tail, and in the inserted file’s head and tail.
Also, shrink the file’s head if the file shrank to be smaller
than its head.
2025-07-15 22:47:16 -07:00
Sean Whitton
a30372f42b ; Fix wording. 2025-07-15 21:58:59 +01:00
Sean Whitton
6ee0093b21 ; Fix recently introduced "ELisp". 2025-07-15 21:57:59 +01:00
Stefan Monnier
c3f3fe136c Add redisplay_counter to catch nested redisplays and abort outer one
The redisplay code is not re-entrant.  To allow running ELisp code
from within redisplay, we have some hacks (e.g. `inhibit-redisplay`)
that try to avoid the resulting breakage.
This commit adds another one of those hacks, which tries
to get closer to the core of the problem, thereby making it "safe"
to override `inhibit-redisplay`, e.g. to debug jit-lock code.

* src/dispextern.h (redisplay_counter): Declare.
* src/xdisp.c (redisplay_counter): Define.
(redisplay_internal) Increment it.
(dsafe__call): Use it, in case `inhibit-redisplay` is overridden.
* src/eval.c (call_debugger): Use it as well to refine the test
we already had.
2025-07-15 13:49:29 -04:00
Po Lu
b2d5e4fe40 Fix the Android port
* src/fileio.c (emacs_full_read): Retype FD param to `emacs_fd'.
(Fcopy_file): Label newsize MAYBE_UNUSED.
2025-07-14 21:41:18 +08:00
Juri Linkov
817f7829f9 * src/xdisp.c (tab-bar-truncate): New variable (bug#78953).
(tab_bar_height): Use it.
2025-07-14 09:43:18 +03:00
Paul Eggert
a8b65860a5 ; Fix indentation. 2025-07-13 21:39:54 -07:00
Paul Eggert
5bce6753e2 Speed up insert-file-contents reads
This change makes insert-file-contents-literally 30% faster on my
platform, when inserting xdisp.c.
* src/fileio.c (READ_BUF_SIZE): Remove, replacing with ...
(IO_BUFSIZE): ... this new constant from Coreutils.
All uses of READ_BUF_SIZE changed to either MAX_ALLOCA or
IO_BUFSIZE.
2025-07-13 21:09:40 -07:00
Paul Eggert
c3f96d20ee Avoid some tiny /proc file reads
* src/fileio.c (union read_non_regular):
New members buf and bufsize replace inserted and trytry.
(read_non_regular): Adjust to this new, simpler interface.
(Finsert_file_contents): If the gap is smaller than read_buf
and we want to read more than the gap, read into read_buf
first, to avoid lots of tiny reads from /proc files.
2025-07-13 21:09:40 -07:00
Paul Eggert
55f41ca3aa insert-file-contents file shrinkage in scanback
* src/fileio.c (emacs_full_read): New function.
(Fcopy_file, Finsert_file_contents): Use it.
(Finsert_file_contents): Check for partial reads when scanning
backwards through the file’s tail, as this indicates the file
shrank while we read it.  Also, use emacs_full_read in other
situations where it’s simpler and should be a bit faster.
2025-07-13 21:09:39 -07:00
Paul Eggert
8ac78986ff int → ptrdiff_t for read results
* src/fileio.c (Finsert_file_contents): Use ptrdiff_t, not int, to
store results returned by emacs_fd_read, which return ptrdiff_t.
This doesn’t fix any bugs since the values happen to fit in int,
but is a bit clearer and may simplify future changes.
2025-07-13 21:09:39 -07:00
Paul Eggert
f4adb56c9a insert-file-contents unexpected end shrinkage
* src/fileio.c (Finsert_file_contents): If the file unexpectedly
shrinks while reading its tail backwards, give up searching for
the match end.
2025-07-13 21:09:39 -07:00
Paul Eggert
c35d09edcf fileio.c comment spelling fix 2025-07-13 21:09:39 -07:00
Paul Eggert
4c4f68be4b insert-file-contents byte vs char confusion
* src/fileio.c (Finsert_file_contents): Use del_range_byte,
not del_range_1, since we are passing byte counts, not
character counts.  Problem reported by Pip Cet (Bug#77315).
2025-07-13 21:09:39 -07:00
Paul Eggert
61a8ce0280 Fix insert-file-contents overlap calculation
* src/fileio.c (Finsert_file_contents): Overlap is impossible, so
omit incorrect overflow adjustments that caused later index
calculations to go off the rails (Bug#77315).  Change a ‘ZV_BYTE’
to ‘same_at_end’ for clarity; they have the same value here.
2025-07-13 21:09:39 -07:00
Paul Eggert
e98da5cc3f insert-file-contents do not rely on st_size
This fix was prompted by Bug#77315.
* src/fileio.c (Finsert_file_contents): Do not rely on st_size for
anything other than a hint about the file size.  Trust only the
file size as revealed by a read that returns 0.
2025-07-13 21:09:39 -07:00
Paul Eggert
de0bb2e059 insert-file-contents file size hint improvement
* src/fileio.c (Finsert_file_contents): When reading yields 0,
update the file size hint to match.  This should improve its
accuracy.
2025-07-13 21:09:39 -07:00
Paul Eggert
aee9b59831 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.
2025-07-13 21:09:39 -07:00
Paul Eggert
56091b6d5c 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.
2025-07-13 21:09:39 -07:00
Paul Eggert
e6c6847973 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.
2025-07-13 21:09:39 -07:00
Paul Eggert
535ab2d116 insert-file-contents END enforcement
* src/fileio.c (Finsert_file_contents): When matching text
at buffer start, don’t go past END if specified.
2025-07-13 21:09:39 -07:00
Paul Eggert
e6c1f46fb1 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.
2025-07-13 21:09:39 -07:00
Paul Eggert
73ab98a8a2 insert-file-contents end offset infinity
* src/fileio.c (Finsert_file_contents): Simplify end_offset
calculation by defaulting to effectively infinity.
2025-07-13 21:09:39 -07:00
Paul Eggert
aa172be7d0 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.
2025-07-13 21:09:39 -07:00
Paul Eggert
b1ada33b5d Non-nil orig_filename in insert-file-contents
* src/fileio.c (Finsert_file_contents): Don’t let orig_filename be
nil, as that might mess up later diagnostics.
2025-07-13 21:09:39 -07:00
Paul Eggert
6a9dbed40c 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.
2025-07-13 21:09:39 -07:00
Paul Eggert
6d09a339ce 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.
2025-07-13 21:09:39 -07:00
Paul Eggert
0a3c8a4df3 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.
2025-07-13 21:09:38 -07:00
Paul Eggert
ffd65be227 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.
2025-07-13 21:09:38 -07:00
Paul Eggert
ae30a61c74 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.
2025-07-13 21:09:38 -07:00
Paul Eggert
490311f86a 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.
2025-07-13 21:09:38 -07:00
Pip Cet
fce86c7e95 Avoid crashes when profiling multi-threaded Lisp (bug#76970)
* src/eval.c (backtrace_p): Check 'current_thread' before
dereferencing it.
2025-07-12 10:24:11 +00: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
Alan Third
9f5d17cd72 Move CSS into the SVG wrapper
This allows CSS to be used with librsvg < 2.48.

* src/image.c (svg_load_image): Move CSS construction and include
"color".  Also append the CSS passed in by the user rather than
replacing it.
2025-07-10 17:54:33 +01:00
Alan Third
4d145d08da Change foreground color handling for SVG files (bug#77841)
* etc/images/checkbox-mixed.svg:
* etc/images/checked.svg:
* etc/images/conceal.svg:
* etc/images/down.svg:
* etc/images/gnus/gnus-pointer.svg:
* etc/images/left.svg:
* etc/images/outline-close.svg:
* etc/images/outline-open.svg:
* etc/images/radio-checked.svg:
* etc/images/radio-mixed.svg:
* etc/images/radio.svg:
* etc/images/reveal.svg:
* etc/images/right.svg:
* etc/images/symbols/check-mark_16.svg:
* etc/images/symbols/chevron_down_16.svg:
* etc/images/symbols/chevron_left_16.svg:
* etc/images/symbols/chevron_right_16.svg:
* etc/images/symbols/chevron_up_16.svg:
* etc/images/symbols/cross_16.svg:
* etc/images/symbols/cross_circle_16.svg:
* etc/images/symbols/cross_circle_fill_16.svg:
* etc/images/symbols/dot_large_16.svg:
* etc/images/symbols/dot_medium_16.svg:
* etc/images/symbols/dot_small_16.svg:
* etc/images/symbols/heart_16.svg:
* etc/images/symbols/heart_fill_16.svg:
* etc/images/symbols/heart_half_16.svg:
* etc/images/symbols/menu_16.svg:
* etc/images/symbols/minus_16.svg:
* etc/images/symbols/minus_circle_16.svg:
* etc/images/symbols/minus_circle_fill_16.svg:
* etc/images/symbols/plus_16.svg:
* etc/images/symbols/plus_circle_16.svg:
* etc/images/symbols/plus_circle_fill_16.svg:
* etc/images/symbols/star_16.svg:
* etc/images/symbols/star_fill_16.svg:
* etc/images/symbols/star_half_16.svg:
* etc/images/unchecked.svg:
* etc/images/up.svg: Set 'fill' color to 'currentcolor'.
* etc/images/symbols/README: Add explanation of change to instructions.
* src/image.c: Remove setting of the 'fill' color in the default SVG
stylesheet.
2025-07-10 17:54:33 +01:00
Eli Zaretskii
b51b01f682 ; * src/fileio.c: Remove version from commentary (bug#78983). 2025-07-10 16:08:29 +03:00
Mattias Engdegård
b83f2d16fb Unintern Qget_file_char and Qget_emacs_mule_file_char
These symbols are used in the reader as special constants and can't be
passed from Lisp (Emacs would crash).

* src/lread.c (syms_of_lread): Unintern.
(init_source): Use BASE_EQ.
2025-07-10 13:45:50 +02:00
Mattias Engdegård
cd3727f7e0 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.
2025-07-10 10:24:58 +02:00
Mattias Engdegård
f605e6ede3 ; * src/lread.c (read_internal_start): Simplify.
This removes code that became dead in the non-recursive reader reform.
2025-07-09 19:23:47 +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
Pip Cet
a76506f131 Fix crashes when "emacsclient -nw" frames are suspended (bug#78980)
* src/frame.c (frame_redisplay_p): Start loop with 'f', not its parent
frame.  Simplify return expression.
2025-07-09 14:09:53 +00:00