From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#61179: lambda inside interactive form of around advice isn't a closure Date: Sun, 05 Feb 2023 00:47:58 +0100 Message-ID: <87edr58029.fsf@web.de> References: <87tu082fcy.fsf@bernoul.li> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12818"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: jonas@bernoul.li, monnier@iro.umontreal.ca To: 61179@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 05 00: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 1pOSHV-00039G-B7 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Feb 2023 00:49:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pOSHK-0001dp-4I; Sat, 04 Feb 2023 18:49:06 -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 1pOSHG-0001d8-Mv for bug-gnu-emacs@gnu.org; Sat, 04 Feb 2023 18: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 1pOSHG-0003xu-Cp for bug-gnu-emacs@gnu.org; Sat, 04 Feb 2023 18:49:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pOSHF-0001p5-Ut for bug-gnu-emacs@gnu.org; Sat, 04 Feb 2023 18:49:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Feb 2023 23:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61179 X-GNU-PR-Package: emacs X-Debbugs-Original-To: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" X-Debbugs-Original-Cc: Jonas Bernoulli , Stefan Monnier , 61179@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16755545056948 (code B ref -1); Sat, 04 Feb 2023 23:49:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Feb 2023 23:48:25 +0000 Original-Received: from localhost ([127.0.0.1]:43625 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pOSGf-0001ny-2S for submit@debbugs.gnu.org; Sat, 04 Feb 2023 18:48:25 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:36190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pOSGd-0001np-SF for submit@debbugs.gnu.org; Sat, 04 Feb 2023 18:48:24 -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 1pOSGd-000183-Ii for bug-gnu-emacs@gnu.org; Sat, 04 Feb 2023 18:48:23 -0500 Original-Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pOSGb-0003u5-Gc for bug-gnu-emacs@gnu.org; Sat, 04 Feb 2023 18:48:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1675554482; bh=uFy8gQ/r++7jOPjs3P5RMRIKDwEgIDwq7qfQZ38/cDg=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=gYvLtHMVuNjSrBXgD/pmTt2MWf71X823lW1lJf86lk9RI31eFERQTJDiFBzb8gYNA xhf8n/r/4wa7ufnNjpMjIUfXZoRHciWSFDZAxaomime4qfVvzBaqXD9vDDj4MVHwDM ZUH06SH8jLZ0BW5PFs/adVXIfWnwMgrxxtlW7FIYA3ZGKxoyi+tpXMhw3G2iLQpC/J yeJFsOW5rQPjzagaBnBjd9dh8IPWiVhFMcoHSXCZ07rsa3+QHk5zLAQpC7H2Ldzlfn bg+DL/BJwzfT0bU+aaNcduK1vzVdsIY3qakDXaNurmUG93xveIkv+NC7dh9ZhK5Qfg DgQ+vEAfSo/ow== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([84.59.210.57]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MVrbz-1pEixz2f7V-00RqIF; Sun, 05 Feb 2023 00:48:02 +0100 In-Reply-To: (Stefan Monnier via's message of "Sat, 04 Feb 2023 11:26:15 -0500") X-Provags-ID: V03:K1:OSl0cOzhVQwqVicW/OLLkJpil0NBos8hmJlY7ZhP9xxjwAnouo/ cIyAEE2mouYizUASPIiRrdNL+FXfURID7WqFZjDp5JDAXOmDaa7RNFpN+QG78OKK7VkLl2f NkuZkjwZjMGOzj5JsO3EUe7XJB6hc+s0aVrQP8JxXR+vyMSvKZL2hucgMHqnvKNufEQYBs6 oUfAUt984dNqYzD0h4s8w== UI-OutboundReport: notjunk:1;M01:P0:VNqLwjz6Vzc=;kc8TYDVhv9WCsP/FfCHCEvh6Shk S/+xDfW4LBdAldcvOehd32GKPWjtBMHnlsDgPi5wVW4dhwgd8OCchf5B35cyQU7NJLdkqJW7N +xj+eZH/PalQGtp8KFH5eDoKkYmlc4vb9haYZBYltFtLNrk9zqi9UOTb8ZjTe043xtOJC1QTM DBFu+HrsuSlzhQv93tspM+xo9sc2ABOxVXj9PzGfKe8FbWb8ZZSQamOunpWoqer7WQkqYCdNv d3osJQU/+XsXsocPdbbrIe724EgnHm4TMQAp8BkleNdsl5yZ57ACOJLVIXjPe8PEphbi8Qi8R DSuXQRuNsGJ8DkRCXE0Uebce4+6/QOxG9N58s0PMSABYRBqs0AKYcaNz7Tbw6g2J//BEJGZYT yF1e8WmKVMgf68lDyqs80PgLNtcDiIYhYzUW1mghaF7gOLInA29xvWGSDmOCzNKLgElrSmuoG eNZ3k/1lZ91UFE7l6PtVc+tUd7sOzCYzfRSM3L6/nVILFnIdTJbTG4Z43JIzfB+NP2OMSMZRB 59hEhrCgADs8+RRxv+LwbXOLgOOBZ4ZAZzRs1k8ftaVFkZEnL/JwESzGiGao8kTM9k5Xnq0zf gN6/8jq3r/W2n3PewD9BTSkR34xBdRbFee8KG3+I3ig2Q1gORKmU5QC0CP0Bk4WJymbT25l0b meVk8gVZvHHa2Fs/Jkz6h2FFFbnnNaD4os6BsQuQ6Mk6oV40hScFZLQzvNpVd5sd8HeRN+9R7 prJHJQOoEtq5kbUGWSwY+BMFN8TokES9n5DlcQ2OM+dx9BdI/zpAfy4e/Q1JVYm3ULE6HpVM Received-SPF: pass client-ip=212.227.17.12; envelope-from=michael_heerdegen@web.de; helo=mout.web.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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:254802 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > I installed a patch in `master` which should fix this problem, both for > the case where the code is interpreted and for the case where it is > byte-compiled. Very good. This seems to break some of my private code. Didn't look into your change so far. My code generates function advices with the following semantics: You specify an alternative function and a condition (as a predicate function). When the advice is enabled, whenever the function is called the predicate is first checked for a non-nil result. When non-nil, the alternative function that had been specified is called (recursive calls are bot affected however). When nil, the original function is called. I'm using this hack only in my init file for convenience, I like the semantics for this purpose. Here is a recipe for emacs -Q: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=int-lambda.el Content-Transfer-Encoding: quoted-printable ;; -*- lexical-binding: t -*- (require 'cl-lib) (defconst flag-mel-ad-run-replacement 'mel-ad-run-replacement) (defconst flag-mel-ad-run-original 'mel-ad-run-original) (defun mel-function-replacement-advice (symbol replacement &optional pred) ;; To do: Factor out the advice fun (cl-callf or pred (lambda () t)) (unless (functionp replacement) (warn "mel-replace-function: Unknown function: `%s'. Can't check for interactive form for replacement of `%s'. Please use `with-eval-after-load' or something like that." replacement symbol)) ;; The hard part is getting commands work as expected. ;; We make the interactive spec return an additional flag indicating whet= her ;; the body should run the replacement or the original definition (cl-with-gensyms (test-result origfun args old-spec) (defvar byte-compile-docstring-max-column) (let ((byte-compile-docstring-max-column 999999)) (byte-compile `(lambda (,origfun &rest ,args) ,(format "Replace with `%s' via `mel-replace-function'." (if (symbolp replacement) (symbol-name replacement) "an anonymous function")) ,@(and (commandp replacement) `((interactive (lambda (,old-spec) (let ((,test-result (funcall #',pred))) (cons (if ,test-result ',flag-mel-ad-run-replacement ',f= lag-mel-ad-run-original) (advice-eval-interactive-spec (if ,test-result ',(cadr (interactive-form replacement)) ,old-spec)))))))) (if (if (not (memq (car-safe ,args) '(,flag-mel-ad-run-replacemen= t ,flag-mel-ad-run-original))) (funcall #',pred) (eq (pop ,args) ',flag-mel-ad-run-replacement)) (cl-letf (((symbol-function ',symbol) ,origfun)) (apply #',replacement ,args)) (apply ,origfun ,args))))))) (defun test () 1) (defvar my-ad (mel-function-replacement-advice #'test #'ignore (lambda () t= ))) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Worked as I wanted until now. But with your patch installed when compiling the above snipped I get a *Compile Log* saying: | Compiling internal form(s) at Sun Feb 5 00:36:11 2023 | int-lambda.elc: Error: =E2=80=98lambda=E2=80=99 defined after use in (lam= bda (old-spec3) (let ((test-result0 (#[0 "\300\207" [t] 1]))) (cons (if tes= t-result0 'mel-ad-run-replacement 'mel-ad-run-original) (advice-eval-intera= ctive-spec (if (not test-result0) old-spec3))))) (missing =E2=80=98require= =E2=80=99 of a library file?) | int-lambda.elc: Error: =E2=80=98lambda=E2=80=99 used as function name is = invalid Who is to blame? TIA, Michael. --=-=-=--