From: npostavs@users.sourceforge.net
To: 24122@debbugs.gnu.org
Subject: bug#24122: Fix byte-compile of interactive closures
Date: Sun, 31 Jul 2016 22:23:08 -0400 [thread overview]
Message-ID: <87invl9qib.fsf@users.sourceforge.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 233 bytes --]
Severity: minor
tags: patch
found: 24.3
found: 25.1
Running
emacs -Q -l bug-byte-compile.el
gives
bug-byte-compile.el:Warning: misplaced interactive spec: ‘(interactive)’
where bug-byte-compile.el is
[-- Attachment #2: bug demo --]
[-- Type: text/plain, Size: 124 bytes --]
;;; -*- lexical-binding: t -*-
(let ((foo--var nil))
(defun foo ()
(interactive)
foo--var))
(byte-compile 'foo)
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
The problem is that byte-compile--reify-function which puts the bindings
inside the closure bindings inside the function body as an optimization,
puts them in front of the docstring and (interactive ...) form. Here is
a fix:
[-- Attachment #4: patch --]
[-- Type: text/plain, Size: 1576 bytes --]
From 46cf05f447a7c834789c5ce8805cb5997c685c43 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
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)))))
\f
;;;###autoload
(defun byte-compile (form)
--
2.8.0
reply other threads:[~2016-08-01 2:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87invl9qib.fsf@users.sourceforge.net \
--to=npostavs@users.sourceforge.net \
--cc=24122@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.