From 24980d168f372bcfcca2526970af6c2f5987e99c Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Wed, 10 Nov 1993 20:30:32 +0000 Subject: (remove-hook): New function, analogous to add-hook. This is now the recommended way to remove a hook that you have added. --- lisp/subr.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lisp/subr.el b/lisp/subr.el index aa15817599..02ada23bb6 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -493,6 +493,21 @@ function, it is changed to a list of functions." (nconc (symbol-value hook) (list function)) (cons function (symbol-value hook)))))) +(defun remove-hook (hook function) + "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." + (if (or (not (boundp hook)) ;unbound symbol, or + (null (symbol-value hook)) ;value is nil, or + (null function)) ;function is nil, then + nil ;Do nothing. + (let ((hook-value (symbol-value hook))) + (if (consp hook-value) + (setq hook-value (delete function hook-value)) + (if (eq hook-value function) + (setq hook-value nil))) + (set hook hook-value)))) ;;;; Specifying things to do after certain files are loaded. -- cgit v1.2.3