Running Emacs as a Daemon

M. J. Wall has an interesting post entitled How I Use Emacs. Wall's workflow is a bit unusual—by which I mean different from mine—in that he spends a lot of time in the terminal even though he's running GUI desktops in Linux and OS X. Sometimes he just wants to edit a file and then return to the terminal. Other times he wants to pop up an Emacs buffer and return to the terminal immediately.

To facilitate that workflow, he has two scripts. One starts Emacs in the terminal window and waits for Emacs to finish before returning to the shell. The other pops up a new Emacs frame and returns to the terminal immediately. An interesting trick that both these scripts use is to call emacsclient with the -a “” option. That says that if the Emacs server is not already running, start it and then reattach emacsclient to it.

As I mentioned, my workflow is different. I always have Emacs running and have a shortcut key to change focus to it so if I'm in a terminal and need Emacs I just press【F6】 to pop into Emacs and do what needs doing. Nonetheless, there is one case where Wall's technique is useful to me. Usually if I want to edit a file on another machine, I just use tramp but if I'm sshed into that machine already it's convenient to just bring up emacsclient on the remote machine. Wall's et script is perfect for that. Even if the remote machine doesn't have a copy of the et script installed, it's simple to call emacsclient directly

emacsclient -a "" -t file-to-edit

If you use Emacs and ever ssh into remote machines, this is a technique worth knowing.

This entry was posted in General and tagged . Bookmark the permalink.