From f68fe4972098b2dc34cef174377dd9f282c4055c Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Wed, 3 Jan 2024 19:09:26 +0800 Subject: [PATCH] feat: emacs daemon --- Justfile | 13 ++ home/base/desktop/editors/emacs/README.md | 5 - home/base/desktop/editors/emacs/default.nix | 127 +++++++++++------- .../desktop/editors/emacs/doom/snippets/.keep | 0 4 files changed, 92 insertions(+), 53 deletions(-) create mode 100644 home/base/desktop/editors/emacs/doom/snippets/.keep diff --git a/Justfile b/Justfile index d709633f..31ba1cf1 100644 --- a/Justfile +++ b/Justfile @@ -167,3 +167,16 @@ test-emacs: test-emacs-clean: rm -rf $"($env.HOME)/.config/doom/" + +emacs-plist-path := "~/Library/LaunchAgents/org.nix-community.home.emacs.plist" + +reload-emacs-cmd := if os() == "macos" { + "launchctl unload " + emacs-plist-path + + "\n" + + "launchctl load " + emacs-plist-path + } else { + "systemctl --user restart emacs.service" + } + +reload-emacs: + {{reload-emacs-cmd}} diff --git a/home/base/desktop/editors/emacs/README.md b/home/base/desktop/editors/emacs/README.md index eace8cd6..9bda8664 100644 --- a/home/base/desktop/editors/emacs/README.md +++ b/home/base/desktop/editors/emacs/README.md @@ -13,11 +13,6 @@ - Emacs Wiki: - Awesome Emacs: -Emacs daemon: - -- -- - ## Install or Update After deploying this nix flake, run the following command to install or update emacs: diff --git a/home/base/desktop/editors/emacs/default.nix b/home/base/desktop/editors/emacs/default.nix index 98cba801..79ef0a4a 100644 --- a/home/base/desktop/editors/emacs/default.nix +++ b/home/base/desktop/editors/emacs/default.nix @@ -19,9 +19,9 @@ with lib; let export PATH="${config.xdg.configHome}/emacs/bin:$PATH" ''; shellAliases = { - e = "emacs"; - ediff = ''emacs -nw --eval "(ediff-files \"$1\" \"$2\")"''; - eman = ''emacs -nw --eval "(switch-to-buffer (man \"$1\"))"''; + e = "emacsclient -c"; + ediff = ''emacsclient -c -nw --eval "(ediff-files \"$1\" \"$2\")"''; + eman = ''emacsclient -c -nw --eval "(switch-to-buffer (man \"$1\"))"''; }; in { options.modules.editors.emacs = { @@ -31,51 +31,82 @@ in { }; }; - config = mkIf cfg.enable { - home.packages = with pkgs; [ - ## Emacs itself - ((emacsPackagesFor emacs-unstable-nox).emacsWithPackages - (epkgs: [ + config = mkIf cfg.enable (mkMerge [ + { + home.packages = with pkgs; [ + librime + emacs-all-the-icons-fonts + + ## Doom dependencies + git + (ripgrep.override {withPCRE2 = true;}) + gnutls # for TLS connectivity + + ## Optional dependencies + fd # faster projectile indexing + imagemagick # for image-dired + zstd # for undo-fu-session/undo-tree compression + + ## Module dependencies + # :checkers spell + (aspellWithDicts (ds: with ds; [en en-computers en-science])) + # :tools editorconfig + editorconfig-core-c # per-project style config + # :tools lookup & :lang org +roam + sqlite + # :lang latex & :lang org (latex previews) + texlive.combined.scheme-medium + ]; + + programs.bash.bashrcExtra = envExtra; + programs.zsh.envExtra = envExtra; + home.shellAliases = shellAliases; + programs.nushell.shellAliases = shellAliases; + + # allow fontconfig to discover fonts and configurations installed through `home.packages` + fonts.fontconfig.enable = true; + + xdg.configFile."doom".source = ./doom; + + home.activation = mkIf cfg.doom.enable { + installDoomEmacs = lib.hm.dag.entryAfter ["writeBoundary"] '' + ${pkgs.rsync}/bin/rsync -avz --chmod=D2755,F744 ${doomemacs}/ ${config.xdg.configHome}/emacs/ + ''; + }; + } + + (mkIf pkgs.stdenv.isLinux { + services.emacs = { + enable = true; + package = with pkgs; ((emacsPackagesFor emacs-unstable-pgtk).emacsWithPackages (epkgs: [ epkgs.vterm - ])) - librime - emacs-all-the-icons-fonts + ])); + client.enable = true; + startWithUserSession = true; + }; + }) - ## Doom dependencies - git - (ripgrep.override {withPCRE2 = true;}) - gnutls # for TLS connectivity - - ## Optional dependencies - fd # faster projectile indexing - imagemagick # for image-dired - zstd # for undo-fu-session/undo-tree compression - - ## Module dependencies - # :checkers spell - (aspellWithDicts (ds: with ds; [en en-computers en-science])) - # :tools editorconfig - editorconfig-core-c # per-project style config - # :tools lookup & :lang org +roam - sqlite - # :lang latex & :lang org (latex previews) - texlive.combined.scheme-medium - ]; - - programs.bash.bashrcExtra = envExtra; - programs.zsh.envExtra = envExtra; - home.shellAliases = shellAliases; - programs.nushell.shellAliases = shellAliases; - - # allow fontconfig to discover fonts and configurations installed through `home.packages` - fonts.fontconfig.enable = true; - - xdg.configFile."doom".source = ./doom; - - home.activation = mkIf cfg.doom.enable { - installDoomEmacs = lib.hm.dag.entryAfter ["writeBoundary"] '' - ${pkgs.rsync}/bin/rsync -avz --chmod=D2755,F744 ${doomemacs}/ ${config.xdg.configHome}/emacs/ - ''; - }; - }; + (mkIf pkgs.stdenv.isDarwin { + launchd.enable = true; + launchd.agents.emacs = { + enable = true; + config = { + ProgramArguments = with pkgs; let + emacsPkg = (emacsPackagesFor emacs-unstable).emacsWithPackages (epkgs: [ + epkgs.vterm + ]); + in [ + "${pkgs.bash}/bin/bash" + "-l" + "-c" + "${emacsPkg}/bin/emacs --fg-daemon" + ]; + StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/emacs-daemon.stderr.log"; + StandardOutPath = "${config.home.homeDirectory}/Library/Logs/emacs-daemon.stdout.log"; + RunAtLoad = true; + KeepAlive = true; + }; + }; + }) + ]); } diff --git a/home/base/desktop/editors/emacs/doom/snippets/.keep b/home/base/desktop/editors/emacs/doom/snippets/.keep new file mode 100644 index 00000000..e69de29b