Po Lu [Sun, 30 Mar 2025 02:24:45 +0000 (10:24 +0800)]
Don't obsolete the _command_ replace-buffer-contents
* lisp/subr.el (replace-buffer-contents): Don't obsolete
function. Its purpose is to serve as a command and such
obsoletion was unnecessary to begin with.
Stephen Gildea [Sat, 29 Mar 2025 23:48:58 +0000 (16:48 -0700)]
time-stamp source commentary: point to manual section
* lisp/time-stamp.el: Add an Info link in the commentary,
now that the manual has more to say.
* doc/emacs/files.texi (Time Stamps for One File): Expand one
consistent example.
Stefan Monnier [Fri, 28 Mar 2025 04:49:33 +0000 (00:49 -0400)]
Org: Use new `replace-region-contents`
* lisp/org/org-compat.el (org-replace-buffer-contents): Delete function.
(org-replace-region-contents): New function.
* lisp/org/org-src.el (org-edit-src-save, org-edit-src-exit): Use it.
Stefan Monnier [Fri, 28 Mar 2025 05:01:17 +0000 (01:01 -0400)]
Use `replace-region-contents` to replace insert+delete
* lisp/minibuffer.el (completion--replace):
* lisp/emacs-lisp/cl-lib.el (cl--set-buffer-substring):
* lisp/subr.el (replace-string-in-region):
Use `replace-region-contents` instead of insert+delete.
* lisp/help-fns.el (help-fns--signature):
Use `replace-region-contents` instead of `cl--set-buffer-substring`.
* lisp/language/japan-util.el (japanese-replace-region):
Rewrite using `replace-region-contents` and mark obsolete.
(japanese-katakana-region, japanese-hankaku-region):
Use `replace-region-contents` instead.
* lisp/progmodes/flymake-proc.el (flymake-proc--replace-region):
Rewrite using `replace-region-contents` and mark obsolete.
(flymake-proc--check-patch-master-file-buffer):
Use `replace-region-contents` instead.
Stefan Monnier [Fri, 28 Mar 2025 04:46:53 +0000 (00:46 -0400)]
(replace-region-contents): Improve and promote (bug#76313)
Swap the role of `replace-region-contents` and `replace-buffer-contents`,
so `replace-region-contents` is the main function, implemented in C,
and `replace-buffer-contents` is a mere wrapper (marked as obsolete).
Also remove the need to rely on narrowing and on describing the
new text as a function.
Finally, allow MAX-SECS==0 to require a cheap replacement, and
add an INHERIT argument.
* src/editfns.c: Include `coding.h`.
(Freplace_region_contents): Rename from `Freplace_buffer_contents`.
Change calling convention to that of `replace-region-contents`.
Add more options for the SOURCE argument. Add INHERIT argument.
Skip the costly algorithm if MAX-SECS is 0.
* src/insdel.c (replace_range): Allow NEW to be a buffer.
* lisp/subr.el (replace-buffer-contents): New implementation.
* lisp/emacs-lisp/subr-x.el (replace-region-contents): Delete.
* doc/lispref/text.texi (Replacing): Document new API for
`replace-region-contents`. Remove documentation of
`replace-buffer-contents`.
* test/src/editfns-tests.el (replace-buffer-contents-1)
(replace-buffer-contents-2, replace-buffer-contents-bug31837):
Use `replace-region-contents`.
(editfns--replace-region): Delete.
(editfns-tests--replace-region): Use `replace-region-contents`.
Adds tests for new types of SOURCE args.
Stefan Kangas [Sat, 29 Mar 2025 12:50:21 +0000 (13:50 +0100)]
Use 'hash-table-contains-p' in a few places
This replaces open coded versions of the common idiom
(not (eq (gethash key table 'missing) 'missing))
with
(hash-table-contains-p key table)
in files where we can rely on features in Emacs 31.
Stefan Kangas [Sat, 29 Mar 2025 13:59:26 +0000 (14:59 +0100)]
New function 'hash-table-contains-p'
This function tests whether a given key is present in a hash table.
Emacs Lisp has long lacked a standard way to do this, leading users to
write one of:
This idiom is error-prone (when 'missing' or 'nil' are valid values),
and it obscures intent. The new function avoids such pitfalls,
improves readability, and makes the intent explicit:
(hash-table-contains-p key table)
The name 'hash-table-contains-p' exists in other Lisp dialects (e.g.,
SRFI-125), and follows the precedent of 'seq-contains-p'. Other
alternatives considered include `hash-table-has-key-p` and
`hash-table-key-exists-p`, but none were clearly better.
This was previously discussed in 2018, and all comments were positive,
but the proposed patch (implementing it in C) was never pushed:
https://lists.gnu.org/r/emacs-devel/2018-02/msg00424.html
* lisp/subr.el (hash-table-contains-p): New function.
* lisp/emacs-lisp/shortdoc.el (hash-table):
* doc/lispref/hash.texi (Other Hash): Document the new function.
* test/lisp/subr-tests.el (hash-table-contains-p): New test.
Vincenzo Pupillo [Sat, 22 Mar 2025 11:30:30 +0000 (12:30 +0100)]
Fix compiler warnings in mhtml-ts-mode.el (bug#77017).
* lisp/textmodes/mhtml-ts-mode.el:
Added variable and function declarations to prevent compiler
warnings.
(mhtml-ts-mode): Require 'html-ts-mode' after checking that
the html parser is available.
Vincenzo Pupillo [Fri, 14 Mar 2025 20:11:22 +0000 (21:11 +0100)]
PHP should be in the PATH, either locally or remotely. (bug#76242).
* lisp/progmodes/php-ts-mode.el
(php-ts-mode-php-default-executable): Renamed from
'php-ts-mode-php-executable'.
(php-ts-mode--executable): New function that returns the absolute
filename of the PHP executable, local or remote, based on
'default-directory'.
(php-ts-mode--anchor-prev-sibling): Replaced 'when-let' with
“when-let*.”
(php-ts-mode--indent-defun): Replaced 'when-let' with
'when-let*'.
(php-ts-mode-run-php-webserver): Use the new function
(php-ts-mode-php-default-executable).
(run-php): Use the new function (php-ts-mode-php-default-executable).
This minor lets you automatically closing block comments after
typing `block-comment-start'. Thus, typing "/*" in c-mode and
its derivatives automatically inserts "*/". (Bug#77081)
* etc/NEWS: Add minor-mode item.
* lisp/electric.el
(electric-block-comment-post-self-insert-function): New function.
(electric-block-comment-mode): New minor mode definition.
Daniel Mendler [Sat, 22 Mar 2025 09:29:45 +0000 (10:29 +0100)]
New Eldoc function `eldoc-show-help-at-pt'
Show `help-at-pt' string via Eldoc as an alternative to the
`help-at-pt-display-when-idle' timer. The help-at-pt timer
competes with Eldoc for the echo area, such that the two
mechanisms do not work well together. Therefore when using
Eldoc, the setting `eldoc-help-at-pt' may be preferable.
* lisp/emacs-lisp/eldoc.el (eldoc-help-at-pt): New customization option.
(eldoc-show-help-at-pt): New Eldoc function.
(eldoc-documentation-functions): Register the new function.
* lisp/help-at-pt.el (help-at-pt-display-when-idle): Mention
`eldoc-help-at-pt' in the docstring.
* doc/emacs/help.texi: Document `eldoc-help-at-pt'.
* etc/NEWS: Announce the change. (Bug#77169)
Jens Schmidt [Sat, 8 Mar 2025 17:13:54 +0000 (18:13 +0100)]
Improve message handling on server stop
* lisp/server.el (server-stop): Use a clearer signal message if there is
an existing, external Emacs server.
(server-start): Use a different warning if one attempts to only
stop (and not restart) an external server.
(server-unload-function): Silently stop the server if unloading its
library. (Bug#76870)
Add major mode for highlighting npmrc files (Bug#77138)
* etc/NEWS: mention the new mode.
* lisp/textmodes/conf-mode.el (conf-npmrc-mode-syntax-table): New
variable.
* lisp/textmodes/conf-mode.el (conf-npmrc-mode): New major mode
derived from conf-mode for highlighting .npmrc files.
* lisp/files.el (auto-mode-alist): Associate the new mode with .npmrc
files.
Po Lu [Sat, 29 Mar 2025 06:45:38 +0000 (14:45 +0800)]
Do not redundantly dump constant forwarding objects
* src/pdumper.c (dump_fwd_int, dump_fwd_bool, dump_fwd_obj): Do
not redundantly dump constant forwarding descriptors; restrict
to dumping the objects being forwarded to.
(dump_fwd_buffer_obj): Copy from the dump file into bss rather
than load buffer forwarding descriptors from the dump file
itself.
(dump_fwd_kboard_obj): Delete function.
(dump_fwd): Don't return offset of dumped objects.
(dump_blv): Adjust correspondingly.
(dump_pre_dump_symbol): Improve documentation. Record offset of
forwarding objects in relation to `emacs_basis' rather than the
dump file.
(dump_symbol): Restore forwarding descriptors to their original
values as static variables in Emacs. This reduces the size of
dump files by an insignificant 2kb but facilitates certain kinds
of watchpoints on platforms where ASLR cannot be disabled, e.g.,
Android.
Stefan Kangas [Tue, 25 Mar 2025 22:16:11 +0000 (23:16 +0100)]
; Improve type specifier documentation
* doc/lispref/functions.texi (Declare Form): Clarify wording for
precision and consistency; note consequences of incorrect declarations.
* doc/lispref/objects.texi (Type Specifiers): Mention use by the native
compiler; tighten wording.
Stephen Gildea [Fri, 28 Mar 2025 14:04:03 +0000 (07:04 -0700)]
; Time Stamps doc: expand the explanation of the examples
* doc/emacs/files.texi (Time Stamps): Divide into three sections.
* doc/emacs/emacs.texi: Add new nodes to menu.
* lisp/time-stamp.el: Change reference to new node.
Michael Albinus [Thu, 27 Mar 2025 16:48:20 +0000 (17:48 +0100)]
Handle better changed default-directory in shell-command
* lisp/simple.el (shell-command): Kill buffer-local values of
`shell-file-name' and `shell-command-switch', there could be left
connection-local values. (Bug#76888)
Alan Mackenzie [Thu, 27 Mar 2025 10:24:48 +0000 (10:24 +0000)]
C++ Mode: Fix some indentation bugs. FIxes bug#19867
1. Fix closing paren aligning with trailing comment on line
with matching open paren.
2. Fix indentation of first identifier inside a comma separated
list aligning with the type rather than the subsequent
identifiers.
3. Fix lambda expressions inside a brace list aligning like a
single statement.
* lisp/progmodes/cc-align.el (c-lineup-arglist): Take into
account any preceding comments when lining up the arguments in
the arglist.
(c-lineup-arglist-intro-after-paren): Handle comments properly,
and don't line up the closing parenthesis with a trailing
comment on the first line.
(c-lineup-item-after-paren-at-boi): Also allow a paren to count
as being at BOI when it is preceded only by open parens on that
line.
(c-lineup-runin-statements, c-lineup-ObjC-method-call): Hanle
comments better.
* lisp/progmodes/cc-engine.el (c-forward-comments) Introduce an
optional limit parameter. Use this limit in calls from
cc-align.el and cc-mode.el.
(c-just-after-func-arglist-p): Handle the presence of a
protection keyword such as "public".
(c-at-bracelist-p): Renamed from c-inside-bracelist-p, after
dropping the accept-in-paren parameter, having removed its
functionality.
(c-looking-at-statement-block-1): New function, based on the
old c-looking-at-statement-block. Enhanced to handle C++
lambda expressions, and to return the symbol `maybe' when the
contents of a brace delimited block fail to determine whether
it is a statement block.
(c-looking-at-statement-block): Enhanced to examine the context
of a brace delimited block when the contents are ambiguous.
(c-looking-at-c++-lambda-expression): Check the character after
point is a < before calling c-forward-<>-arglist.
(c-add-stmt-syntax): Make the context more accurate by calling
c-looking-at-statement-block.
(c-guess-basic-syntax, CASE 5D.5): Replace the syntactic symbol
topmost-intro-cont with the new symbol class-field-cont,
additionally determining the position of the enclosing brace as
an extra anchor point.
(c-guess-basic-syntax, CASE 5V): New case for an identifier
following a type inside class braces.
(c-guess-basic-syntax, CASE 9): Use
c-looking-at-statement-block to detect a brace list more
accurately.
* lisp/progmodes/cc-fonts.el (c-get-fontification-context):
Rename the call to c-inside-bracelist-p to c-at-bracelist-p.
* lisp/progmodes/cc-langs.el (c-protection-kwds): Add an entry
for java-mode.
(c-stmt-block-only-keywords-regexp): Prevent this regexp also
matching a character preceding the keyword.
* /lisp/progmodes/cc-mode.el (c-before-change-include-<>)
(c-after-change-include-<>): Use the new limit argument to
c-forward-comments.
* lisp/progmodes/cc-styles.el (c-style-alist, "gnu" and "java"
styles): Change the offset for arglist-close to
c-lineup-arglist-close-under-paren.
* lisp/progmodes/cc-vars.el (c-offsets-alist): Introduce the
new syntactic symbol class-field-cont, giving it default
offset +.
* doc/misc/cc-mode.texi (Syntactic Symbols, Class Symbols):
Document the new syntactic symbol class-field-cont.
(treesit-generic-mode-list): Remove variable.
(define-treesit-generic-mode): Remove docstring text about hook
that is already added by 'define-derived-mode'.
(treesit-generic-mode): Remove command.
Eli Zaretskii [Wed, 26 Mar 2025 17:04:16 +0000 (19:04 +0200)]
Fix vertical cursor motion with wide images and line numbers
* src/xdisp.c (produce_image_glyph): When cropping an image that
exceeds the window's right edge, account for the screen estate
taken by line-number display. (Bug#77217)
Eli Zaretskii [Wed, 26 Mar 2025 12:31:41 +0000 (14:31 +0200)]
; Fix OOM kill in ert-tests
* test/lisp/emacs-lisp/ert-tests.el
(ert-test-run-tests-batch-expensive): Mark it 'unstable', as it
might run out of memory on GNU/Linux and on Windows.
Martin Rudalics [Wed, 26 Mar 2025 08:04:49 +0000 (09:04 +0100)]
Further amendments of child frame handling and documentation
* src/frame.c (frame_subsumes_p): New static function
(delete_frame): On ttys refuse to delete a frame that could be
used as surrogate minibuffer frame by surviving frames.
(store_frame_param): Make sure 'minibuffer' parameter does not
reference a deleted window. If on a tty it references a live
window, make sure its frame has the same root frame as the frame
where the parameter shall be installed. Also on ttys make sure
that storing the 'parent-frame' parameter does not assign a
surrogate minibuffer frame a different root frame than that of
any of its client frames. Further on ttys assert that making a
child a new root frame gives it the dimensions of the terminal.
(Fmouse_position_in_root_frame): Don't use XFRAME before
it's clear that FRAME is a frame.
* doc/lispref/elisp.texi (Top): Add menu for Child Frames section.
* doc/lispref/frames.texi (Buffer Parameters): Mention that
value 'child-frame' is not special for 'minibuffer' parameter on
text terminals.
(Visibility of Frames): Fix description of 'iconify-frame'.
(Raising and Lowering): 'minibuffer-auto-raise' is an option.
(Child Frames): Major rewrite using subsections. Explain new
and deviant features on text terminals - menu bar access,
reparenting, deleting, visibility and minibuffer-only child
frames.
* etc/NEWS: Remove remark that child frames cannot be
arbitrarily reparented on ttys.
Stefan Monnier [Tue, 25 Mar 2025 18:06:32 +0000 (14:06 -0400)]
bs.el: Janitorial work; most importantly use `special-mode`
* lisp/bs.el: Prefer # to quote function arguments.
(bs-mode-font-lock-keywords): Use backquote; quote face names; and use
a list of faces instead of two applications at the same spot.
(bs-sort-buffer-interns-are-last, bs-config--files-and-scratch)
(bs-configurations, bs--intern-show-never): Fix ^$-vs-\`\' confusion.
(bs-mode-map): Remove bindings made redundant by inheritance.
(bs--redisplay): Use `line-number-at-pos`.
(bs--goto-current-buffer): Use `regexp-opt`.
(bs-mode): Inherit from `special-mode`.
(bs--current-buffer, bs--up): Use `point-min`.
(bs--create-header-line): Remove redundant arg.
Stefan Monnier [Tue, 25 Mar 2025 17:43:53 +0000 (13:43 -0400)]
bookmark.el: Cosmetic changes
* lisp/bookmark.el: Prefer # to quote function arguments.
(bookmark-watch-bookmark-file): Remove redundant `:group`.
(bookmark-bmenu-mode): Let `define-derived-mode` take care of
`mode-class` property.
Philipp Stephani [Tue, 25 Mar 2025 01:56:01 +0000 (02:56 +0100)]
Mimic behavior of 'aref' when signalling out-of-range errors.
The convention used by 'aref' and friends is that for
'args-out-of-range', the error data is a list (SEQ INDEX). Use the same
convention for the vector-related module functions.
* src/emacs-module.c (check_vec_index): Use vector and index as error
data.
Philipp Stephani [Tue, 25 Mar 2025 01:50:37 +0000 (02:50 +0100)]
Don't use 'args-out-of-range' error for too-small buffers.
'args-out-of-range' means that some index argument isn't valid for a
given sequence/range, which isn't the case here. Instead, define a new
error symbol to mean "user-supplied buffer is too small." Since we
never specified nor tested which error symbol was signalled in this
case, changing it shouldn't cause severe breakages.
* src/emacs-module.c (module_buffer_too_small): New helper function.
(module_copy_string_contents, module_extract_big_integer): Use it.
(syms_of_module): Define 'buffer-too-small' error symbol.
Stefan Monnier [Mon, 24 Mar 2025 21:12:16 +0000 (17:12 -0400)]
(byte-compile-maybe-guarded): Make its code edebuggable
* lisp/emacs-lisp/bytecomp.el (byte-compile--reify-function): Hoist
subexpression out of `if`.
(byte-compile-variadic-numeric, byte-compile--cond-vars)
(byte-compile--cond-switch-prefix, byte-compile-file-form-defalias):
Obey `lexical-binding` when evaluating the code we're compiling.
(byte-compile--maybe-guarded): New function, extracted from
`byte-compile-maybe-guarded`.
(byte-compile-maybe-guarded): Use it so we can edebug the code.
Stefan Monnier [Mon, 24 Mar 2025 21:08:26 +0000 (17:08 -0400)]
(buffer-local-set-state): Optimize away unused data
* lisp/subr.el (buffer-local-set-state--get): Simplify by making it
take only the vars rather than the pairs.
(buffer-local-set-state): Adjust accordingly so we don't needlessly keep
part of the source code in the compiled code.
Sean Whitton [Mon, 24 Mar 2025 02:29:17 +0000 (10:29 +0800)]
log-edit: Don't add rear-nonsticky to font-lock-extra-managed-props
* lisp/vc/log-edit.el (log-edit-mode): Don't add rear-nonsticky
to font-lock-extra-managed-props (bug#77197). Investigated by
Paul D. Nelson <ultrano@gmail.com>. Fix due to Stefan Monnier.