From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thibault Polge Newsgroups: gmane.emacs.bugs Subject: bug#45393: 27.1; Make remove-hook (interactive Date: Wed, 23 Dec 2020 14:22:27 +0100 Message-ID: <87r1ngbqss.fsf@thb.lt> 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="35734"; mail-complaints-to="usenet@ciao.gmane.io" To: 45393@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 23 14:23:34 2020 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 1ks473-0009Bs-Oi for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 23 Dec 2020 14:23:33 +0100 Original-Received: from localhost ([::1]:33286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ks472-0003S0-D6 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 23 Dec 2020 08:23:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ks46Z-0003Rt-EO for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 08:23:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ks46Y-00076r-Va for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 08:23:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ks46Y-0008K1-HZ for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 08:23:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Thibault Polge Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 23 Dec 2020 13:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45393 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.160872977231956 (code B ref -1); Wed, 23 Dec 2020 13:23:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 23 Dec 2020 13:22:52 +0000 Original-Received: from localhost ([127.0.0.1]:52323 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks46O-0008JM-Bu for submit@debbugs.gnu.org; Wed, 23 Dec 2020 08:22:52 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:55664) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ks46L-0008JD-6T for submit@debbugs.gnu.org; Wed, 23 Dec 2020 08:22:51 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ks46L-0003Q7-0k for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 08:22:49 -0500 Original-Received: from 8.mo2.mail-out.ovh.net ([188.165.52.147]:58699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ks46I-0006xv-Ha for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 08:22:48 -0500 Original-Received: from player692.ha.ovh.net (unknown [10.108.42.168]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 9B4101F405D for ; Wed, 23 Dec 2020 14:22:34 +0100 (CET) Original-Received: from thb.lt (lfbn-idf3-1-503-177.w83-114.abo.wanadoo.fr [83.114.90.177]) (Authenticated sender: thibault@thb.lt) by player692.ha.ovh.net (Postfix) with ESMTPSA id 543D919520935 for ; Wed, 23 Dec 2020 13:22:33 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-106R006dd5ed6c1-da79-4226-9b8b-9769a0a7ed6c, 273662A954AFE31D1DDA89026AB79E951850FC0F) smtp.auth=thibault@thb.lt X-OVh-ClientIp: 83.114.90.177 X-Ovh-Tracer-Id: 4943263544981047563 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedujedrvddtjedgheduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvffufffkgggtsehmtderredttddtnecuhfhrohhmpefvhhhisggruhhlthcurfholhhgvgcuoehthhhisggruhhlthesthhhsgdrlhhtqeenucggtffrrghtthgvrhhnpeekheekveejuddtheffueehteeiffdttdejheehtdehvdeuheffiedtvdejkeefveenucffohhmrghinhepghhnuhdrohhrghenucfkpheptddrtddrtddrtddpkeefrdduudegrdeltddrudejjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrheiledvrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepthhhihgsrghulhhtsehthhgsrdhlthdprhgtphhtthhopegsuhhgqdhgnhhuqdgvmhgrtghssehgnhhurdhorhhg Received-SPF: pass client-ip=188.165.52.147; envelope-from=thibault@thb.lt; helo=8.mo2.mail-out.ovh.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, 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" Xref: news.gmane.io gmane.emacs.bugs:196616 Archived-At: --=-=-= Content-Type: text/plain This is a follow-up to a previous discussion on emacs-devel[1]. The attached patch makes `remove-hook` interactive. A common use case for remove-hook is to fix your own mistakes when programming Emacs: renaming a hook function for something more expressive, moving a function to a different hook or from global to local, and so on. For these cases, it seems more natural to use the function interactively than to have to write throwaway lisp one-liners. A limitation of this approach is that since completion requires a text representation of the function to remove, if two hooks have the same representation under `princ` it will be impossible to distinguish between them. In this case, which is probably *extremely* rare (and only concerns anonymous functions), only the first one will be removed. The copyright assignment paperwork was completed on Dec, 11. [1] See: https://lists.gnu.org/archive/html/emacs-devel/2020-11/msg00860.html --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Make-remove-hook-interactive.patch >From 8175c3f1e92a53a6b9bb9e78cfb7d2cb481bf583 Mon Sep 17 00:00:00 2001 From: Thibault Polge Date: Wed, 23 Dec 2020 14:19:15 +0100 Subject: [PATCH] Make `remove-hook` interactive * lisp/subr.el: modify remove-hook to make it interactive. --- lisp/subr.el | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lisp/subr.el b/lisp/subr.el index 1fb0f9ab7e..2c8bc6a191 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1742,7 +1742,30 @@ FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the list of hooks to run in HOOK, then nothing is done. See `add-hook'. The optional third argument, LOCAL, if non-nil, says to modify -the hook's buffer-local value rather than its default value." +the hook's buffer-local value rather than its default value. + +Interactively, prompt for the various arguments (skipping local +unless HOOK has both local and global functions). If multiple +functions have the same representation under `princ', the first +one will be removed." + (interactive + (let* ((hook (intern (completing-read "Hook variable: " obarray #'boundp t))) + (local + (and + (local-variable-p hook) + (symbol-value hook) + (or (not (default-value hook)) ; No need to prompt if there's nothing global + (y-or-n-p (format "%s has a buffer-local binding, use that? " hook))))) + (fn-alist (mapcar + (lambda (x) (cons (with-output-to-string (prin1 x)) x)) + (if local (symbol-value hook) (default-value hook)))) + (function (alist-get (completing-read + (format "%s hook to remove:" + (if local "Buffer-local" "Global")) + fn-alist + nil t) + fn-alist nil nil 'string=))) + (list hook function local))) (or (boundp hook) (set hook nil)) (or (default-boundp hook) (set-default hook nil)) ;; Do nothing if LOCAL is t but this hook has no local binding. -- 2.29.2 --=-=-= Content-Type: text/plain Best regards, Thibault --=-=-=--