feat: emacs daemon

This commit is contained in:
Ryan Yin
2024-01-03 19:09:26 +08:00
parent 59d9601f49
commit f68fe49720
4 changed files with 92 additions and 53 deletions
+13
View File
@@ -167,3 +167,16 @@ test-emacs:
test-emacs-clean: test-emacs-clean:
rm -rf $"($env.HOME)/.config/doom/" 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}}
@@ -13,11 +13,6 @@
- Emacs Wiki: <https://www.emacswiki.org/emacs/SiteMap> - Emacs Wiki: <https://www.emacswiki.org/emacs/SiteMap>
- Awesome Emacs: <https://github.com/emacs-tw/awesome-emacs#lsp-client> - Awesome Emacs: <https://github.com/emacs-tw/awesome-emacs#lsp-client>
Emacs daemon:
- <https://github.com/nix-community/home-manager/blob/master/modules/services/emacs.nix>
- <https://github.com/LnL7/nix-darwin/blob/1a41453cba42a3a1af2fff003be455ddbd75386c/modules/services/emacs.nix>
## Install or Update ## Install or Update
After deploying this nix flake, run the following command to install or update emacs: After deploying this nix flake, run the following command to install or update emacs:
+40 -9
View File
@@ -19,9 +19,9 @@ with lib; let
export PATH="${config.xdg.configHome}/emacs/bin:$PATH" export PATH="${config.xdg.configHome}/emacs/bin:$PATH"
''; '';
shellAliases = { shellAliases = {
e = "emacs"; e = "emacsclient -c";
ediff = ''emacs -nw --eval "(ediff-files \"$1\" \"$2\")"''; ediff = ''emacsclient -c -nw --eval "(ediff-files \"$1\" \"$2\")"'';
eman = ''emacs -nw --eval "(switch-to-buffer (man \"$1\"))"''; eman = ''emacsclient -c -nw --eval "(switch-to-buffer (man \"$1\"))"'';
}; };
in { in {
options.modules.editors.emacs = { options.modules.editors.emacs = {
@@ -31,13 +31,9 @@ in {
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable (mkMerge [
{
home.packages = with pkgs; [ home.packages = with pkgs; [
## Emacs itself
((emacsPackagesFor emacs-unstable-nox).emacsWithPackages
(epkgs: [
epkgs.vterm
]))
librime librime
emacs-all-the-icons-fonts emacs-all-the-icons-fonts
@@ -77,5 +73,40 @@ in {
${pkgs.rsync}/bin/rsync -avz --chmod=D2755,F744 ${doomemacs}/ ${config.xdg.configHome}/emacs/ ${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
]));
client.enable = true;
startWithUserSession = true;
}; };
})
(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;
};
};
})
]);
} }