Commit graph

9806 commits

Author SHA1 Message Date
Andrea Corallo
468f3f1cb4 (disassemble): Fix case of (byte-code ...) argument
* lisp/emacs-lisp/disass.el (disassemble): Handle (byte-code ...) here..
(disassemble-internal): ...instead of here.
(disassemble-1): Adjust text to reflect the existence of other
compiled functions.
2024-05-01 14:14:01 -04:00
Basil L. Contovounesios
65fa47e3fa Assume match before calling help-xref-button
help-xref-button fails if not preceded by a valid match, so a
preceding unconditional search should not be allowed to fail
silently.

* lisp/emacs-lisp/ert.el (ert-describe-test):
* lisp/help-fns.el (help-fns--compiler-macro)
(help-fns-function-description-header, describe-variable)
(help-fns--customize-variable, describe-face)
(help-fns--face-attributes, describe-keymap): Let unconditional
re-search-backward before help-xref-button fail early, as that would
indicate a logic bug, and the backtrace would more accurately point
to the actual source of the mistake.
2024-05-01 12:38:51 +02:00
Mattias Engdegård
c15d67ecfc * lisp/emacs-lisp/bytecomp.el (byte-compile-make-closure): Simplify. 2024-04-30 16:22:48 +02:00
Mattias Engdegård
c3c2e3b4d3 * lisp/emacs-lisp/bytecomp.el (byte-compile-lambda): Simplify.
Remove the add-lambda argument.  All callers adapted.
2024-04-30 16:20:45 +02:00
Mattias Engdegård
3000edc617 Use the nthcdr byte-op for drop, and raise open-code limit
* lisp/emacs-lisp/byte-opt.el (byte-optimize-nthcdr):
Open-code for any integral N<5.  Always use the byte-op otherwise.
2024-04-29 22:16:08 +02:00
Stefan Monnier
ccb49acd2a (disassemble-internal): Handle new function values
* lisp/emacs-lisp/disass.el (disassemble-internal): Fix the
`interpreted-function` case.
2024-04-29 13:47:15 -04:00
Stefan Monnier
7cf767ef54 (byte-compile): Fix interaction with old advice.el
* lisp/emacs-lisp/bytecomp.el (byte-compile): Handle symbols whose
function "value" is a bare lambda expression (bug#70368).
2024-04-29 13:14:31 -04:00
Mattias Engdegård
3be382311f Declare the variable rx-constituents obsolete.
It has been effectively obsolete since Emacs 27, when the modern
extension mechanism was introduced.

* lisp/emacs-lisp/rx.el (rx-constituents): Make obsolete.
* test/lisp/emacs-lisp/rx-tests.el (rx-constituents): Suppress warning.
* etc/NEWS: Announce.
2024-04-29 14:29:53 +02:00
Stefan Monnier
f2bccae22b Use a dedicated type to represent interpreted-function values
Change `function` so that when evaluating #'(lambda ...)
we return an object of type `interpreted-function` rather than
a list starting with one of `lambda` or `closure`.
The new type reuses the existing PVEC_CLOSURE (nee PVEC_COMPILED)
tag and tries to align the corresponding elements:

- the arglist, the docstring, and the interactive-form go in the
  same slots as for byte-code functions.
- the body of the function goes in the slot used for the bytecode string.
- the lexical context goes in the slot used for the constants of
  bytecoded functions.

The first point above means that `help-function-arglist`,
`documentation`, and `interactive-form`s don't need to
distinguish interpreted and bytecode functions any more.

Main benefits of the change:

- We can now reliably distinguish a list from a function value.
- `cl-defmethod` can dispatch on `interactive-function` and `closure`.
  Dispatch on `function` also works now for interpreted functions but still
  won't work for functions represented as lists or as symbols, of course.
- Function values are now self-evaluating.  That was alrready the case
  when byte-compiled, but not when interpreted since
  (eval '(closure ...)) signals a void-function error.
  That also avoids false-positive warnings about "don't quote your lambdas"
  when doing things like `(mapcar ',func ...)`.

* src/eval.c (Fmake_interpreted_closure): New function.
(Ffunction): Use it and change calling convention of
`Vinternal_make_interpreted_closure_function`.
(FUNCTIONP, Fcommandp, eval_sub, funcall_general, funcall_lambda)
(Ffunc_arity, lambda_arity): Simplify.
(funcall_lambda): Adjust to new representation.
(syms_of_eval): `defsubr` the new function.  Remove definition of `Qclosure`.

* lisp/emacs-lisp/cconv.el (cconv-make-interpreted-closure):
Change calling convention and use `make-interpreted-closure`.

* src/data.c (Fcl_type_of): Distinguish `byte-code-function`s from
`interpreted-function`s.
(Fclosurep, finterpreted_function_p): New functions.
(Fbyte_code_function_p): Don't be confused by `interpreted-function`s.
(Finteractive_form, Fcommand_modes): Simplify.
(syms_of_data): Define new type symbols and `defsubr` the two
new functions.

* lisp/emacs-lisp/cl-print.el (cl-print-object) <interpreted-function>:
New method.

* lisp/emacs-lisp/oclosure.el (oclosure): Refine the parent
to be `closure`.
(oclosure--fix-type, oclosure-type): Simplify.
(oclosure--copy, oclosure--get, oclosure--set): Adjust to
new representation.

* src/callint.c (Fcall_interactively): Adjust to new representation.

* src/lread.c (bytecode_from_rev_list):

* lisp/simple.el (function-documentation):
* lisp/help.el (help-function-arglist): Remove the old `closure` case
and adjust the byte-code case so it handles `interpreted-function`s.

* lisp/emacs-lisp/cl-preloaded.el (closure): New type.
(byte-code-function): Add it as a parent.
(interpreted-function): Adjust parent (the type itself was already
added earlier by accident).

* lisp/emacs-lisp/bytecomp.el (byte-compile--reify-function): Adjust to
new representation.
(byte-compile): Use `interpreted-function-p`.

* lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand): Adjust to
new representation.
(side-effect-free-fns): Add `interpreted-function-p` and `closurep`.

* src/profiler.c (trace_hash, ffunction_equal): Simplify.
* lisp/profiler.el (profiler-function-equal): Simplify.

* lisp/emacs-lisp/nadvice.el (advice--interactive-form-1):
Use `interpreted-function-p`; adjust to new representation; and take
advantage of the fact that function values are now self-evaluating.

* lisp/emacs-lisp/lisp-mode.el (closure):
Remove `lisp-indent-function` property.

* lisp/emacs-lisp/disass.el (disassemble-internal): Adjust to
new representation.
* lisp/emacs-lisp/edebug.el (edebug--strip-instrumentation):
Use `interpreted-function-p`.
* lisp/emacs-lisp/comp-common.el (comp-known-type-specifiers):
Add `closurep` and `interpreted-function-p`.

* test/lisp/help-fns-tests.el (help-fns-test-lisp-defun): Adjust to
more precise type info in `describe-function`.
* test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d--render-entries):
Use `interpreted-function-p`.
* test/lisp/emacs-lisp/macroexp-resources/vk.el (vk-f4, vk-f5):
Don't hardcode function values.

