From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jonas Bernoulli Newsgroups: gmane.emacs.bugs Subject: bug#61179: lambda inside interactive form of around advice isn't a closure Date: Mon, 30 Jan 2023 16:48:13 +0100 Message-ID: <87tu082fcy.fsf@bernoul.li> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5420"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier To: 61179@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 30 16:49:19 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 1pMWPH-0001Cc-0I for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 Jan 2023 16:49:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMWP2-0000v7-0U; Mon, 30 Jan 2023 10:49:04 -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 1pMWP0-0000uh-CA for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 10:49:02 -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 1pMWP0-00027f-4C for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 10:49:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pMWOz-0007ty-ML for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 10:49:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jonas Bernoulli Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 Jan 2023 15:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 61179 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.167509370530320 (code B ref -1); Mon, 30 Jan 2023 15:49:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Jan 2023 15:48:25 +0000 Original-Received: from localhost ([127.0.0.1]:50164 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pMWOP-0007sx-2L for submit@debbugs.gnu.org; Mon, 30 Jan 2023 10:48:25 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:54932) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pMWON-0007sp-01 for submit@debbugs.gnu.org; Mon, 30 Jan 2023 10:48:23 -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 1pMWOL-00006Z-8v for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 10:48:22 -0500 Original-Received: from mail.hostpark.net ([212.243.197.30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMWOI-0001yh-Cs for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 10:48:20 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 0C79316289; Mon, 30 Jan 2023 16:48:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bernoul.li; h= content-type:content-type:mime-version:message-id:date:date :subject:subject:from:from:received:received; s=sel2011a; t= 1675093693; bh=elwky+mahFoOs3l5U4UJoUSJg+rp6gry4Vew9cUN1lw=; b=Q htDM4Pw/O+cFqsV5Lj0m6ySayxlAkxOVw143r41E7OK1NU2VQZmWOZbIYySN8N5F LzLRLxoa9BfhiPmqbf9mYL3gulFrQUWwtQ+0zVfy9shQlABI022pFMwTjMTp0Ib/ lJZDYUOtgK+UlH7qY3RdHNOrnhhh+RgQjeLzgezdIE= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Original-Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail1.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id QMDyZZq7AX8C; Mon, 30 Jan 2023 16:48:13 +0100 (CET) Original-Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id BFA821625E; Mon, 30 Jan 2023 16:48:13 +0100 (CET) Received-SPF: none client-ip=212.243.197.30; envelope-from=jonas@bernoul.li; helo=mail.hostpark.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:254447 Archived-At: A function used as an around advice may advise the advised function's interactive form, using (interactive (lambda (spec) ...)). 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))) Or if you want to observe the failure when trying to use such an advice: (defun -make-advice () (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)))) (defun -command (arg) (interactive (list (read-string ": ")))) (advice-add '-command :around (-make-advice) '((name . "-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. I have tried throwing an eval or two in there, but with limited success. This gives me an inner closure, but the outside closure does not capture the same environment it seems: (let ((var :value)) (eval `(lambda (fn &rest args) (interactive ,(lambda (spec) (message "interactive: %s" var) (advice-eval-interactive-spec spec))) (message "body: %s" var) (apply fn args)) t)) I got desperate and also tried things like: (call-interactively (let ((lex '((var . :value)))) (eval `(lambda () (interactive ,(eval '(lambda (spec) (message "interactive: %s" var) nil) lex)) (message "body: %s" var)) lex))) Thanks for your help! Jonas