emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 174327c: Make `remove-hook' interactive


From: Lars Ingebrigtsen
Subject: master 174327c: Make `remove-hook' interactive
Date: Fri, 25 Dec 2020 00:44:51 -0500 (EST)

branch: master
commit 174327cefa7b2982722ed5b33248cc6adc5b31bc
Author: Thibault Polge <thibault@thb.lt>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make `remove-hook' interactive
    
    * lisp/subr.el (remove-hook): Make `remove-hook' interactive
    (bug#45393).
---
 etc/NEWS     |  3 +++
 lisp/subr.el | 27 ++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 3a01022..b65f184 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1461,6 +1461,9 @@ that makes it a valid button.
 ** Miscellaneous
 
 ---
+*** 'remove-hook' is now an interactive command.
+
+---
 *** New user option 'authinfo-hide-elements'.
 This can be set to nil to inhibit hiding passwords in .authinfo files.
 
diff --git a/lisp/subr.el b/lisp/subr.el
index 9527f71..725722c 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1742,7 +1742,32 @@ 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)
+            ;; No need to prompt if there's nothing global
+            (or (not (default-value hook))
+                (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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]