aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-09-21 05:19:43 +0000
committerRichard M. Stallman1994-09-21 05:19:43 +0000
commitaa09b5ca24bcddd8590c9200e66bcde329c31b16 (patch)
treee2c40b39f5f10370102e52f556a7a920679851ba
parentec265841c9fb7f7eddd744d1c5384f38b314e5e6 (diff)
downloademacs-aa09b5ca24bcddd8590c9200e66bcde329c31b16.tar.gz
emacs-aa09b5ca24bcddd8590c9200e66bcde329c31b16.zip
(remove-hook, add-hook): Copy existing list before modifying.
-rw-r--r--lisp/subr.el15
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.
551 551
552HOOK should be a symbol, and FUNCTION may be any valid function. If 552HOOK should be a symbol, and FUNCTION may be any valid function. If
553HOOK is void, it is first set to nil. If HOOK's value is a single 553HOOK is void, it is first set to nil. If HOOK's value is a single
554function, it is changed to a list of functions. 554function, it is changed to a list of functions."
555
556Note: if you make a hook variable buffer-local, copy its value before
557you use `add-hook' to add to it. For example,
558
559 (make-local-variable 'foo-hook)
560 (if (boundp 'foo-hook)
561 (setq foo-hook (copy-sequence foo-hook)))
562 (add-hook 'foo-hook 'my-foo-function)"
563 (or (boundp hook) (set hook nil)) 555 (or (boundp hook) (set hook nil))
564 ;; If the hook value is a single function, turn it into a list. 556 ;; If the hook value is a single function, turn it into a list.
565 (let ((old (symbol-value hook))) 557 (let ((old (symbol-value hook)))
@@ -570,7 +562,7 @@ you use `add-hook' to add to it. For example,
570 (memq function (symbol-value hook))) 562 (memq function (symbol-value hook)))
571 (set hook 563 (set hook
572 (if append 564 (if append
573 (nconc (symbol-value hook) (list function)) 565 (append (symbol-value hook) (list function))
574 (cons function (symbol-value hook)))))) 566 (cons function (symbol-value hook))))))
575 567
576(defun remove-hook (hook function) 568(defun remove-hook (hook function)
@@ -584,7 +576,8 @@ list of hooks to run in HOOK, then nothing is done. See `add-hook'."
584 nil ;Do nothing. 576 nil ;Do nothing.
585 (let ((hook-value (symbol-value hook))) 577 (let ((hook-value (symbol-value hook)))
586 (if (consp hook-value) 578 (if (consp hook-value)
587 (setq hook-value (delete function hook-value)) 579 (if (member function hook-value)
580 (setq hook-value (delete function (copy-sequence hook-value))))
588 (if (equal hook-value function) 581 (if (equal hook-value function)
589 (setq hook-value nil))) 582 (setq hook-value nil)))
590 (set hook hook-value)))) 583 (set hook hook-value))))