Using (Multiple) Emacs Daemons (Windows)

GNU Emacs’ performance on Windows at times feels a bit sluggish/ slow. It still randomly crashes sometimes when I use the menu bar but I haven’t figured out why. Of course, the daemon/ server-mode can be used, however, you can also run multiple daemon(s?)!

Benefits

SystemD

On my GNU/Linux laptop, this was easy: just create a user systemd file.

Make sure it starts after boot instead of after login: sudo loginctl enable-linger $(whoami)

In ~/.config/systemd/user/emacs@.service:

[Unit]
Description=Emacs daemon

[Service]
Type=forking
ExecStart=emacs --daemon=%i --chdir %h
ExecStop=emacsclient --server-file=hud --eval "(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
Restart=always
TimeoutStartSec=0

[Install]
WantedBy=default.target

Starting and enabling daemon named personal and work: systemctl enable --now emacs@personal.service --user and systemctl enable --now emacs@work.service --user.

Windows

On Windows, I struggled to find a way to launch the daemons on login - Task Scheduler didn’t seem to work.

My solution was creating start-emacs-daemons.bat in C:\Users\earne\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup:

runemacs --daemon=personal --chdir=%HOME%
runemacs --daemon=work --chdir=%HOME%

Make sure runemacs.exe (and all the other executables) are in your PATH, and set %HOME% to C:\Users\YourUsername. Then just click the file to start the daemons for the first time, although after this they should automatically launch on login.

Aliases

I placed these in my ~/.bashrc (I use Git Bash on windows and just regular bash on GNU/Linux, so this works fine)

## personal Emacs Daemon
alias pe="emacsclient --server-file=personal"
alias pew="emacsclient --server-file=personal --create-frame --no-wait"
alias pk="emacsclient --server-file=personal -e '(kill-emacs)'"
## work Emacs Daemon
alias we="emacsclient --server-file=work"
alias wew="emacsclient --server-file=work --create-frame --no-wait"
alias wk="emacsclient --server-file=work -e '(kill-emacs)'"

More Reading

Here are links to my dotfiles and Emacs configuration.

:)



Subscribe

Emails are sent about once a month instead of per post. Of course, I won't send you spam, and you can unsubscribe at any time. Otherwise, you can also subscribe via Atom or RSS, Telegram, or Mastodon.

If you enjoyed reading this post, please consider supporting me 💜