aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEshel Yaron2025-10-05 17:36:07 +0200
committerEshel Yaron2025-10-06 10:27:09 +0200
commit7fc85f8dec38e20a9ad32edf3ae1abd2cd79271b (patch)
treec352453335500e614f579ba4559f397437650161
parentef08bdcd6d4668746e20b184e324112118c58e03 (diff)
downloademacs-7fc85f8dec38e20a9ad32edf3ae1abd2cd79271b.tar.gz
emacs-7fc85f8dec38e20a9ad32edf3ae1abd2cd79271b.zip
; elisp-scope.el: Recognize special variable declarations
* 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.
-rw-r--r--lisp/emacs-lisp/elisp-scope.el25
-rw-r--r--lisp/progmodes/elisp-mode.el3
2 files changed, 18 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/elisp-scope.el b/lisp/emacs-lisp/elisp-scope.el
index 20efdb1b6d1..13668a687c3 100644
--- a/lisp/emacs-lisp/elisp-scope.el
+++ b/lisp/emacs-lisp/elisp-scope.el
@@ -382,6 +382,13 @@ NAME inherits properties that do not appear in PROPS from its PARENTS."
382 :imenu "Variable" 382 :imenu "Variable"
383 :namespace 'variable) 383 :namespace 'variable)
384 384
385(elisp-scope-define-symbol-role special-variable-declaration ()
386 :doc "Special variable declarations."
387 :definition 'defvar
388 :face 'elisp-special-variable-declaration
389 :help (cl-constantly "Special variable declaration")
390 :namespace 'variable)
391
385(elisp-scope-define-symbol-role defface () 392(elisp-scope-define-symbol-role defface ()
386 :doc "Face definitions." 393 :doc "Face definitions."
387 :definition 'defface 394 :definition 'defface
@@ -2529,13 +2536,17 @@ property, or if the current buffer is trusted (see `trusted-content-p')."
2529(elisp-scope-define-special-form-analyzer setq (&rest args) 2536(elisp-scope-define-special-form-analyzer setq (&rest args)
2530 (elisp-scope-setq args)) 2537 (elisp-scope-setq args))
2531 2538
2532(elisp-scope-define-special-form-analyzer defvar (&optional sym init _doc) 2539(elisp-scope-define-special-form-analyzer defvar (&rest args)
2540 (elisp-scope-report-s
2541 (car args)
2542 (if (cdr args) 'defvar 'special-variable-declaration))
2543 (elisp-scope-1 (cadr args)))
2544
2545(elisp-scope-define-special-form-analyzer defconst (&optional sym init _doc)
2533 (elisp-scope-report-s sym 'defvar) 2546 (elisp-scope-report-s sym 'defvar)
2534 (elisp-scope-1 init)) 2547 (elisp-scope-1 init))
2535 2548
2536(put 'defconst 'elisp-scope-analyzer #'elisp-scope--analyze-defvar) 2549(elisp-scope-define-special-form-analyzer condition-case (var bodyform &rest handlers)
2537
2538(defun elisp-scope-condition-case (var bodyform handlers)
2539 (let* ((bare (bare-symbol var)) 2550 (let* ((bare (bare-symbol var))
2540 (beg (when (symbol-with-pos-p var) (symbol-with-pos-pos var))) 2551 (beg (when (symbol-with-pos-p var) (symbol-with-pos-pos var)))
2541 (l (elisp-scope-local-new bare beg elisp-scope--local))) 2552 (l (elisp-scope-local-new bare beg elisp-scope--local)))
@@ -2553,12 +2564,6 @@ property, or if the current buffer is trusted (see `trusted-content-p')."
2553 (let ((elisp-scope--local l)) 2564 (let ((elisp-scope--local l))
2554 (elisp-scope-n (cdr handler) elisp-scope-output-spec))))) 2565 (elisp-scope-n (cdr handler) elisp-scope-output-spec)))))
2555 2566
2556(elisp-scope-define-special-form-analyzer condition-case (var bodyform &rest handlers)
2557 (elisp-scope-condition-case var bodyform handlers))
2558
2559(elisp-scope-define-macro-analyzer condition-case-unless-debug (var bodyform &rest handlers)
2560 (elisp-scope-condition-case var bodyform handlers))
2561
2562(elisp-scope-define-special-form-analyzer function (&optional arg) 2567(elisp-scope-define-special-form-analyzer function (&optional arg)
2563 (when arg (elisp-scope-sharpquote arg))) 2568 (when arg (elisp-scope-sharpquote arg)))
2564 2569
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index a768a0c39d6..94e3aff59c5 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -309,6 +309,9 @@ code analysis."
309(defface elisp-free-variable '((t :inherit underline)) 309(defface elisp-free-variable '((t :inherit underline))
310 "Face for highlighting free variables in Emacs Lisp code.") 310 "Face for highlighting free variables in Emacs Lisp code.")
311 311
312(defface elisp-special-variable-declaration '((t :inherit elisp-free-variable))
313 "Face for highlighting free variable declarations in Emacs Lisp code.")
314
312(defface elisp-condition '((t :foreground "red")) 315(defface elisp-condition '((t :foreground "red"))
313 "Face for highlighting `condition-case' conditions in Emacs Lisp code.") 316 "Face for highlighting `condition-case' conditions in Emacs Lisp code.")
314 317