After having a problem with debugging a package I write, I finally tracked down the problem to the following: auto-revert-mode
is making kill-buffer-hook
buffer-local (which is fine by me). The problem is that every library (auto-)loaded afterwards (while the buffer is still active) only "sees" the buffer-local binding, and any add-hook
only modifies the buffer-local binding.
Here are a few steps to reproduce the problem using only standard emacs libraries:
(find-file "foo.el")
kill-buffer-hook ; => (uniquify-kill-buffer-function vc-kill-buffer-hook)
(default-value 'kill-buffer-hook) ; => (uniquify-kill-buffer-function vc-kill-buffer-hook)
;; Turn on `auto-revert-mode': `kill-buffer-hook' becomes buffer-local
(auto-revert-mode)
kill-buffer-hook ; => (auto-revert-notify-rm-watch uniquify-kill-buffer-function vc-kill-buffer-hook)
(default-value 'kill-buffer-hook) ; => (uniquify-kill-buffer-function vc-kill-buffer-hook)
;; Subsequently load a library which adds a `kill-buffer-hook'
;; only the local binding is modified; no other buffer will ever see
;; the hook installed by `tramp'
(require 'tramp)
kill-buffer-hook ; => (tramp-delete-temp-file-function auto-revert-notify-rm-watch uniquify-kill-buffer-function vc-kill-buffer-hook)
(default-value 'kill-buffer-hook) ; => (uniquify-kill-buffer-function vc-kill-buffer-hook)
;; The same thing happens (unsurprisingly) for auto-loaded libraries
(browse-url "emacs.stackexchange.com")
kill-buffer-hook ; => (browse-url-delete-temp-file tramp-delete-temp-file-function auto-revert-notify-rm-watch uniquify-kill-buffer-function vc-kill-buffer-hook)
(default-value 'kill-buffer-hook) ; => (uniquify-kill-buffer-function vc-kill-buffer-hook)
So I guess my question is: is this normal and desired behaviour? Shouldn't all buffers see the hooks installed by subsequently loaded packages?
Although the problem here is specifically caused by auto-revert-mode
and kill-buffer-hook
, I'm guessing this situation is fairly more general and could happen for a lot of libraries and hooks...