]> git.eshelyaron.com Git - emacs.git/commitdiff
Make `remove-hook' interactive
authorThibault Polge <thibault@thb.lt>
Fri, 25 Dec 2020 05:44:40 +0000 (06:44 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 25 Dec 2020 05:44:40 +0000 (06:44 +0100)
* lisp/subr.el (remove-hook): Make `remove-hook' interactive
(bug#45393).

etc/NEWS
lisp/subr.el

index 3a0102238ca6769cf003f8a56b82ed4fa958239e..b65f184bc828cf33bb1cc28b3eac64a1a701abf0 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1460,6 +1460,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.
index 9527f7120aa606ae4b5b3174c455ccea605477b4..725722cbee18b6c20745527f7068e26a30e22023 100644 (file)
@@ -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.