From: Thibault Polge Date: Fri, 25 Dec 2020 05:44:40 +0000 (+0100) Subject: Make `remove-hook' interactive X-Git-Tag: emacs-28.0.90~4582 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=174327cefa7b2982722ed5b33248cc6adc5b31bc;p=emacs.git Make `remove-hook' interactive * lisp/subr.el (remove-hook): Make `remove-hook' interactive (bug#45393). --- diff --git a/etc/NEWS b/etc/NEWS index 3a0102238ca..b65f184bc82 100644 --- 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. diff --git a/lisp/subr.el b/lisp/subr.el index 9527f7120aa..725722cbee1 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.