0

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.

  • 1
    I'm sorry but I fail to see the problem. Would you mind to add a little more detail to your question? Particularly, could you explain why you can't just add an appropriate function to these hooks? – lunaryorn Nov 24 '14 at 10:39
  • The thing is that the function in 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. – wasamasa Nov 24 '14 at 10:45
  • I've experimented a bit and added a question for an alternative way of achieving my goal by finding out what hook ran the function. – wasamasa Nov 24 '14 at 11:09
  • You can't, and in my opinion, the desire to do so indicates a design flaw. Make your hook functions idempotent, so that they don't repeat the action when called twice. How to do that of course depends on what your functions actually do, which is precisely the reason why I asked for more details. – lunaryorn Nov 24 '14 at 11:14
  • 1
    I just saw your update: Just use a different function for kill-buffer-hook then. Different hooks, different functions. There is nothing “bad” or “less elegant” about this. – lunaryorn Nov 24 '14 at 13:14
0

I've eventually written one function per hook as suggested in the comments. Thanks to @lunaryorn for the suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.