Bala's Blog

Running Emacs as daemon

June 30 2018
173 words, ~1 min. read
emacs,  daemon,  windows,  linux,  freebsd 

Windows

  1. Open startup folder [Hint: Use Win + R to bring Run window, type shell:startup in the textbox and press the OK button]
  2. Create a shortcut in the startup folder to target <path-to-emacs-dir>\runemacs.exe --daemon ; also, set the value of Start in folder to <user-home-directory> or open Control Panel and add user environment variable EMACS_SERVER_FILE with value as <user-home-directory>\.emacs.d\server\server
  3. Start the emacs daemon [double-click the shortcut created above; or Logout and Login again]
  4. From now on, instead of running emacs or runemacs, run emacsclientw -c

Linux / FreeBSD

  1. In a shell/terminal, invoke emacs --daemon
  2. From now on, run emacsclientw -tc or emacsclientw -c, for shell and X accordingly

Note: Though recent emacs distribution come with systemd service for automatic startup, I prefer the following aliases setup in ~/.bashrc

alias ed="emacs --daemon"
alias ec="emacsclient -tc"
alias ek="emacsclient --eval '(kill-emacs)'"

Note : I had issues in setting up the default font, especially in daemon mode; the issue was resolved by adding the following in emacs startup file,

(add-to-list 'default-frame-alist '(font . "Hack-12"))

References