I'm in the process of writing an Emacs package that helps you controlling popup windows and have hit a minor roadblock while developing a new feature for it. Currently I'm using window-configuration-change-hook
to track certain buffers and their windows that have either been buried or closed, however this hook cannot catch if the buffer in question has been killed since this isn't a window configuration change.
edit: There is a kill-buffer-hook
that could help me solve this minor annoyance, however it's run differently than window-configuration-change-hook
. window-configuration-change-hook
is run after the window configuration changes, kill-buffer-hook
is run before the buffer is killed with the buffer selected. This means that if I add my function to both hooks, I cannot detect if the buffer has been killed because it hasn't been killed yet when the hook is run. That means I'd need to either use a different function in kill-buffer-hook
that operates on the selected buffer than in window-configuration-change-hook
where the selected buffer has different semantics or would need to know what hook has run it.
window-configuration-change-hook
is running through conditions specific to the cases the hook is run for, removes the function from the hook afterwards and is not aware of being run by a different hook before or afterwards. I'm looking for a clean solution that avoids using two slightly different functions per each hook and can clean up after itself without making the other hook error out.kill-buffer-hook
then. Different hooks, different functions. There is nothing “bad” or “less elegant” about this.