GNU bug report logs -
#45393
27.1; Make remove-hook (interactive
Previous Next
Reported by: Thibault Polge <thibault <at> thb.lt>
Date: Wed, 23 Dec 2020 13:23:02 UTC
Severity: normal
Tags: fixed
Found in version 27.1
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45393 in the body.
You can then email your comments to 45393 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45393
; Package
emacs
.
(Wed, 23 Dec 2020 13:23:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Thibault Polge <thibault <at> thb.lt>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 23 Dec 2020 13:23:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
This is a follow-up to a previous discussion on emacs-devel[1].
The attached patch 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.
The copyright assignment paperwork was completed on Dec, 11.
[1] See: https://lists.gnu.org/archive/html/emacs-devel/2020-11/msg00860.html
[0001-Make-remove-hook-interactive.patch (text/x-patch, inline)]
From 8175c3f1e92a53a6b9bb9e78cfb7d2cb481bf583 Mon Sep 17 00:00:00 2001
From: Thibault Polge <thibault <at> thb.lt>
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
[Message part 3 (text/plain, inline)]
Best regards,
Thibault
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45393
; Package
emacs
.
(Wed, 23 Dec 2020 16:56:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 45393 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
1. I think this is a fine idea.
For one thing, it'll help with the gotcha of
someone misguidedly using a lambda form as a
hook function (which requires using the same
form for removal). Instead of having to type
the lambda form exactly for `remove-hook', it
can be retrieved from the history.
2. Please add a space char at the end of the
"Function:" prompt.
3. The doc string should maybe start with a
description of the interactive use. I think
that's typical. And that description should
describe each arg (instead of the interactive
description just referring to the Lisp
description).
On the other hand, 90% of the uses will not
be interactive, so maybe that general rule
shouldn't be followed here?
4. I suggest doing the same for `add-hook',
and letting `remove-hook' use the last hook
added interactively as default when reading
the hook.
Attached is some quick-and-dirty code that
does that, to show what I mean. If the idea
is accepted then we can work out a patch.
When `add-hook' is used interactively (only),
the hook var and function are recorded in
vars `last-add-hook-var' and `hook-history'.
[throw-add-remove-hook.el (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45393
; Package
emacs
.
(Fri, 25 Dec 2020 05:46:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 45393 <at> debbugs.gnu.org (full text, mbox):
Thibault Polge <thibault <at> thb.lt> writes:
> The attached patch makes `remove-hook` interactive.
Looks good; applied to Emacs 28 (after some minor white-space changes to
make the lines shorter than 80 characters).
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Fri, 25 Dec 2020 05:46:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 28.1, send any further explanations to
45393 <at> debbugs.gnu.org and Thibault Polge <thibault <at> thb.lt>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Fri, 25 Dec 2020 05:46:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45393
; Package
emacs
.
(Mon, 04 Jan 2021 18:09:03 GMT)
Full text and
rfc822 format available.
Message #18 received at 45393 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> The attached patch makes `remove-hook` interactive.
>
> Looks good; applied to Emacs 28 (after some minor white-space changes to
> make the lines shorter than 80 characters).
It's difficult to use this feature without a default value.
Here's the patch that adds it:
[remove-hook-default.patch (text/x-diff, inline)]
diff --git a/lisp/subr.el b/lisp/subr.el
index 1acc3c3250..ad0c812ed3 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1749,7 +1749,11 @@ remove-hook
functions have the same representation under `princ', the first
one will be removed."
(interactive
- (let* ((hook (intern (completing-read "Hook variable: " obarray #'boundp t)))
+ (let* ((default (and (symbolp (variable-at-point))
+ (symbol-name (variable-at-point))))
+ (hook (intern (completing-read
+ (format-prompt "Hook variable" default)
+ obarray #'boundp t nil nil default)))
(local
(and
(local-variable-p hook)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45393
; Package
emacs
.
(Tue, 05 Jan 2021 08:36:02 GMT)
Full text and
rfc822 format available.
Message #21 received at 45393 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> It's difficult to use this feature without a default value.
> Here's the patch that adds it:
Sure; looks good to me.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 02 Feb 2021 12:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 55 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.