defmacro
code: byte-run.el
(defalias 'defmacro
(cons
'macro
#'(lambda (name arglist &optional docstring &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 &optional DOCSTRING DECL &rest BODY)"
;; We can't just have `decl' as an &optional argument, because we need
;; to distinguish
;; (defmacro foo (arg) (bar) nil)
;; from
;; (defmacro foo (arg) (bar)).
(let ((decls (cond
((eq (car-safe docstring) 'declare)
(prog1 (cdr docstring) (setq docstring nil)))
((and (stringp docstring)
(eq (car-safe (car body)) 'declare))
(prog1 (cdr (car body)) (setq body (cdr body)))))))
(if docstring (setq body (cons docstring body))
(if (null body) (setq body '(nil))))
;; Can't use backquote because it's not defined yet!
(let* ((fun (list 'function (cons 'lambda (cons arglist body))))
(def (list 'defalias
(list 'quote name)
(list 'cons ''macro fun)))
(declarations
(mapcar
(let ((f (cdr (assq (car x) macro-declarations-alist))))
(if f (apply (car f) name arglist (cdr x))
(macroexp-warn-and-return
(format-message
"Unknown macro property %S in %S"
(car x) name)
nil))))
decls)))
;; Refresh font-lock if this is a new macro, or it is an
;; existing macro whose 'no-font-lock-keyword declaration
;; has changed.
(if (and
;; If lisp-mode hasn't been loaded, there's no reason
;; to flush.
(fboundp 'lisp--el-font-lock-flush-elisp-buffers)
(or (not (fboundp name)) ;; new macro
(and (fboundp name) ;; existing macro
(member `(function-put ',name 'no-font-lock-keyword
',(get name 'no-font-lock-keyword))
declarations))))
(lisp--el-font-lock-flush-elisp-buffers))
(if declarations
(cons 'prog1 (cons def declarations))
def))))))