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

2021-04-19 Emacs news

Upcoming events: Emacs APAC (virtual, in English) https://emacs-apac.gitlab.io/ Sat Apr 24 0130 Vancouver / 0330 Chicago / 0430 Toronto / 0830 GMT / 1030 Berlin / 1400 Kolkata / 1630 Singapore Emacs Berlin (virtual, in English) https://emacs-berlin.org/ Wed Ap…

via Sacha Chua April 19, 2021

Misinformation about Permissions Policy and FLoC

This post was written in a hurry in response to some misinformation about Google’s newest Web antifeature, Federated Learning of Cohorts (FLoC). Google’s FLoC is an attempt to track users even when their browsers (rightly) block third-party cookies. The i…

via Posts on Seirdy's Home April 16, 2021

Modus themes 1.3.0 for GNU Emacs

Information about the latest version of my highly accessible themes for GNU Emacs.

via Protesilaos Stavrou: Master feed with all updates April 17, 2021