Sometimes when I get to work, I notice some Org mode file, that I share via Dropbox, looks out of date... which means I forgot to save my changes. Sometimes when I'm home, I notice the reverse. I wanted a solution more considered than a blunt auto-save timer.

I was just mentioning the emacsclient(1) yesterday and noted its -e option (--eval). This lets you evaluate a bit of elisp in your running Emacs, from the command line, via th Emacs Server. Pairing this with SSH made for an easy "remote save" solution.

I mostly work between buttercup and elder-whale, my home and work machines, so my shell function defaults to saving buffers on the other host. I use Zsh and haven't tested this elsewhere.

function emacs-save-remote-buffers {
    local remote_host=$1
    if [ -z "$remote_host" ]; then
        case $HOST in
                echo "please supply a hostname"
                return 1
    ssh $remote_host "emacsclient -e '(if (save-some-buffers t) \"buffers saved\" \"no unsaved buffers\")'"

Emacs offers the option to directly update the file a buffer is visiting. I prefer the original design that auto-saves to a separate file, only updating the real file on explicit save operations. With that being the case, sometimes this little hack comes in handy.

Cover photo by Kelly Sikkema