I want to do some custom stuff before a window is deleted?
window-configuration-change-hook
seems to be invoked after a window is deleted.
Inspection of delete-window
in GNU Emacs 25.1.50.2 (i686-pc-linux-gnu, GTK+ Version 3.10.8) of 2016-04-25
shows that there is no such hook.
I don't right follow the argument of lawlist in his comment that delete-window
is too fundamental to be advised.
For an example the following advice would provide a hook for functions with a WINDOW
argument that is run before window WINDOW
is deleted.
(defvar window-before-delete-functions nil
"Functions to be run with argument WINDOW before \(delete-window WINDOW).")
(defun delete-window-ad (window)
"Add `window-before-delete-functions' as before-advice of \(delete-window WINDOW)."
(run-hook-with-args 'window-before-delete-functions (or window (selected-window))))
(advice-add #'delete-window :before #'delete-window-ad)
Just remove the hook functions in window-before-delete-functions
if something goes wrong with them.
pre-command-hook
and/or apost-command-hook
with a test for a list of functions that would trigger additional custom stuff:(when (memq this-command '(.....)) custom-stuff)
. If the condition is not met, there is virtually zero overhead. And, these hooks can be buffer local if so desired. The test can be more complicated of so desired, e.g., a particular major-mode, current window of the previous command is the same window as the new command, etc. I cannot recommend advisingdelete-window
ordelete-other-windows
as they are too fundamental to mess.