Created
December 15, 2024 16:54
-
-
Save jdtsmith/90ee949bcef023633f9c5127fac5e7c4 to your computer and use it in GitHub Desktop.
Cleanup TRAMP connections prior to sleeping with Hammerspoon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local cw = require "hs.caffeinate.watcher" | |
function cleanup_tramp_on_sleep(ev_type) | |
if ev_type == cw.systemWillSleep then | |
hs.execute("/usr/local/bin/emacsclient -e " .. | |
"'(when (tramp-list-connections) " .. | |
" (message \"Cleaning up TRAMP before sleep\") " .. | |
" (tramp-cleanup-all-connections))'") | |
end | |
end | |
-- Note: watcher must be a global to continue running | |
sleep_watcher = cw.new(cleanup_tramp_on_sleep) | |
sleep_watcher:start() | |
print("Watching for sleep with ", sleep_watcher) |
For Linux you can do the same using a function which is executed when the DBus suspend signal occurs.
Check out gnus-dbus-sleep-handler
for reference.
I this context it should be a little cleaner to write the elisp function in Emacs e.g. in init.el and then call it with emacsclient e.g. as in emacsclient -e my_function
. To bad you can't just subscribe to Mach IPC messages as you can with DBus in Emacs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This helps prevent tramp lockup in emacs by cleaning up all tramp connections prior to sleep. Operating in any remote emacs buffers will automatically re-establish the connection.