diff options
author | Richard M. Stallman <rms@gnu.org> | 1994-09-21 05:19:43 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1994-09-21 05:19:43 +0000 |
commit | 79b32c2d4ed26e286a4e48ffa6ac210314c6d70d (patch) | |
tree | 17897afde77308dd2ff8bd6a4ef48432090d7715 /lisp/subr.el | |
parent | af797b8d6ddf6e5b6d3df811fae1219c7c8bf0f9 (diff) | |
download | emacs-79b32c2d4ed26e286a4e48ffa6ac210314c6d70d.tar.gz |
(remove-hook, add-hook): Copy existing list before modifying.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index e985125263e..6b9768e0e60 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -551,15 +551,7 @@ FUNCTION is added at the end. HOOK should be a symbol, and FUNCTION may be any valid function. If HOOK is void, it is first set to nil. If HOOK's value is a single -function, it is changed to a list of functions. - -Note: if you make a hook variable buffer-local, copy its value before -you use `add-hook' to add to it. For example, - - (make-local-variable 'foo-hook) - (if (boundp 'foo-hook) - (setq foo-hook (copy-sequence foo-hook))) - (add-hook 'foo-hook 'my-foo-function)" +function, it is changed to a list of functions." (or (boundp hook) (set hook nil)) ;; If the hook value is a single function, turn it into a list. (let ((old (symbol-value hook))) @@ -570,7 +562,7 @@ you use `add-hook' to add to it. For example, (memq function (symbol-value hook))) (set hook (if append - (nconc (symbol-value hook) (list function)) + (append (symbol-value hook) (list function)) (cons function (symbol-value hook)))))) (defun remove-hook (hook function) @@ -584,7 +576,8 @@ list of hooks to run in HOOK, then nothing is done. See `add-hook'." nil ;Do nothing. (let ((hook-value (symbol-value hook))) (if (consp hook-value) - (setq hook-value (delete function hook-value)) + (if (member function hook-value) + (setq hook-value (delete function (copy-sequence hook-value)))) (if (equal hook-value function) (setq hook-value nil))) (set hook hook-value)))) |