Function: rx-let-eval
rx-let-eval is an autoloaded macro defined in rx.el.gz.
Signature
(rx-let-eval BINDINGS BODY...)
Documentation
Evaluate BODY with local BINDINGS for rx-to-string.
BINDINGS, after evaluation, is a list of definitions each on the form
(NAME [(ARGS...)] RX), in effect for calls to rx-to-string
in BODY.
For bindings without an ARGS list, NAME is defined as an alias
for the rx expression RX. Where ARGS is supplied, NAME is
defined as an rx form with ARGS as argument list. The
parameters are bound from the values in the (NAME ...) form and
are substituted in RX. ARGS can contain &rest parameters,
whose values are spliced into RX where the parameter name occurs.
Any previous definitions with the same names are shadowed during
the expansion of BODY only.
For extensions when using the rx macro, use rx-let.
To make global rx extensions, use rx-define.
For more details, see Info node (elisp) Extending Rx.
Other relevant functions are documented in the regexp group.
Probably introduced at or before Emacs version 27.1.
Shortdoc
;; regexp
(rx-let-eval
'((ponder (x) (seq "Where have all the " x " gone?")))
(rx-to-string
'(ponder (or "flowers" "cars" "socks"))))
=> "\\(?:Where have all the \\(?:\\(?:car\\|flower\\|sock\\)s\\) gone\\?\\)"
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/rx.el.gz
;;;###autoload
(defmacro rx-let-eval (bindings &rest body)
"Evaluate BODY with local BINDINGS for `rx-to-string'.
BINDINGS, after evaluation, is a list of definitions each on the form
(NAME [(ARGS...)] RX), in effect for calls to `rx-to-string'
in BODY.
For bindings without an ARGS list, NAME is defined as an alias
for the `rx' expression RX. Where ARGS is supplied, NAME is
defined as an `rx' form with ARGS as argument list. The
parameters are bound from the values in the (NAME ...) form and
are substituted in RX. ARGS can contain `&rest' parameters,
whose values are spliced into RX where the parameter name occurs.
Any previous definitions with the same names are shadowed during
the expansion of BODY only.
For extensions when using the `rx' macro, use `rx-let'.
To make global rx extensions, use `rx-define'.
For more details, see Info node `(elisp) Extending Rx'.
\(fn BINDINGS BODY...)"
(declare (indent 1) (debug (form body)))
;; FIXME: this way, `rx--extend-local-defs' may need to be autoloaded.
`(let ((rx--local-definitions (rx--extend-local-defs ,bindings)))
,@body))