* doc/lispref/functions.texi (Anonymous Functions): Don't suggest that
function values are lists.  Reword "self-quoting" to reflect the
fact that #' doesn't return the exact same object.  Update examples
with the new shape of the return value.

* doc/lispref/variables.texi (Lexical Binding):
* doc/lispref/lists.texi (Rearrangement):
* doc/lispref/control.texi (Handling Errors): Update examples to reflect
new representation of function values.
2024-04-28 11:58:12 -04:00
Eshel Yaron
f5439a9291
Refine the Custom type of generated '*-modes' options
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Refine the Custom type of the '*-modes' option, generated when
this macro is given a ':predicate' argument.  (Bug#70589)
2024-04-27 17:18:31 +02:00
Eli Zaretskii
a7d51085cf Improve documentation of 'package-enable-at-startup'
* doc/emacs/package.texi (Package Installation): Clarify how to
customize 'package-enable-at-startup'.

* lisp/emacs-lisp/package.el (package-enable-at-startup): Add note
about customization.  (Bug#70402)
2024-04-27 11:52:30 +03:00
Philip Kaludercic
758fe9b670 Always update VC packages from a vc-dir buffer
* lisp/emacs-lisp/package-vc.el (vc-dir-prepare-status-buffer):
Add a declaration.
(package-vc-upgrade): Prepare a dummy vc-dir buffer to ensure
that 'vc-pull' (or rather 'vc-deduce-fileset') can correctly
infer the VC backend to use.  (bug#70526)
2024-04-26 08:21:37 +02:00
Mattias Engdegård
e442161f11 Better format string compilation warning
* lisp/emacs-lisp/bytecomp.el (byte-compile-format-warn):
Speed up by eliminating the temporary buffer.
Detect invalid format sequences.  Use plurals properly.
* test/lisp/emacs-lisp/bytecomp-tests.el: Update test.
2024-04-22 19:27:24 +02:00
Juri Linkov
086608876a * lisp/emacs-lisp/warnings.el (warning-display-at-bottom): New defcustom.
(display-warning): Use 'warning-display-at-bottom' to display
the warning buffer at the bottom of the screen and to scroll
to the last warning message (bug#69983).
2024-04-22 09:50:45 +03:00
Stefan Monnier
0536b96011 (backtrace--print-func-and-args): Fix (part of) bug#70436
The source of bug#70436 is that we print a value into the buffer
and then we generate its print representation a second time to
get its length to find the bounds of the thing we just printed.
Not only it's wasteful, but it risks bugs because the two
"prints" can be inconsistent with each other.

This is not a complete fix because in the non EVALD case we
still use that same broken way.

* lisp/emacs-lisp/backtrace.el (backtrace--print-func-and-args):
Don't re-print things just to get their length.
(backtrace--print-to-string): Skip a temp-buffer indirection.
2024-04-20 11:23:58 -04:00
Stefan Monnier
24ea3024ae (cl-print-object): Fix indirect cause of bug#70436
* lisp/emacs-lisp/cl-print.el (cl-print-object): Fix specializer
for the byte-code case.
2024-04-20 11:17:39 -04:00
Stefan Monnier
71d2ec7aba (track-changes--call-signal): Silence late signals
* lisp/emacs-lisp/track-changes.el (track-changes--call-signal):
Skip the call if the tracker was unregistered.
2024-04-19 22:19:00 -04:00
Augusto Stoffel
3cdd86b8af Propagate 'lexical-binding' value to pp buffers
See bug#70137.

* lisp/emacs-lisp/pp.el (pp-display-expression): Set lexical-binding to
match the value in the calling buffer.
2024-04-17 17:02:11 -04:00
Juri Linkov
4dd3288569 * lisp/emacs-lisp/icons.el (define-icon): Add 'doc-string' to 'declare'. 2024-04-17 21:01:14 +03:00
Stefan Monnier
523aca13a4 * lisp/emacs-lisp/track-changes.el: Fix trailer 2024-04-17 10:57:11 -04:00
Stefan Monnier
3660c51736 track-changes.el: Fix last change for early use
* lisp/emacs-lisp/track-changes.el (track-changes--recover-from-error):
Don't burp if there have been fewer than 20 keystrokes since Emacs start.
2024-04-17 09:04:12 -04:00
Juri Linkov
ada429c375 * lisp/emacs-lisp/lisp.el (forward-sexp-function): Set back to nil.
(forward-sexp): Revert back to checking 'forward-sexp-function'
for nil (bug#70426).
2024-04-17 09:53:02 +03:00
Stefan Monnier
a33ab7565e track-changes.el: Minor changes for version 1.0
Arrange for the library to be usable on older Emacsen, which
includes reducing the noise when `before/after-change-functions`
are badly paired or missing.
Also, since the signal function receives the distance (for `:disjoint`),
we don't need `track-changes--disjoint-threshold`: the signal
function can simply do nothing when the distance is smaller than
the threshold it wants to use.

* lisp/emacs-lisp/track-changes.el: Prepare header for ELPA.
(track-changes--tracker, track-changes--state): Don't use `:noinline`,
so as to be compatible with Emacs<27.
(track-changes-record-errors): New variable.
(track-changes--recover-from-error): Use it.  Record only the last 20
keys and the last 50 stack frames in the error log.
(track-changes--disjoint-threshold): Delete variable.
(track-changes--before): Don't use it any more.

* lisp/progmodes/eglot.el (eglot--track-changes-signal):
Coalesce disjoint changes nearer than what used to be coalesced because of
`track-changes--disjoint-threshold`.
2024-04-16 21:57:05 -04:00
Stefan Monnier
484b097909 (cl-defstruct): Improve handling of unknown options
Until now `cl-defstruct` signaled an error when encountering an
unknown option.  It's easy to code and it does the job, but it
doesn't give good location info in the compiler's output,
and it makes it more painful to use not-yet-supported options.
So just signal a warning instead.

* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Warn about unknown
options, instead of signaling an error.
2024-04-16 21:17:47 -04:00
Stefan Monnier
3ac1a7b6fe (track-changes-fetch): Fix nested use case
* lisp/emacs-lisp/track-changes.el (track-changes-fetch):
Don't presume that if there's nothing to do we're on
`track-changes--clean-trackers`.
2024-04-15 16:06:54 -04:00
Stefan Monnier
5fda398fb3 (track-changes--before): Fix bug#70396
* lisp/emacs-lisp/track-changes.el (track-changes--before):
Widen the buffer before accessing it with positions
potentially outside the beg..end region.
2024-04-15 15:53:48 -04:00
Juri Linkov
568c174135 Add 'forward-sexp-default-function' to be used by 'treesit-forward-sexp'
* lisp/emacs-lisp/lisp.el (forward-sexp-default-function):
New function with body from 'forward-sexp' (bug#68993).
(forward-sexp-function): Change the default value from nil to
'forward-sexp-default-function'.
(forward-sexp): Use either 'forward-sexp-function' or
'forward-sexp-default-function'.

* lisp/treesit.el (treesit-forward-sexp): In nodes of type 'text'
fall back to 'forward-sexp-default-function'.  Improve docstring.

* doc/lispref/positions.texi (List Motion): Fix pxref.
2024-04-14 19:22:01 +03:00
Mattias Engdegård
616af56579 ; * lisp/emacs-lisp/macroexp.el (macroexp--expand-all): less consing 2024-04-14 11:51:17 +02:00
Stefan Monnier
17e26cf57e (define-globalized-minor-mode): Require the use of run-mode-hooks
When `define-globalized-minor-mode` was introduced (Emacs-22),
`run-mode-hooks` was brand new, so we could not expect all major
modes to use it and we had to rely on brittle workarounds to try
and approximate `after-change-major-mode-hook`.

These workarounds have undesirable side effects, and (we hope)
they're not needed any more now that virtually all major modes
have been changed to use `run-mode-hooks` (or
`define-derived-mode`).

* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Rely only on `after-change-major-mode-hook`, remove the "cmhh"
[typo for the intended "cmmh", BTW] workaround.

* doc/lispref/modes.texi (Mode Hooks): Clarify the importance of
`after-change-major-mode-hook` w.r.t `define-globalized-minor-mode`.
(Defining Minor Modes): Rewrite the explanation of which buffers
are affected, including adjusting it to the fact that
`fundamental-mode` has used run `run-mode-hooks` for last 10 years.
2024-04-13 10:31:28 -04:00
Stefan Monnier
3f7e26e2be (define-globalized-minor-mode): Fix bug#58888
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode) <MODE-cmhh>:
Try and detect well-behaved modes so they're not affected by
those which require the cmhh hack.
2024-04-13 10:10:19 -04:00
Stefan Monnier
d67e08d6c3 Merge branch 'track-changes' 2024-04-13 09:44:12 -04:00
Stefan Monnier
d7a83e23d4 lisp/emacs-lisp/track-changes.el: New file (bug#70077)
This new package provides an API that is easier to use right than
our `*-change-functions` hooks.

The patch includes changes to `diff-mode.el` and `eglot.el` to
make use of this new package.

* lisp/emacs-lisp/track-changes.el: New file.
* test/lisp/emacs-lisp/track-changes-tests.el: New file.
* doc/lispref/text.texi (Tracking changes): New subsection.

* lisp/progmodes/eglot.el: Require `track-changes`.
(eglot--virtual-pos-to-lsp-position): New function.
(eglot--track-changes): New var.
(eglot--managed-mode): Use `track-changes-register` i.s.o
`after/before-change-functions` when available.
(eglot--track-changes-signal): New function, partly extracted from
`eglot--after-change`.
(eglot--after-change): Use it.
(eglot--track-changes-fetch): New function.
(eglot--signal-textDocument/didChange): Use it.

* lisp/vc/diff-mode.el: Require `track-changes`.
Also require `easy-mmode` before the `eval-when-compile`s.
(diff-unhandled-changes): Delete variable.
(diff-after-change-function): Delete function.
(diff--track-changes-function): Rename from `diff-post-command-hook`
and adjust to new calling convention.
(diff--track-changes): New variable.
(diff--track-changes-signal): New function.
(diff-mode, diff-minor-mode): Use it with `track-changes-register`.
2024-04-13 09:43:11 -04:00
Andrea Corallo
3eb462405e * lisp/emacs-lisp/comp-cstr.el (comp-cstr-type-p): Improve last change. 2024-04-10 18:45:47 +02:00
Andrea Corallo
ee03a73375 * lisp/emacs-lisp/comp-cstr.el (comp-cstr-type-p): New function. 2024-04-10 18:16:26 +02:00
Andrea Corallo
d4d8575bf0 * lisp/emacs-lisp/comp-cstr.el (comp-cstr-symbol-p): Simplify. 2024-04-10 18:16:26 +02:00
Andrea Corallo
219b98916b * lisp/emacs-lisp/comp-cstr.el (comp-cstr-fixnum-p): Fix. 2024-04-10 18:16:26 +02:00
Andrea Corallo
f471181129 * lisp/emacs-lisp/cl-macs.el (cl-typep): Add docstring. 2024-04-10 15:30:08 +02:00
Stefan Monnier
dd6b9c9426 (cl--describe-class-slots): Avoid cryptic t type
* lisp/emacs-lisp/cl-extra.el (cl--describe-class-slots): Use the empty
string for the trivial `t` type.

* lisp/emacs-lisp/cl-preloaded.el (cl-structure-class):
Fix non-existing `bool` => `boolean`.
2024-04-09 18:33:01 -04:00
Mattias Engdegård
cda5155c61 Inhibit flymake lexical cookie warning in *scratch* (bug#70068)
Add a hack to prevent flymake from complaining about a missing lexical
cookie when enabled in *scratch*.

* lisp/emacs-lisp/bytecomp.el
(bytecomp--inhibit-lexical-cookie-warning): New variable.
(byte-compile-file): Use it to gate the warning.
* lisp/progmodes/elisp-mode.el (elisp-flymake-byte-compile):
Set the inhibitor when spawning a check in lisp-interaction-mode.
2024-04-09 10:56:44 +02:00
Stefan Monnier
dc5fe95a48 (cl--describe-class): Improve based on dicussion in bug#70077
* lisp/emacs-lisp/cl-extra.el (cl--describe-class): Move docstring
after the class' slots.
(cl--describe-class-slots): Buttonize the types.
2024-04-08 13:59:58 -04:00
Stefan Monnier
9506b9392e (define-globalized-minor-mode): Fix bug#69431
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
When `after-change-major-mode-hook` runs, enable the mode only
in the current buffer and not in other pending buffers.
2024-04-08 08:18:31 -04:00
Andrea Corallo
c9d7721db6 * Make comp ignore EIEIO classes (bug#70141)
* lisp/emacs-lisp/comp-cstr.el (comp--all-classes): Ignore EIEIO classes.
2024-04-08 12:07:22 +02:00
Eli Zaretskii
5f89da1423 Merge from origin/emacs-29
46b8746b38 Fix warning-suppress for list type "warning type"
910ea5f1e5 Make object init more robust (bug#69571)
2024-04-06 11:13:34 -04:00
Mattias Engdegård
fa9791fe6a Revert "Check if lexical-binding is enabled before warning"
This reverts commit 7de192680f.
The logic is wrong (bug#70068).
2024-04-03 11:28:49 +02:00
Philip Kaludercic
7de192680f Check if lexical-binding is enabled before warning
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Suppress "file
has no `lexical-binding' directive" is the variable is non-nil,
as is the case with 'lisp-interaction-mode'.  (Bug#70068)
2024-04-03 10:52:12 +02:00
Vladimir Kazanov
3f9263f791 Fix symbol list matching regexps.
Fix symbol list matching regexp performance

Allow empty face lists, improve the face list matching regexp (see
discussion in Bug#69714) based on relint's comments, add tests:
* test/lisp/emacs-lisp/ert-font-lock-tests.el: Add tests.
* lisp/emacs-lisp/ert-font-lock.el: Fix regexps.
2024-04-01 11:13:12 +02:00
Mattias Engdegård
155462a1bd Fix mutates-arguments warning for sort
* lisp/emacs-lisp/bytecomp.el (bytecomp--sort-call-in-place-p)
(bytecomp--mutargs-nconc, bytecomp--mutargs-sort): New.
(byte-compile-form, bytecomp--actually-important-return-value-p)
(mutating-fns):
Use a slightly more extendible scheme for specifying what arguments
a function mutates.  Give `sort` special treatment.
2024-04-01 09:42:46 +02:00
Xuan Wang
46b8746b38 Fix warning-suppress for list type "warning type"
Per the documentation of 'warning-suppress-types' and the
implementation of 'warning-suppress-p', a warning type can
be either a symbol or a list of symbols.  The previous
implementation could generate wrong 'warning-suppress-types':

  old behavior:
  type              warning-suppress-types
  pkg           ->    '((pkg))                  Correct
  (pkg subtype) ->    '(((pkg subtype)))        Incorrect

Now we check whether type is a cons cell first.  (Should not
use listp here, as listp returns t for nil.)

  new behavior:
  type              warning-suppress-types
  pkg           ->    '((pkg))                Correct
  (pkg subtype) ->    '((pkg subtype))        Correct

* lisp/emacs-lisp/warnings.el (warnings-suppress): Fix saving
warning types in 'warning-suppress-types'.  (Bug#70063)

Copyright-paperwork-exempt: yes
2024-03-31 12:06:15 +03:00
Stefan Monnier
717e7edc2a * lisp/emacs-lisp/comp.el (comp--add-cond-cstrs): Consolidate 2 cases 2024-03-29 15:36:45 -04:00
Mattias Engdegård
b20866c4b3 Better sort ignored-return-value warning
* lisp/emacs-lisp/bytecomp.el (byte-compile-form)
(bytecomp--actually-important-return-value-p):
Special handling of `sort` that takes into account that it may return
an important value depending on the :in-place keyword argument.
2024-03-29 11:39:38 +01:00