[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Wed, 08 Oct 2003 00:52:06 -0400
| The optional third argument, LOCAL, if non-nil, says to modify
| the hook's buffer-local value rather than its default value.
| This makes the hook buffer-local if needed.
When does remove-hook need to make a hook buffer-local to remove a
function from it?
I am not sure any more why it does that, or whether it is
really necessary, but that is indeed what the code does.
Perhaps the reason is to prevent it from removing a global
hook when lOCAL is non-nil.
It also deletes buffer-local values when there is no more
need for them.
Anyway, this seems like a cleaner definition overall.
But does it work right?
(defun remove-hook (hook function &optional local)
"Remove from the value of HOOK the function FUNCTION.
HOOK should be a symbol, and FUNCTION may be any valid function. If
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."
(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.
(unless (and local (not (local-variable-p hook)))
;; Detect the case where make-local-variable was used on a hook
;; and do what we used to do.
(when (and (local-variable-p hook)
(not (and (consp (symbol-value hook))
(memq t (symbol-value hook)))))
(setq local t))
(let ((hook-value (if local (symbol-value hook) (default-value hook))))
;; Remove the function, for both the list and the non-list cases.
(if (or (not (listp hook-value)) (eq (car hook-value) 'lambda))
(if (equal hook-value function) (setq hook-value nil))
(setq hook-value (delete function (copy-sequence hook-value))))
;; If the function is on the global hook, we need to shadow it locally
;;(when (and local (member function (default-value hook))
;; (not (member (cons 'not function) hook-value)))
;; (push (cons 'not function) hook-value))
;; Set the actual variable
(if (not local)
(set-default hook hook-value)
(if (equal hook-value '(t))
(set hook hook-value))))))
Re: remove-hook., Luc Teirlinck, 2003/10/07
Richard Stallman <=
- Re: remove-hook., (continued)