feat(lib): imply &allow-other-keys in fn! macro

This commit is contained in:
Henrik Lissner 2021-09-16 02:42:32 +02:00
parent 0ad7874a28
commit f2588b0e90

View file

@ -215,8 +215,20 @@ See `eval-if!' for details on this macro's purpose."
(defmacro fn! (arglist &rest body)
"Returns (cl-function (lambda ARGLIST BODY...))
The closure is wrapped in `cl-function', meaning ARGLIST will accept anything
`cl-defun' will. "
`cl-defun' will. Implicitly adds `&allow-other-keys' if `&key' is present in
ARGLIST."
(declare (indent defun) (doc-string 1) (pure t) (side-effect-free t))
;; Don't complain about undeclared keys.
(when (memq '&key arglist)
(if (memq '&aux arglist)
(let (newarglist arg)
(while arglist
(setq arg (pop arglist))
(when (eq arg '&aux)
(push '&allow-other-keys newarglist))
(push arg newarglist))
(setq arglist (nreverse newarglist)))
(setq arglist (append arglist (list '&allow-other-keys)))))
`(cl-function (lambda ,arglist ,@body)))
(defmacro cmd! (&rest body)