When starting a server it's possible to set a name for the server (http://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html). These names are to be useful for connecting emacsclients to those servers, however it would be nice to switch some behavior in my config based on the server name(my initial thoughts are changing the theme).

I've dug around on google and the best way seems to be setting an env var and then reading that back in the configuration (http://www.emacswiki.org/emacs/EmacsAsDaemon#toc13). I can't seem to find a way to get this information from within emacs without setting the env var, and I'd rather not have to run a separate wrapper just to know what server is running. How would I go about finding this information programmatically?

2 Answers 2


It appears daemonp will return the name of the server. I ended up with code that looks something like

 ((string= "org" (daemonp))
  (load-theme 'solarized-light)
  (load-theme 'solarized-dark)
  • 1
    daemonp is a predicate, it either returns t or nil.
    – wasamasa
    Mar 13, 2015 at 11:12
  • I'm on 24.4.1 and daemonp is returning the name of the server. I updated the sample to use string= because daemonp will return nil if emacs isn't running a server.
    – Aaron Lee
    Mar 13, 2015 at 11:46
  • According to the sources, daemonp can do both. For the server it can return either its name or nil, for the client it can be both t and nil. This is pretty bonkers considering there's the server-name variable, yet no exposed daemon-name variable.
    – wasamasa
    Mar 13, 2015 at 11:53
  • The builtin documentation also states that daemonp has a dual behavior ` daemonp is a built-in function in C source code'. (daemonp) Return non-nil if the current emacs process is a daemon. If the daemon was given a name argument, return that name. I suggest you to accept your own answer
    – Joafigue
    Aug 28, 2015 at 23:41

In a client instance the variable server-name is bound and contains the server name.

(and (boundp 'server-name) server-name)
  • Thank you for letting me know about server-name, but it is only set in the client and so isn't available during initialization.
    – Aaron Lee
    Mar 13, 2015 at 11:45

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.