Chris R Chris R - 6 months ago 23
Bash Question

How can I detect that emacs-server is running from a shell prompt?

I want to have my .bashrc detect if running emacsclient would work in lieu of running emacs. Basically:

if emacs_server_is_running; then
EDITOR=emacsclient
VISUAL=emacsclient
else
EDITOR=emacs
VISUAL=emacs
fi


What would I put in the
emacs_server_is_running
function to accomplish this aim?

Answer

You're making this too hard. From the the emacsclient(1) man page:

-a, --alternate-editor=EDITOR if the Emacs server is not running, run the specified editor instead. This can also be specified via the `ALTERNATE_EDITOR' environment variable. If the value of EDITOR is the empty string, then Emacs is started in daemon mode and emacsclient will try to connect to it.
Comments