timp
timp copied to clipboard
`timp--kill-emacs` ignores dynamically bound `kill-emacs-hook`
Hi,
I am the author of the package restart-emacs
.
One of the package's user hit a bug. After some debugging it seems that issue is with the advice timp--kill-emacs
that timp
adds around save-buffers-kill-emacs
function.
The restart-emacs package works by starting a new instance of Emacs just before current instance of Emacs is killed, to achieve this a function is added to the kill-emacs-hook
which actually starts the new instance.
Obviously the function needs to be added temporarily to kill-emacs-hook
, so that it does not interfere with normal Emacs exists. The easiest way to do this is to create a let binding
for kill-emacs-hook
around the invocation of function save-buffers-kill-emacs
, which contains the function that needs to be invoked for launching other Emacs. This way the hook is present only for that invocation and no code is needed to remove it if Emacs exit fails for some reason. I am not sure if I have explained the restart process well enough, let me know if it was not clear.
Now since timp--kill-emacs
invokes the function asynchronously (if some thread is running and needs to be stopped) using a timer the dynamic environment setup with the special value of kill-emacs-hook
described above is lost and restarting fails.
Perhaps making the wait synchronous would solve the issue, something like the following
(dotimes (x 5)
(message "Waiting ... %d seconds left" (- 5 x))
(sit-for 1))
Thanks