Function: defmacro

defmacro is a macro defined in byte-run.el.gz.

Signature

(defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...)

Documentation

Define NAME as a macro.

When the macro is called, as in (NAME ARGS...), the function (lambda ARGLIST BODY...) is applied to the list ARGS... as it appears in the expression, and the result should be a form to be evaluated instead of the original. DECL is a declaration, optional, of the form (declare DECLS...) where DECLS is a list of elements of the form (PROP . VALUES). These are interpreted according to macro-declarations-alist. The return value is undefined.

View in manual

Probably introduced at or before Emacs version 1.2.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-run.el.gz
(defalias 'defmacro
  (cons
   'macro
   #'(lambda (name arglist &rest body)
       "Define NAME as a macro.
When the macro is called, as in (NAME ARGS...),
the function (lambda ARGLIST BODY...) is applied to
the list ARGS... as it appears in the expression,
and the result should be a form to be evaluated instead of the original.
DECL is a declaration, optional, of the form (declare DECLS...) where
DECLS is a list of elements of the form (PROP . VALUES).  These are
interpreted according to `macro-declarations-alist'.
The return value is undefined.

\(fn NAME ARGLIST [DOCSTRING] [DECL] BODY...)"
       (let* ((parse (byte-run--parse-body body nil))
              (docstring (nth 0 parse))
              (declare-form (nth 1 parse))
              (body (nth 3 parse))
              (warnings (nth 4 parse))
              (declarations
               (and declare-form (byte-run--parse-declarations
                                  name arglist (cdr declare-form) 'macro
                                  macro-declarations-alist))))
         (setq body (nconc warnings body))
         (setq body (nconc (cdr declarations) body))
         (if docstring
             (setq body (cons docstring body)))
         (if (null body)
             (setq body '(nil)))
         (let* ((fun (list 'function (cons 'lambda (cons arglist body))))
                (def (list 'defalias
                           (list 'quote name)
                           (list 'cons ''macro fun))))
           (if declarations
	       (cons 'prog1 (cons def (car declarations)))
	     def))))))