From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Steven Allen Newsgroups: gmane.emacs.bugs Subject: bug#68114: [PATCH] Make 'advice-remove' interactive Date: Sat, 30 Dec 2023 08:22:04 -0800 Message-ID: <87ttnzhd8z.fsf@stebalien.com> References: <87r0j42353.fsf@stebalien.com> <83a5ps6a5e.fsf@gnu.org> <87r0j491mx.fsf@stebalien.com> 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="23779"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 68114@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 30 17:23:12 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 1rJc7C-0005v7-Au for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Dec 2023 17:23:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJc75-0004Oz-5k; Sat, 30 Dec 2023 11:23:03 -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 1rJc74-0004On-4S for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 11:23:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJc73-0003BN-Rl for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 11:23:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rJc74-0007eu-E4 for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 11:23:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Steven Allen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Dec 2023 16:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68114 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68114-submit@debbugs.gnu.org id=B68114.170395333829381 (code B ref 68114); Sat, 30 Dec 2023 16:23:02 +0000 Original-Received: (at 68114) by debbugs.gnu.org; 30 Dec 2023 16:22:18 +0000 Original-Received: from localhost ([127.0.0.1]:44918 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rJc6L-0007dp-OC for submit@debbugs.gnu.org; Sat, 30 Dec 2023 11:22:18 -0500 Original-Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:53815) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rJc6I-0007db-R8 for 68114@debbugs.gnu.org; Sat, 30 Dec 2023 11:22:16 -0500 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 00CF232004AE; Sat, 30 Dec 2023 11:22:07 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 30 Dec 2023 11:22:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stebalien.com; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1703953327; x= 1704039727; bh=2PI0HRtaRk5R5+ywNO46h1/LuuajwBAvyBFraOdYUMs=; b=I octfKF5UJZmCzFVUiSxPmBvLuoEo96x5M0o5wt6AD38ktcd9c3fbGrhsTDyz7NVN WDCC53b8myHEFYRW7RW+i12KyFWUfnIcMEwzEG3H2JB0CRwNr/r/mmtGVBlGvgb1 WbbzXDGRy25/BFWOlscrWSI5ecNoR17nhAB52Xm2T+Pcu9lvrAGtmFTn7ZwUdMOA 9iXsxEDXUjzcuEy41M73HKfDTtJnLgfHTqPgp9u1uswTL+Zo8nvSAqh0umUbc9M8 RvEnf9wD9cj4v81HNevjWXCFoq2yng6HLnBjcoSkddSVIUcCpkgttiIC/xfhEjeL V5VuJCvTfFQndtM2sTlhQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1703953327; x=1704039727; bh=2PI0HRtaRk5R5+ywNO46h1/Luuaj wBAvyBFraOdYUMs=; b=3UhIlQ47oHZxReVgH5gBcE09cCkpHEWfSxuusvXovHYI KPZjlpMCTvecRBJcqaVvKa/mo+uIKgqKLway/ystMuY4HVbf29JtpmbJAcPi9a/9 ltXd1MfDlHaD7+rXpuv6iBLZZA2B5BFKIX8l3tn0OW0s4oZZ5KvBWUZ5YzclpKy4 ji8chILC2XIC/h7Ns+/Zh+WXthtILn5pnR64uiheC4K05mBVEMGThngt51XkfGbo vVJXs8z42mynSL1igK3KrO6zfb4xCLzscDUbVhZuHFycg25Lds85Ek9hOM9E33J/ j6+GhdP0US5n1KBSl027pzAH/U/0hC+ZhaHbeWwPqQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdefhedgkeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefujghffffkgggtsehmtderredttddtnecuhfhrohhmpefuthgvvhgv nhcutehllhgvnhcuoehsthgvvhgvnhesshhtvggsrghlihgvnhdrtghomheqnecuggftrf grthhtvghrnhepjedufedvieejueektddtgedugeffveejheehieeulefgfffhleffheef vefhvdegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epshhtvghvvghnsehsthgvsggrlhhivghnrdgtohhm X-ME-Proxy: Feedback-ID: ie8a146a7:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 30 Dec 2023 11:22:06 -0500 (EST) In-Reply-To: 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:277088 Archived-At: --=-=-= Content-Type: text/plain > You should include the default in the prompt using `format-prompt`. > >> + (advice-mapc (lambda (f _) (push (cons (prin1-to-string f) f) advice)) symbol) Fixed. I also: - Broke the large `completing-read` call into multiple let bindings. - Made sure that the default value was actually advised before suggesting it. > The var name `advice` suggests it holds a single piece of advice. > I'd call it `advices` instead. Fixed > Also, some advice's functions are lambda expressions (i.e. closures) > which can be rather ugly/unwieldy when printed. When code expects to > remove them, we usually provide a `name` property for them, so I suggest > that you use something like Fixed, although I noticed a few oddities (commented in the code to avoid confusing future readers). Basically 1. 'name' can be either a string or a symbol, but they're not considered the same name. 2. The same advice can be applied multiple times with different names, so I changed the code to select the advice's 'name' instead of the advice itself, if named. > I suspect you want to `require-match` in the `completing-read` call. Fixed. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment >From 130adbe7542304b2fa5dd23c23d66c275cd5bcb1 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 29 Dec 2023 09:53:05 -0800 Subject: [PATCH] Make 'advice-remove' interactive `ad-advice-remove' is already interactive, but it doesn't work with new-style advice. * lisp/emacs-lisp/nadvice.el (advice-remove): Make it interactive. * doc/lispref/functions.texi (Advising Named Functions): Document that 'advice-remove' is now an interactive command. --- doc/lispref/functions.texi | 8 +++++--- etc/NEWS | 4 ++++ lisp/emacs-lisp/nadvice.el | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index d0c8f3e90e8..6f5c1a997e2 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -2077,10 +2077,12 @@ Advising Named Functions (@pxref{Core Advising Primitives}). @end defun -@defun advice-remove symbol function +@deffn Command advice-remove symbol function Remove the advice @var{function} from the named function @var{symbol}. -@var{function} can also be the @code{name} of a piece of advice. -@end defun +@var{function} can also be the @code{name} of a piece of advice. When +called interactively, prompt for both an advised @var{function} and +the advice to remove. +@end deffn @defun advice-member-p function symbol Return non-@code{nil} if the advice @var{function} is already in the named diff --git a/etc/NEWS b/etc/NEWS index c002ec33d45..553365fc7a4 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -83,6 +83,10 @@ see the variable 'url-request-extra-headers'. * Changes in Emacs 30.1 +** 'advice-remove' is now an interactive command. +When called interactively, 'advice-remove' now prompts for an advised +function to the advice to remove. + ** Emacs now supports Unicode Standard version 15.1. ** Network Security Manager diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el index 9f2b42f5765..f2fa5f34ef8 100644 --- a/lisp/emacs-lisp/nadvice.el +++ b/lisp/emacs-lisp/nadvice.el @@ -539,6 +539,30 @@ advice-remove or an autoload and it preserves `fboundp'. Instead of the actual function to remove, FUNCTION can also be the `name' of the piece of advice." + (interactive + (let* ((pred (lambda (sym) (advice--p (advice--symbol-function sym)))) + (default (when-let* ((f (function-called-at-point)) + ((funcall pred f))) + (symbol-name f))) + (prompt (format-prompt "Advised Function" default)) + (symbol (intern (completing-read prompt obarray pred t nil nil default))) + advices) + (advice-mapc (lambda (f p) + (let ((k (or (alist-get 'name p) f))) + (push (cons + ;; "name" (string) and 'name (symbol) are + ;; considered different names so we use + ;; `prin1-to-string' even if the name is + ;; a string to distinguish between these + ;; two cases. + (prin1-to-string k) + ;; We use `k' here instead of `f' because + ;; the same advice can have multiple + ;; names. + k) + advices))) + symbol) + (list symbol (cdr (assoc-string (completing-read "Advice: " advices nil t) advices))))) (let ((f (symbol-function symbol))) (remove-function (cond ;This is `advice--symbol-function' but as a "place". ((get symbol 'advice--pending) -- 2.43.0 --=-=-=--