earnest ma's site

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.

:)

Tags: #emacs

Comments

You may view or reply if you have an account anywhere in the Fediverse.

Recent posts from blogs I read Generated by openring

Weekly review: Week ending February 19, 2021

I got captions to flow from my phone to Node to Emacs to OBS to Twitch. There’s some delay, but it’s a good starting point that might come in handy for live captioning my own stuff. I added autocategorization to Emacs News. I tried out pretty-hydra. I wro…

via sacha chua :: living an awesome life February 21, 2021

A great alternative is rarely fatter than what it aims to replace

This is not always true, but in my experience, it tends to hold up. We often build or evaluate tools which aim to replace something kludgy^Wvenerable. Common examples include shells, programming languages, system utilities, and so on. Rust, Zig, etc, are tak…

via Drew DeVault's blog February 21, 2021

Back Home

I was busy sanding down the planks all evening last Sunday in that unbearable cold in the garage and just nearly got done when it started snowing. My wife had been lamenting all week about the snow in Dallas and naturally this made her happy. That happine…

via simbly.me February 20, 2021