diff --git a/core/core-lib.el b/core/core-lib.el index c1309672d..f5da5a23a 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -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)