From 46cf05f447a7c834789c5ce8805cb5997c685c43 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 31 Jul 2016 20:46:37 -0400 Subject: [PATCH v1] Fix byte-compile of interactive closures * lisp/emacs-lisp/bytecomp.el (byte-compile--reify-function): Put bindings after docstring and `interactive' form, if any. --- lisp/emacs-lisp/bytecomp.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index dc7574e..175690a 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -2582,7 +2582,13 @@ byte-compile--reify-function (pcase-let* (((or (and `(lambda ,args . ,body) (let env nil)) `(closure ,env ,args . ,body)) fun) + (preamble nil) (renv ())) + ;; Split docstring and `interactive' form from body. + (when (stringp (car body)) + (push (pop body) preamble)) + (when (eq (car-safe (car body)) 'interactive) + (push (pop body) preamble)) ;; Turn the function's closed vars (if any) into local let bindings. (dolist (binding env) (cond @@ -2595,8 +2601,8 @@ byte-compile--reify-function ((eq binding t)) (t (push `(defvar ,binding) body)))) (if (null renv) - `(lambda ,args ,@body) - `(lambda ,args (let ,(nreverse renv) ,@body))))) + `(lambda ,args ,@preamble ,@body) + `(lambda ,args ,@preamble (let ,(nreverse renv) ,@body))))) ;;;###autoload (defun byte-compile (form) -- 2.8.0