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:37:48 -0800 Message-ID: <87r0j3hcir.fsf@stebalien.com> References: <87r0j42353.fsf@stebalien.com> <83a5ps6a5e.fsf@gnu.org> <87r0j491mx.fsf@stebalien.com> <837ckw5gug.fsf@gnu.org> 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="37861"; mail-complaints-to="usenet@ciao.gmane.io" To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 05 22:44:24 2024 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 1rLrzL-0009eq-16 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 Jan 2024 22:44:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLryz-0006gP-5E; Fri, 05 Jan 2024 16:44:01 -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 1rLryw-0006fu-KP for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2024 16:43:58 -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 1rLryw-0005tt-CL for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2024 16:43:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rLrz0-0004d9-25 for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2024 16:44: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: Fri, 05 Jan 2024 21:44: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.170449104017784 (code B ref 68114); Fri, 05 Jan 2024 21:44:02 +0000 Original-Received: (at 68114) by debbugs.gnu.org; 5 Jan 2024 21:44:00 +0000 Original-Received: from localhost ([127.0.0.1]:58080 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rLryy-0004ck-53 for submit@debbugs.gnu.org; Fri, 05 Jan 2024 16:44:00 -0500 Original-Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:48787) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rLryt-0004cU-SJ for 68114@debbugs.gnu.org; Fri, 05 Jan 2024 16:43:59 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.west.internal (Postfix) with ESMTP id BBC3F3200AD7 for <68114@debbugs.gnu.org>; Fri, 5 Jan 2024 16:43:44 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 05 Jan 2024 16:43:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stebalien.com; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to :resent-date:resent-from:resent-message-id:resent-to:subject :subject:to:to; s=fm1; t=1704491024; x=1704577424; bh=au0JhpIJiq 8DNIgDnjH75Ha1dLjKlk/tCEXA5F94Zzw=; b=e7TcGHT8XxRbzNX8i1LsHQWqaa lCvgMM5aGjwjyQNWC4mb/59ujvHLsGiQsYof/KeQvVyAlmNtZ0u7sPzthe8tduI1 lh41R0qIYVBUblTmRuhJ+Mu6iukAVR7ln2Vmx4kiD9JlLvfTS6vIin+l6Mkj/0zv zdwNATi7j/GAbY+X1ua1KSK5BrIgEvS0OjTYvBMnHWi+xaCIRFd6fOyHKf1b78N0 O1CgXVe6GinI9yx4IAgA0iGY4800oouwwNhOmcuU8w6MdVlvoNHFkA6M2PYaVaUb 4wknyhNuScHwawHtwKdGugPPLVsac+SgXDFnLPf5vqgewccfhHZ3AJuwzQ4w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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:resent-date :resent-from:resent-message-id:resent-to:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1704491024; x=1704577424; bh=au0JhpIJiq8DNIgDnjH75Ha1dLjK lk/tCEXA5F94Zzw=; b=BQiO8gnqijDRw6rh1R3PDsJRmRk2H/LAki2QPzwAjwwR 19iHjTIS/rmaKU9eO4gqbd1CpkHTRYxflcWjjwCAp0RKEX6DymicwJgQqdmG4jML uI65yukaZ8EKzhpnVh11gvXxe0NVUS4f/fQXgrs5PR0W9U095WZHw7FSSgRsc38Q fMXOH/rCajd7pWG7V2WrnTR6KSdT1kB9QkvjuSJreLFkCRT/Sp4WJ2HkUGKWVMn0 TmkGlJjpIo2l8c3tMDMYUVsORZMoPaKKvfLKCO/R9hR8UqvwA6nTo+oxw0rVhgBD dJ1yuR3l6qOnAIXuB/fhwaF8yY5EM3kc90Lwses6xA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdegledgudeglecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffujghffffkgggtsehmtderredttddtnecuhfhrohhmpefuthgvvhgv nhcutehllhgvnhcuoehsthgvvhgvnhesshhtvggsrghlihgvnhdrtghomheqnecuggftrf grthhtvghrnhepudffgffhfeehgedtffeuudejkeduleekieeufeegvefhueffhfehhfef vedvjefgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epshhtvghvvghnsehsthgvsggrlhhivghnrdgtohhm X-ME-Proxy: Feedback-ID: ie8a146a7:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for <68114@debbugs.gnu.org>; Fri, 5 Jan 2024 16:43:43 -0500 (EST) Resent-To: 68114@debbugs.gnu.org Resent-From: Steven Allen Resent-Date: Fri, 05 Jan 2024 13:43:42 -0800 Resent-Message-ID: <87wmsn8nht.fsf@stebalien.com> In-Reply-To: <837ckw5gug.fsf@gnu.org> 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:277418 Archived-At: --=-=-= Content-Type: text/plain Ah, I responded to the previous message before seeing this one. > Please mention the bug number, since it is now known, in the log > message. Done. > Two spaces between sentences, please. Fixed in the first revision (d4a07757). > Btw, what is "the 'name' of a piece of advice"? I realize that this > text was there to begin with, but I don't think I understand what it > wants to tell me, so maybe we could clarify that. The only reference > to a "name" in the preceding text uses "name" to mean a symbol, but > then what is "the name of a piece of advice"? I guess this goes back > to define-advice, which says: > > @defmac define-advice symbol (where lambda-list &optional name depth) &rest body > This macro defines a piece of advice and adds it to the function named > @var{symbol}. The advice is an anonymous function if @var{name} is > @code{nil} or a function named @code{symbol@@name}. See > @code{advice-add} for explanation of other arguments. > > which is also a bit mysterious. Does NAME used here serve as "the > name of the piece of advice"? if so, should "@code{symbol@@name}" be > "@code{symbol@@@var{name}}" instead, i.e. "name" is not a literal > string but the reference to NAME? So, those two names are actually different. The 'name' in referenced in the `advice-remove` documentation is the 'name in the advice's 'props' alist. The 'name' specified in `define-advice` is _not_ added to this alist and is only used in the advice's function name. I'm happy to resolve this in a separate patch, if that's OK with you. Something like (`define-advice` documentation): Note if NAME is nil the advice is anonymous; otherwise the advice function is named `SYMBOL@NAME' and the advice is named NAME. Then actually add NAME to the properties. > I wonder whether "Remove advice from function: " would be a better > prompt. Good point, done! > And here I wonder whether "Advice to remove: " would be a better > prompt. Also done. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment >From c9dbd06fd6484227e46361e39c29798750d2470e 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 (Bug#67926). * 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 | 26 ++++++++++++++++++++++++++ 3 files changed, 35 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..b1d314c0796 100644 --- a/lisp/emacs-lisp/nadvice.el +++ b/lisp/emacs-lisp/nadvice.el @@ -539,6 +539,32 @@ 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 "Remove advice from 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 to remove: " 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 --=-=-=--