From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61179: lambda inside interactive form of around advice isn't a closure Date: Tue, 31 Jan 2023 18:33:18 -0500 Message-ID: References: <87tu082fcy.fsf@bernoul.li> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19511"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 61179@debbugs.gnu.org To: Jonas Bernoulli Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 01 00:34:29 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pN08y-0004sU-Ni for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 01 Feb 2023 00:34:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pN08k-0002gZ-Ih; Tue, 31 Jan 2023 18:34:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pN08d-0002fe-Pq for bug-gnu-emacs@gnu.org; Tue, 31 Jan 2023 18:34:08 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pN08Y-0004jw-G0 for bug-gnu-emacs@gnu.org; Tue, 31 Jan 2023 18:34:07 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pN08Y-0003UJ-3Q for bug-gnu-emacs@gnu.org; Tue, 31 Jan 2023 18:34:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 31 Jan 2023 23:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61179 X-GNU-PR-Package: emacs Original-Received: via spool by 61179-submit@debbugs.gnu.org id=B61179.167520801413373 (code B ref 61179); Tue, 31 Jan 2023 23:34:02 +0000 Original-Received: (at 61179) by debbugs.gnu.org; 31 Jan 2023 23:33:34 +0000 Original-Received: from localhost ([127.0.0.1]:55324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pN086-0003Td-A9 for submit@debbugs.gnu.org; Tue, 31 Jan 2023 18:33:34 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:29156) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pN083-0003TP-GZ for 61179@debbugs.gnu.org; Tue, 31 Jan 2023 18:33:32 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 74846442E57; Tue, 31 Jan 2023 18:33:25 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 6A6BA442E56; Tue, 31 Jan 2023 18:33:19 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1675207999; bh=QuGtqaS8gFoyk3THL2V9m6bBKU7MvLzJF1CIAPPh2xc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=pXUwkieQScTG8NzXYjV++kWhrYliAV3bcW4EcOl2BZmF+UPOvbuOIkL/slxhrcAm8 GlOv3ZpM2AbPnQ9DJmCoMXUTwGIaWFXol4G6WniCzFTyWB6Q1BlYF+GyJtDXcn8Uwt /+pSoLXOH0bK4LF8a+L3XRICuSg4Msfd/ZMn+YfgCkFct6ur4K7TiK9PSoTP2R2G8p ZiREScip9KvXL0ooHbiLHvzdA6sDxuz5srsE8lLtFHG/Ri2iIc96uPg+vi+1QXlxdn qbqAr3qtwVSqDDYFuyj67IddUVpWU1KOQixVERrkgT8nny7iX04BNlroQlc1mP7j+9 T7b5JLTnaUXPw== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 587C912127D; Tue, 31 Jan 2023 18:33:19 -0500 (EST) In-Reply-To: <87tu082fcy.fsf@bernoul.li> (Jonas Bernoulli's message of "Mon, 30 Jan 2023 16:48:13 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:254550 Archived-At: > Unfortunately this inner lambda expression is not turned into a closure > as demonstrated by this simple example: > > ;; -*- lexical-binding: t -*- > (let ((var :value)) > (lambda (fn &rest args) > (interactive > (lambda (spec) > (message "interactive: %s" var) > (advice-eval-interactive-spec spec))) > (message "body: %s" var) > (apply fn args))) Hmm... in Emacs-29, we fixed a part of this problem. E.g. (call-interactively (let ((x 42)) (lambda (f) (interactive (list (lambda () x))) (+ (funcall f) 1)))) should return 43 (even when byte-compiled). But indeed, the fix currently fails to account for such "interactive advice" :-( > Could this be changed in the next Emacs release? Even if this should > make it into 29.1 (which I doubt), it would still be very useful for me > if this could somehow be rewritten to also work in older Emacs releases. The above fix is non-trivial, I'm afraid (e.g. it relies on OClosures internally). For your above code, I think I'd try something like: (let* ((var :value) (interactive-advice (lambda (spec) (message "interactive: %s" var) (advice-eval-interactive-spec spec))) (advice-body (lambda (fn &rest args) (message "body: %s" var) (apply fn args)))) (eval `(lambda (&rest args) (interactive ,interactive-advice) (apply ',advice-body args)) t)) where the last 4 lines are "generic" and could be turned into a helper function if you end up using it several times. This should also minimize the amount of code that's hidden from the compiler by the backquote. Stefan