From f2588b0e900c35137488126e01d6ffe278b88210 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 16 Sep 2021 02:42:32 +0200 Subject: [PATCH] feat(lib): imply &allow-other-keys in fn! macro --- core/core-lib.el | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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)