* lisp/emacs-lisp/cl-macs.el (cl-deftype): Support dispatch on
types that take arguments, as long as they can be used without arguments.
* lisp/emacs-lisp/cl-generic.el (cl--generic-derived-mode-specializers):
Rename from `cl--generic-derived-specializers` to clarify it's about
derived modes and not derived types.
(cl--generic-derived-mode-generalizer): Adjust accordingly and rename
from `cl--generic-derived-generalizer` for the same reason.
Ignore additional args in the tagcode function.
(cl-generic-generalizers) <derived-mode>: Adjust accordingly.
* lisp/emacs-lisp/macroexp.el (macroexp--dynamic-variable-p): Simplify.
* lisp/emacs-lisp/cl-extra.el (cl--types-of-memo): Delete var.
(cl--derived-type-specializers-memo): New var.
(cl-types-of): Delete function.
(cl--derived-type-specializers): New function.
(cl--derived-type-dispatch-list): Delete var.
(cl--derived-type-generalizer): Use the `:need-specializers` API instead.
(cl--derived-type-generalizers): Don't fill
`cl--derived-type-dispatch-list` any more.
* lisp/emacs-lisp/cl-preloaded.el (cl--derived-type-list): Delete var.
(cl--define-derived-type): Don't add type to `cl--derived-type-list`.
* test/lisp/emacs-lisp/cl-extra-tests.el (cl-types-test): Adjust.
Sometimes, the computation of the tag (or the computations of
the list of specializers corresponding to a tag) can be sped up
if we know the set of specializers we're looking for.
So we add a new API for both the TAGCODE-FUNCTION and SPECIALIZERS-FUNCTION
that lets them receive the set of specializers they need to consider (or any
information they can precompute from that), i.e. the set of specializers
handled by the same generalizer currently used by the generic function
for the the specific argument on which we're currently dispatching.
* lisp/emacs-lisp/cl-generic.el (cl-generic-define-generalizer):
Document new API.
(cl--generic-collect-specializers, cl--generic-filter-specializers)
(cl--generic--tagcode-with-specializers): New helper functions.
(cl--generic-get-dispatcher): Use them to support new API.
* lisp/emacs-lisp/bytecomp.el (byte-compile-get-constant):
No reason not to use 'assoc' to search for strings as well.
Previously we kept searching even after having found the string!
Calls to these functions were previously rewritten in terms of other
functions both in the optimiser and during codegen, for no good reason.
This also resulted in poor diagnostics: wrong-arity calls to 'atom' and
'nlistp' produced doubled but slightly-different warnings, and no
warnings at all for '/='.
Using compiler macros fixes the problems. The generated code is the same.
* lisp/emacs-lisp/bytecomp.el (byte-compile-negated)
(byte-compile-negation-optimizer): Replace with...
(bytecomp--define-negated): ...this compiler macro defining macro.
* lisp/emacs-lisp/bytecomp.el (byte-compile-cmp):
Don't assume that N-ary comparisons have been normalised, which is done
in the optimiser. Reported by Pip Cet.
Replace the use of 'elisp-scope-face(-1)' for analyzing face
specifications with 'elisp-scope-1' calls with an
appropriate OUTSPEC argument. This allows us to analyze
face specifications even when they are not passed directly
to relevant functions, but rather appear in a tail position
of a form that evaluates to a face specification.
* lisp/emacs-lisp/elisp-scope.el
(elisp-scope--match-spec-to-arg): Add new 'face' spec.
Use it instead of...
(elisp-scope-face, elisp-scope-face-1): ...these functions.
Remove them, no longer used.
* test/lisp/progmodes/elisp-mode-resources/semantic-highlighting.el:
Add test.
* lisp/emacs-lisp/inline.el (define-inline): Add `noinline` declaration.
* doc/lispref/functions.texi (Inline Functions): Mention it.
* lisp/emacs-lisp/cl-macs.el (cl--do-arglist): Avoid %s for lists in
format string.
(cl-dolist, cl-dotimes): Remove obsolete optimization.
(cl-defstruct): Use `define-inline` instead of `cl-defsubst` for accessors.
This removes the bespoke analyzer for 'let-alist'. It
required special accommodations in 'elisp-scope--symbol'
(which is otherwise very generic), and didn't bring any
concrete benefit for semantic highlighting purposes.
Instead, we rely on 'elisp-scope-1' macro-expanding
'let-alist' forms and analyzing the result.
* lisp/emacs-lisp/elisp-scope.el: Delete bespoke analyzer
definition for 'let-alist'.
(elisp-scope--current-let-alist-form): Remove, no longer used.
(elisp-scope--symbol, elisp-scope--handle-quoted): Simplify.
* lisp/emacs-lisp/elisp-scope.el: Require `cl-lib`.
[ We could instead replace the `cl-case`s with `pcase`. ]
(elisp-scope-cl-lambda-rest, elisp-scope-cl-lambda-key): Simplify.
* lisp/emacs-lisp/bytecomp.el (byte-compile--check-arity-bytecode)
(byte-compile-warn-about-unresolved-functions, byte-compile-form)
(byte-compile-free-vars-warn):
Delay checking whether a warning is enabled until we are about to emit
such a warning, since most warnings are enabled most of the time but
finding something to warn about is rare.
Some global minor modes require initialization. Those that are preloaded
currently abuse `custom-initialize-delay` for that, but it's suboptimal
and doesn't help those that aren't preloaded.
So introduce a new function to fill that need.
While at it, make `define-globalized-minor-mode` use it
automatically when useful.
* lisp/custom.el (custom-initialize-after-file-load): New function.
* lisp/tooltip.el (tooltip-mode):
* lisp/paren.el (show-paren-mode):
* lisp/rfn-eshadow.el (file-name-shadow-mode):
* lisp/epa-hook.el (auto-encryption-mode):
* lisp/minibuffer.el (minibuffer-regexp-mode, minibuffer-nonselected-mode):
* lisp/electric.el (electric-indent-mode): Use it instead of
`custom-initialize-delay` since the value does not depend on the
runtime context.
(electric-quote-mode): Don't use `custom-initialize-delay` since
the default value is nil anyway.
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Automatically add `:initialize` if needed.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): Remove `:initialize`,
now provided automatically.
* doc/lispref/customize.texi (Variable Definitions):
* doc/lispref/modes.texi (Defining Minor Modes): Document and Suggest
`custom-initialize-after-file-load` instead of `custom-initialize-delay`.
Stop trying to detect when a globalized mode enabled its
minor mode "too early". This reverts the core of commit 876daebc85
since the problem it tried to circumvent has been made almost impossible
by commit 17e26cf57e.
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Remove the `MODE-mode-name` variable, don't remember in which major
mode we enabled the minor mode, and don't disable the minor mode
before (re)enabling it.
* lisp/progmodes/elisp-mode.el
(elisp--annotate-symbol-with-help-echo): Take SYM argument
instead of DEF. Apply ':help' function partially with SYM
instead of calling it.
* lisp/emacs-lisp/elisp-scope.el: Adapt ':help' functions.
So far, 'scope-elisp-analyze-form' would disable
'read-symbol-shorthands' while reading a source form in
order to obtain the "original" length of symbols and pass
that length to the callback called for each analyzed symbol.
However, 'scope-elisp-analyze-form' could report an
incorrect length when a symbol was written with redundant
escaping (e.g. 'f\oo'). Moreover, disabling
'read-symbol-shorthands' breaks macro-expansion during
analysis, because macros may expect "expanded" symbols,
without shorthands.
In this commit we address these issues by leaving
'scope-elisp-analyze-form' enabled (so we get expended
symbols for macro-expansion) and recovering the original
length lazily in the callback, if needed, by going to the
beginning of the symbol and searching forward for its end.
* lisp/emacs-lisp/elisp-scope.el (elisp-scope--report):
Replace LEN argument with SYM, the analyzed symbol itself.
Adapt all callers.
(elisp-scope-analyze-form): Cease let-binding
'read-symbol-shorthands' to nil while reading. Wrap
analysis in 'save-excursion' when reading from current
buffer. Update docstring.
* lisp/progmodes/elisp-mode.el (elisp-local-references)
(elisp-fontify-symbol): Obtain symbol length from buffer.
* test/lisp/progmodes/elisp-mode-resources/semantic-highlighting.el:
Add test that incorporates 'read-symbol-shorthands'.
* test/lisp/progmodes/elisp-mode-tests.el (elisp-test-font-lock):
Set up 'read-symbol-shorthands' in test file.
* lisp/emacs-lisp/byte-opt.el (byte-opt--nary-comparison)
(byte-optimize-constant-args, byte-optimize-member)
(byte-optimize-append):
* lisp/emacs-lisp/bytecomp.el (byte-compile-warnings)
(byte-compile-out-toplevel):
* lisp/emacs-lisp/cconv.el (cconv-convert):
Replace various hand-written 'any' and 'all' expressions with
calls to the new functions, for readability and speed.
Implement a better fix for bug#79634.
* lisp/emacs-lisp/byte-run.el (eval-and-compile):
* lisp/emacs-lisp/bytecomp.el (byte-compile-initial-macro-environment)
<eval-and-compile>: Preserve the surrounding lexical context (the part
available during macroexpansion, i.e. which vars are dynbound).
* lisp/emacs-lisp/rx.el (<pcase> rx): Remove workaround.
* test/lisp/emacs-lisp/macroexp-tests.el
(macroexp--dynbound-eval-and-compile): New test.
Also add a few missing docstrings.
* lisp/emacs-lisp/elisp-scope.el (elisp-scope-symbol-role-p)
(elisp-scope-read-symbol-role, elisp-scope-special-variables)
(elisp-scope-let, elisp-scope-let*): Add docstring.
(elisp-scope-counter, elisp-scope-callback)
(elisp-scope-current-let-alist-form, elisp-scope-local-new)
(elisp-scope-sym-pos, elisp-scope-sym-bare)
(elisp-scope-report, elisp-scope-special-variable-p)
(elisp-scope-let-1, elisp-scope-variable)
(elisp-scope-binding, elisp-scope-symbol): Rename, replace
'elisp-scope-' prefix with 'elisp-scope--' to indicate that
these are private. Update all references.
When a global minor mode is enabled by init-value rather than by
calling the major mode function, we failed to register it in
`global-minor-modes` (bug#79518).
* lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Register
ourselves in `global-minor-modes` at top-level for global modes
with a non-nil init-value.
Also in the `modefun`, simply the code with `not` and `add-to-list`
and consolidate the local/global paths to update `*-minor-modes`.
* lisp/simple.el (global-minor-modes): Move to...
* lisp/subr.el (global-minor-modes): ...here so it's defined early enough
for `auto-compression-mode` to register itself.
Use argument specs to analyze complex widget types.
* lisp/emacs-lisp/elisp-scope.el (elisp-scope-widget-type)
(elisp-scope-widget-type-1)
(elisp-scope-widget-type-keyword-arguments)
(elisp-scope-widget-type-arguments)
(elisp-scope-widget-type-arguments-1): Delete, no longer used.
(custom-declare-variable, define-widget): Simplify analyzers.
(elisp-scope--match-spec-to-arg): Add new 'list', 'and', and
'plist-and-then' parametric specs, and add 'widget-type' as a
new recursive spec.
* test/lisp/progmodes/elisp-mode-resources/semantic-highlighting.el
Add test.
Rename a couple of faces to solidify the convention that the
face name 'elisp-foo' implies "references to foo", not "foo
definitions". For definitions we use 'elisp-deffoo' if foo is
only one word, or 'elisp-bar-baz-definition' otherwise.
* lisp/progmodes/elisp-mode.el (elisp-function-reference):
Rename to 'elisp-function'.
(elisp-macro-call): Rename to 'elisp-macro'.
(elisp-non-local-exit):
(elisp-unknown-call):
(elisp-special-form):
* lisp/emacs-lisp/elisp-scope.el:
* test/lisp/progmodes/elisp-mode-resources/semantic-highlighting.el:
Update references to renamed faces.
* lisp/progmodes/elisp-mode.el (elisp-fontify-semantically):
Fix typo in doc string.
(elisp--annotate-symbol-with-help-echo): Accept plain string
as value of ':help' symbol role property.
* lisp/emacs-lisp/elisp-scope.el: Remove unused symbol role
properties from all defined symbol roles. Use plain strings
for ':help' instead of wrapping them with 'cl-constantly'.
Cease 'require'ing 'cl-lib', no longer needed in runtime.
(elisp-scope-define-symbol-role): Update doc string.
* lisp/emacs-lisp/elisp-scope.el (elisp-scope-if-let): Fix
handling of a plain symbol as one the bindings in an
'if-let*' form, as in (if-let* (foo) 'bar).
* test/lisp/progmodes/elisp-mode-resources/semantic-highlighting.el:
Test it.
* lisp/emacs-lisp/elisp-scope.el
(elisp-scope--local-function-analyzer): New function.
(elisp-scope-flet, elisp-scope-labels)
(elisp-scope-named-let): Use it.
(elisp-scope-cl-macrolet): Check that argument is
'symbol-with-pos-p' before calling 'symbol-with-pos-pos'.