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