From 7465289ef0e2a40dacbc49cdd97e99dd83971671 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Thu, 22 Dec 2022 21:42:56 +0100 Subject: [PATCH] [emacs] Enable emacs daemon and wrap `emacsclient`. Emacs can be run locally as a daemon. `emacsclient` connects to it and can open multiple windows during the same session. --- bash/.config/profile.d/20-env.sh | 1 + conf/home/emacs.scm | 21 +++++++++++++++++++-- emacs/.local/bin/emacs_client | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 emacs/.local/bin/emacs_client diff --git a/bash/.config/profile.d/20-env.sh b/bash/.config/profile.d/20-env.sh index 5583c3f..b1a7828 100644 --- a/bash/.config/profile.d/20-env.sh +++ b/bash/.config/profile.d/20-env.sh @@ -4,3 +4,4 @@ # 20-env.sh - generic environment variables. export EDITOR="emacs" +export PATH="${HOME}/.local/bin:${PATH}" diff --git a/conf/home/emacs.scm b/conf/home/emacs.scm index 4615e2c..aaf22fa 100644 --- a/conf/home/emacs.scm +++ b/conf/home/emacs.scm @@ -5,17 +5,34 @@ (define-module (conf home emacs) #:use-module (conf home program) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) #:use-module (gnu packages emacs) #:use-module (gnu services) #:use-module (guix gexp) #:export (emacs-services)) +(define emacs-daemon-shepherd-service + (shepherd-service + (provision '(emacs)) + (start #~(make-forkexec-constructor + (list "emacs" "--fg-daemon") + #:directory (getenv "HOME"))) + (stop #~(make-kill-destructor)) + (documentation ""))) + +(define emacs-daemon-service + (simple-service 'emacs-daemon-service + home-shepherd-service-type + (list emacs-daemon-shepherd-service))) (define emacs-service (service home-program-service-type (home-program-configuration (packages (list emacs)) - (dotfiles '())))) + (dotfiles + (list "emacs/.local/bin/emacs_client"))))) (define emacs-services - (list emacs-service)) + (list emacs-daemon-service + emacs-service)) diff --git a/emacs/.local/bin/emacs_client b/emacs/.local/bin/emacs_client new file mode 100755 index 0000000..07bd391 --- /dev/null +++ b/emacs/.local/bin/emacs_client @@ -0,0 +1,5 @@ +#!/bin/sh +# Copyright (c) 2022 Jakub Czajka +# License: GPL-3.0 or later. + +emacsclient --socket-name=/run/user/$(id -u)/emacs/server --create-frame & -- 2.39.5