* [PATCH] Make remove-hook interactive
@ 2020-11-18 21:09 Thibault Polge
2020-11-24 6:34 ` Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Thibault Polge @ 2020-11-18 21:09 UTC (permalink / raw)
To: emacs-devel
This 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.
---
lisp/subr.el | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 6e9f66fe97b..ac59ae15465 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1742,7 +1742,30 @@ remove-hook
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.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Make remove-hook interactive
2020-11-18 21:09 [PATCH] Make remove-hook interactive Thibault Polge
@ 2020-11-24 6:34 ` Lars Ingebrigtsen
2020-11-24 9:46 ` Thibault Polge
2020-11-24 13:23 ` Thibault Polge
0 siblings, 2 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2020-11-24 6:34 UTC (permalink / raw)
To: Thibault Polge; +Cc: emacs-devel
Thibault Polge <thibault@thb.lt> writes:
> This 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.
I think this makes sense, so I'd like to add it to Emacs 28. However,
it's more code than we can apply without having a copyright assignment
for the FSF. Would you be willing to sign such paperwork?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Make remove-hook interactive
2020-11-24 6:34 ` Lars Ingebrigtsen
@ 2020-11-24 9:46 ` Thibault Polge
2020-11-24 10:37 ` Lars Ingebrigtsen
2020-11-24 13:23 ` Thibault Polge
1 sibling, 1 reply; 6+ messages in thread
From: Thibault Polge @ 2020-11-24 9:46 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> I think this makes sense, so I'd like to add it to Emacs 28. However,
> it's more code than we can apply without having a copyright assignment
> for the FSF. Would you be willing to sign such paperwork?
Sure, could you please send me the forms?
Regards,
--
Thibault
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Make remove-hook interactive
2020-11-24 9:46 ` Thibault Polge
@ 2020-11-24 10:37 ` Lars Ingebrigtsen
0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2020-11-24 10:37 UTC (permalink / raw)
To: emacs-devel
Thibault Polge <thibault@thb.lt> writes:
> Sure, could you please send me the forms?
(Sent off-list.)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Make remove-hook interactive
2020-11-24 6:34 ` Lars Ingebrigtsen
2020-11-24 9:46 ` Thibault Polge
@ 2020-11-24 13:23 ` Thibault Polge
2020-11-25 6:15 ` Lars Ingebrigtsen
1 sibling, 1 reply; 6+ messages in thread
From: Thibault Polge @ 2020-11-24 13:23 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> Would you be willing to sign such paperwork?
Request sent. Should I let you know when the process is finished, or
will you be notified?
Best regards,
--
Thibault
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Make remove-hook interactive
2020-11-24 13:23 ` Thibault Polge
@ 2020-11-25 6:15 ` Lars Ingebrigtsen
0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2020-11-25 6:15 UTC (permalink / raw)
To: Thibault Polge; +Cc: emacs-devel
Thibault Polge <thibault@thb.lt> writes:
>> Would you be willing to sign such paperwork?
>
> Request sent. Should I let you know when the process is finished, or
> will you be notified?
We'll be notified when the process is finished, it'd be good if you
poked us, too, because it's easy to forget these things.
It's probably also a good idea to open a bug report for this, and post
the patch there. That way we're sure not to lose track of the issue.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-11-25 6:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 21:09 [PATCH] Make remove-hook interactive Thibault Polge
2020-11-24 6:34 ` Lars Ingebrigtsen
2020-11-24 9:46 ` Thibault Polge
2020-11-24 10:37 ` Lars Ingebrigtsen
2020-11-24 13:23 ` Thibault Polge
2020-11-25 6:15 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).