Function: rx-define

rx-define is an autoloaded macro defined in rx.el.gz.

Signature

(rx-define NAME [(ARGS...)] RX)

Documentation

Define NAME as a global rx definition.

If the ARGS list is omitted, define NAME as an alias for the rx expression RX.

If the ARGS list is supplied, define NAME 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 global definition of NAME is overwritten with the new one. To make local rx extensions, use rx-let for rx, rx-let-eval for rx-to-string. For more details, see Info node (elisp) Extending Rx.

Other relevant functions are documented in the regexp group.

View in manual

Probably introduced at or before Emacs version 27.1.

Shortdoc

;; regexp
(and (rx-define haskell-comment (seq "--" (zero-or-more nonl)))
       (rx haskell-comment))
    => "--.*"

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/rx.el.gz
;;;###autoload
(defmacro rx-define (name &rest definition)
  "Define NAME as a global `rx' definition.
If the ARGS list is omitted, define NAME as an alias for the `rx'
expression RX.

If the ARGS list is supplied, define NAME 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 global definition of NAME is overwritten with the new one.
To make local rx extensions, use `rx-let' for `rx',
`rx-let-eval' for `rx-to-string'.
For more details, see Info node `(elisp) Extending Rx'.

\(fn NAME [(ARGS...)] RX)"
  (declare (indent defun))
  `(eval-and-compile
     (put ',name 'rx-definition ',(rx--make-binding name definition))
     ',name))