changeset 4964:78c13f3054e5

(remove-hook): New function, analogous to add-hook. This is now the recommended way to remove a hook that you have added.
author Richard M. Stallman <rms@gnu.org>
date Wed, 10 Nov 1993 20:30:32 +0000
parents 6648ce61e9fd
children dad86ab54e36
files lisp/subr.el
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Wed Nov 10 20:12:45 1993 +0000
+++ b/lisp/subr.el	Wed Nov 10 20:30:32 1993 +0000
@@ -493,6 +493,21 @@
 	       (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.