(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))
;; 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
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.
(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