* martin rudalics [2010-06-20 12:42+0200] writes: >> I'm wondering a bit though: kill-buffer protects the current buffer >> while calling kill-buffer-hook. Wouldn't it be prudent to do that for >> the entire function? > > You mean for the case where the buffer we want to kill is not the > current buffer? Both cases. Even in the case where the to-be-killed buffer is not current, kill-buffer may decide not to actually kill it and instead return nil; this case should also not switch the buffer. >> Actually, I think there is a small bug there: if kill-buffer-hook is a >> list of functions, the first function could potentially switch buffer >> and the second function would be called in the wrong buffer. > > I suppose you're right. Could you propose a patch for this and the > above issue? Below are two patches. The first essentially adds a save-excursion around the whole function. The second patch adds a function run_hook_in_buffer. It iterates over the functions in the hook and for each function explicitly sets the buffer before calling it. I had to introduce a new macro DO_HOOK_FUNCTIONS which is a big hammer for this, but I couldn't find a better way. Helmut