diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-01-08 17:57:26 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-01-08 17:57:26 -0500 |
commit | 768a35279388106f83842b7e029aa4a61b142df2 (patch) | |
tree | a69c23f54e53124b8578824d090921ff326a7d3f /lisp/emacs-lisp/macroexp.el | |
parent | a31bfd594523dc06941ceb89cdbeabcd4a5d19f7 (diff) | |
download | emacs-768a35279388106f83842b7e029aa4a61b142df2.tar.gz emacs-768a35279388106f83842b7e029aa4a61b142df2.tar.bz2 emacs-768a35279388106f83842b7e029aa4a61b142df2.zip |
* lisp/emacs-lisp/macroexp.el (macroexp--fgrep): Rename from `pcase--fgrep`
* lisp/emacs-lisp/cl-generic.el (cl--generic-fgrep): Delete.
(cl--generic-lambda): Use `macroexp--pacse` instead.
* lisp/emacs-lisp/pcase.el (pcase--fgrep): Rename to `macroexp--fgrep`.
Diffstat (limited to 'lisp/emacs-lisp/macroexp.el')
-rw-r--r-- | lisp/emacs-lisp/macroexp.el | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el index 82a8cd2d777..d5fda528b4f 100644 --- a/lisp/emacs-lisp/macroexp.el +++ b/lisp/emacs-lisp/macroexp.el @@ -480,6 +480,35 @@ itself or not." v (list 'quote v))) +(defun macroexp--fgrep (bindings sexp) + "Return those of the BINDINGS which might be used in SEXP. +It is used as a poor-man's \"free variables\" test. It differs from a true +test of free variables in the following ways: +- It does not distinguish variables from functions, so it can be used + both to detect whether a given variable is used by SEXP and to + detect whether a given function is used by SEXP. +- It does not actually know ELisp syntax, so it only looks for the presence + of symbols in SEXP and can't distinguish if those symbols are truly + references to the given variable (or function). That can make the result + include bindings which actually aren't used. +- For the same reason it may cause the result to fail to include bindings + which will be used if SEXP is not yet fully macro-expanded and the + use of the binding will only be revealed by macro expansion." + (let ((res '())) + (while (and (consp sexp) bindings) + (dolist (binding (macroexp--fgrep bindings (pop sexp))) + (push binding res) + (setq bindings (remove binding bindings)))) + (if (vectorp sexp) + ;; With backquote, code can appear within vectors as well. + ;; This wouldn't be needed if we `macroexpand-all' before + ;; calling macroexp--fgrep, OTOH. + (macroexp--fgrep bindings (mapcar #'identity sexp)) + (let ((tmp (assq sexp bindings))) + (if tmp + (cons tmp res) + res))))) + ;;; Load-time macro-expansion. ;; Because macro-expansion used to be more lazy, eager macro-expansion |