How to start emacs server only if it is not started?
This code starts the server only if it's not running:
(load "server")
(unless (server-running-p) (server-start))
The emacs daemon can be started automatically in a very simple manner. Just add this to your .bashrc/.zshrc/whatever
export ALTERNATE_EDITOR=""
Now when you invoke emacsclient
(using either --tty
or --create-frame
) the server will be started (with emacs --daemon
) if it's not already running.
I also find this shell alias handy:
alias e='emacsclient --tty'
Note that since Emacs 23 this is the preferred way to use Emacs in daemon mode. (start-server)
is now mostly deprecated.