How to start emacs server only if it is not started?

Meng Lu picture Meng Lu · Apr 6, 2011 · Viewed 19.8k times · Source

I'd like to use emacsclient to edit emails in Mutt.

I added this in .emacs

(server-start)

And in .muttrc I added

set editor="emacsclient -nw %s"

It seems they work. When I start a second Emacs, it complains there is already a server running so it issues errors. How to make sure to do (server-start) only if the server isn't already started?

Thanks

Answer

Philipp picture Philipp · Apr 6, 2011

This code starts the server only if it's not running:

(load "server")
(unless (server-running-p) (server-start))