From: Eshel Yaron Date: Tue, 24 Dec 2024 17:14:00 +0000 (+0100) Subject: scope.el: Minor cleanup X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e0e279985ac8fd65b500faa5b7bff369a9e03427;p=emacs.git scope.el: Minor cleanup --- diff --git a/lisp/emacs-lisp/scope.el b/lisp/emacs-lisp/scope.el index 75ca7ef9404..4aea25b5520 100644 --- a/lisp/emacs-lisp/scope.el +++ b/lisp/emacs-lisp/scope.el @@ -485,17 +485,23 @@ Optional argument LOCAL is a local context to extend." (defvar scope-safe-macros t "Specify which macros are safe to expand. -If this is t, all macros are considered safe. Otherwise, this is +If this is t, macros are considered safe by default. Otherwise, this is a (possibly empty) list of safe macros.") +(defvar scope-unsafe-macros + '( static-if cl-eval-when eval-when-compile eval-and-compile let-when-compile + rx)) + (defun scope-safe-macro-p (macro) - (or (eq scope-safe-macros t) - (memq macro scope-safe-macros) - (get macro 'safe-macro))) + (and (not (memq macro scope-unsafe-macros)) + (or (eq scope-safe-macros t) + (memq macro scope-safe-macros) + (get macro 'safe-macro) + (trusted-content-p)))) (defvar warning-minimum-log-level) -(defun scope-1 (local form &optional top-level) +(defun scope-1 (local form) (cond ((consp form) (let* ((f (car form)) (bare (scope-sym-bare f)) @@ -617,18 +623,11 @@ a (possibly empty) list of safe macros.") ;; macros during this expansion. ;; We'll encounter them later on ;; and handle them manually. - '((static-if) (rx) (cl-eval-when) - (eval-when-compile) (eval-and-compile)) + (mapcar #'list scope-unsafe-macros) macroexpand-all-environment)) (macroexp-inhibit-compiler-macros t) (warning-minimum-log-level :emergency)) (macroexpand-1 form macroexpand-all-environment)))))))) - ;; Assume nothing about unknown top-level forms. - (top-level - (when (symbol-with-pos-p f) - (funcall scope-callback 'top-level - (symbol-with-pos-pos f) (length (symbol-name bare)) - nil))) (scope-assume-func-p (when (symbol-with-pos-p f) (funcall scope-callback 'function @@ -649,7 +648,8 @@ of `variable', `function', `block' `defun' and `defvar'; POS is the position of SYM in STREAM; LEN is SYM's length; and BINDER is the position in which SYM is bound. If SYM is itself a binding occurrence, then POS and BINDER are equal. If SYM is not lexically bound, then -BINDER is nil. +BINDER is nil. This function ignores `read-symbol-shorthands', so SYM +and LEN always correspond to the symbol as it appears in STREAM. If STREAM is nil, it defaults to the current buffer. @@ -683,7 +683,7 @@ starting with a top-level form, by inspecting HEAD at each level: (let ((scope-counter 0) (scope-callback callback) (read-symbol-shorthands nil)) - (scope-1 nil (read-positioning-symbols (or stream (current-buffer))) t))) + (scope-1 nil (read-positioning-symbols (or stream (current-buffer)))))) (provide 'scope) ;;; scope.el ends here