I'm using (server-start) in my init.el, but I'd like to be able to launch multiple server instances, every time I launch emacs.

Today, server-start complains if the server is already launched.

It would be nice that if the server already exists, a new server name is automatically determined (like server2, server3), a new server instance launched, and the server name displayed in a message.

As I'm emacs lisp newbie, can someone please help scripting this in init.el? How to determine if serverN is already launched? List /tmp/emacs$UID?

  • 1
    You could try use server-start from the command line: emacs --eval '(progn (setq server-name "server2") (server-start))' file Commented Jun 16, 2017 at 9:35

2 Answers 2


How to determine if serverN is already launched?

server-running-p is a compiled Lisp function in ‘server.el’.

(server-running-p &optional NAME)

Test whether server NAME is running.

Return values:
  nil              the server is definitely not running.
  t                the server seems to be running.
  something else   we cannot determine whether it’s running without using
                   commands which may have to wait for a long time.

You can replace the call (server-start) with following code in your init.el:

(require 'server)

(defun my--server-start ()
    (let ((server-num 0))
        (while (server-running-p (unless (eq server-num 0) (concat "server" (number-to-string server-num))))
            (setq server-num (+ server-num 1)))

        (unless (eq server-num 0)
            (setq server-name (concat "server" (number-to-string server-num))))

        (setq frame-title-format server-name)))


Note: to connect to those servers, you have to use emacsclient like this:
emacsclient -s server<SERVERNUMBER>
Example: emacsclient -s server2


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.