Function: pcase-defmacro

pcase-defmacro is an autoloaded macro defined in pcase.el.gz.

Signature

(pcase-defmacro NAME ARGS [DOC] &rest BODY...)

Documentation

Define a new kind of pcase PATTERN, by macro expansion.

Patterns of the form (NAME ...) will be expanded according to this macro.

By convention, DOC should use "EXPVAL" to stand for the result of evaluating EXP (first arg to pcase).

Probably introduced at or before Emacs version 25.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/pcase.el.gz
;;;###autoload
(defmacro pcase-defmacro (name args &rest body)
  "Define a new kind of pcase PATTERN, by macro expansion.
Patterns of the form (NAME ...) will be expanded according
to this macro.

By convention, DOC should use \"EXPVAL\" to stand
for the result of evaluating EXP (first arg to `pcase').
\n(fn NAME ARGS [DOC] &rest BODY...)"
  (declare (indent 2) (debug defun) (doc-string 3))
  ;; Add the function via `fsym', so that an autoload cookie placed
  ;; on a pcase-defmacro will cause the macro to be loaded on demand.
  (let ((fsym (intern (format "%s--pcase-macroexpander" name)))
	(decl (assq 'declare body)))
    (when decl (setq body (remove decl body)))
    `(progn
       ;; FIXME: We use `eval-and-compile' here so that the pcase macro can be
       ;; used in the same file where it's defined, but ideally, we should
       ;; handle this using something similar to `overriding-plist-environment'
       ;; but for `symbol-function' slots so compiling a file doesn't have the
       ;; side-effect of defining the function.
       (eval-and-compile
         (defun ,fsym ,args ,@body))
       (define-symbol-prop ',fsym 'edebug-form-spec ',(cadr (assq 'debug decl)))
       (define-symbol-prop ',name 'pcase-macroexpander #',fsym))))