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.
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/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.
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.
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'.
* lisp/emacs-lisp/elisp-scope.el (elisp-scope-1): All
special-forms should have an associated analyzer, so drop
fallback handling for unknown special-forms.
* lisp/emacs-lisp/elisp-scope.el
(elisp-scope-local-definitions): New variable. Replaces...
(elisp-scope-flet-alist, elisp-scope-macrolet-alist): these.
Removed, no longer used.
(elisp-scope-1, elisp-scope--handle-quoted): Update.
(elisp-scope-with-local-definition): New macro.
(elisp-scope-flet, elisp-scope-labels, elisp-scope-named-let)
(elisp-scope-cl-macrolet): Use it.
* lisp/emacs-lisp/elisp-scope.el (elisp-scope-flet)
(elisp-scope-labels, elisp-scope-cl-macrolet): Add argument
'outspec' and pass it down to 'elisp-scope-n'.
* lisp/emacs-lisp/elisp-scope.el
(special-variable-declaration): New symbol role.
(defvar): Update analyzer to distinguish between
declarations and definitions.
(defconst): Add a separate analyzer.
* lisp/progmodes/elisp-mode.el
(elisp-special-variable-declaration): New face.
* lisp/emacs-lisp/elisp-scope.el
(elisp-scope-add-symbol-roles-to-describe-symbol): New
autoloaded function intended for user configs, hooks
`elisp-scope-describe-symbol-role' into `describe-symbol'.
Extend the "type" system (to be renamed to "spec" in
subsequent commit) of elisp-scope.el with a plist spec.
This allows us to define a spec for the 'slots' argument of
'eieio-defclass-internal'. Also add a 'cl-type' spec,
describing the type specifications used by 'cl-typep', and
replace the 'equal' spec with a more general 'member' spec,
like we have in 'cl-typep'.
Take an Edebug spec of t as an indication that all of the
macro's arguments are evaluated, and analyze them as such.
Only do so as a fallback for macros that we cannot expand,
because expanding can lead to more accurate analysis,
e.g. with regards to the output type of the form.
Change the terminology used in elisp-scope.el to call the
symbols we use to categorizes the use of (other) symbols
"symbol roles" instead of "symbol types".
* lisp/emacs-lisp/elisp-scope.el:
* lisp/progmodes/elisp-mode.el: Change all occurrences of
"symbol type" say "role" instead.