From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: remove-hook. Date: Wed, 08 Oct 2003 00:52:06 -0400 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: Reply-To: rms@gnu.org NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1065589021 27912 80.91.224.253 (8 Oct 2003 04:57:01 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 8 Oct 2003 04:57:01 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed Oct 08 06:56:59 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A76Nf-0006sf-00 for ; Wed, 08 Oct 2003 06:56:59 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1A76Nf-0004MB-00 for ; Wed, 08 Oct 2003 06:56:59 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1A76NL-0004DE-Tf for emacs-devel@quimby.gnus.org; Wed, 08 Oct 2003 00:56:39 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1A76Lq-0002tf-2n for emacs-devel@gnu.org; Wed, 08 Oct 2003 00:55:06 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1A76LS-0002HW-1W for emacs-devel@gnu.org; Wed, 08 Oct 2003 00:54:57 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1A76LK-0001xk-Az for emacs-devel@gnu.org; Wed, 08 Oct 2003 00:54:34 -0400 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.24) id 1A76Iw-0002zT-6l; Wed, 08 Oct 2003 00:52:06 -0400 Original-To: Lute Kamstra In-reply-to: (message from Lute Kamstra on Tue, 07 Oct 2003 15:25:36 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:17001 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:17001 | 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)) (kill-local-variable hook) (set hook hook-value))))))