[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: add-hook sets hook globally if buffer-local hook is nil
From: |
Stefan Monnier |
Subject: |
Re: add-hook sets hook globally if buffer-local hook is nil |
Date: |
23 Oct 2003 17:56:14 -0400 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
> @@ -856,9 +870,7 @@
> (set (make-local-variable hook) (list t)))
> ;; 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)))))
> + (unless (and (consp (symbol-value hook)) (memq t (symbol-value
> hook)))
> (setq local t)))
> (let ((hook-value (if local (symbol-value hook) (default-value hook))))
> ;; If the hook value is a single function, turn it into a list.
> i dont think this change causes the problem.
> this code detects case where hook var has a local binding
> and it wasnt made with add-hook.
> i think thye change makes it safer.
I disagree. The old code (the above diff is reversed, BTW, sorry) set
`local' to t more often, which makes it less likely that add-hook will
change the global value by mistake.
More specifically, the old code set `local' to t even if the variable is
not local-variable-p but is local-variable-if-set-p.
Thus with a variable that has been make-variable-buffer-local'd, the new
code will fail to set `local' to t and will thus incorrectly modify the global
part of the hook. That's the bug we're seeing.
A better fix than the one you provided is to replace in the above code
`local-variable-p' with `local-variable--if-set-p', but I still have no
idea why the additional check would be needed in the first place.
Stefan
- add-hook sets hook globally if buffer-local hook is nil, Alan Shutko, 2003/10/21
- Re: add-hook sets hook globally if buffer-local hook is nil, Klaus Zeitler, 2003/10/22
- Re: add-hook sets hook globally if buffer-local hook is nil, Lute Kamstra, 2003/10/22
- Re: add-hook sets hook globally if buffer-local hook is nil, Klaus Zeitler, 2003/10/22
- Re: add-hook sets hook globally if buffer-local hook is nil, Alan Shutko, 2003/10/22
- Re: add-hook sets hook globally if buffer-local hook is nil, Stefan Monnier, 2003/10/22
- Re: add-hook sets hook globally if buffer-local hook is nil, Lute Kamstra, 2003/10/22
- Re: add-hook sets hook globally if buffer-local hook is nil, Richard Stallman, 2003/10/23
- Re: add-hook sets hook globally if buffer-local hook is nil,
Stefan Monnier <=
- Re: add-hook sets hook globally if buffer-local hook is nil, Richard Stallman, 2003/10/24
- Re: add-hook sets hook globally if buffer-local hook is nil, Stefan Monnier, 2003/10/26