mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 11:39:46 +01:00
services/emacs: add option to set emacsclient
as the default editor (#2545)
* services/emacs: add `defaultEditor` option Sets `emacsclient` as the default editor using the `EDITOR` environment variable.
This commit is contained in:
parent
05d655146b
commit
f3be3cda6a
4 changed files with 63 additions and 1 deletions
|
@ -80,6 +80,16 @@ in {
|
||||||
socketActivation = {
|
socketActivation = {
|
||||||
enable = mkEnableOption "systemd socket activation for the Emacs service";
|
enable = mkEnableOption "systemd socket activation for the Emacs service";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
defaultEditor = mkOption rec {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
example = !default;
|
||||||
|
description = ''
|
||||||
|
Whether to configure <command>emacsclient</command> as the default
|
||||||
|
editor using the <envar>EDITOR</envar> environment variable.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
|
@ -139,7 +149,16 @@ in {
|
||||||
Install = { WantedBy = [ "default.target" ]; };
|
Install = { WantedBy = [ "default.target" ]; };
|
||||||
};
|
};
|
||||||
|
|
||||||
home.packages = optional cfg.client.enable (hiPrio clientDesktopItem);
|
home = {
|
||||||
|
packages = optional cfg.client.enable (hiPrio clientDesktopItem);
|
||||||
|
|
||||||
|
sessionVariables = mkIf cfg.defaultEditor {
|
||||||
|
EDITOR = getBin (pkgs.writeShellScript "editor" ''
|
||||||
|
exec ${
|
||||||
|
getBin cfg.package
|
||||||
|
}/bin/emacsclient "''${@:---create-frame}"'');
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
(mkIf cfg.socketActivation.enable {
|
(mkIf cfg.socketActivation.enable {
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
emacs-service-28 = ./emacs-service-28.nix;
|
emacs-service-28 = ./emacs-service-28.nix;
|
||||||
emacs-socket-27 = ./emacs-socket-27.nix;
|
emacs-socket-27 = ./emacs-socket-27.nix;
|
||||||
emacs-socket-28 = ./emacs-socket-28.nix;
|
emacs-socket-28 = ./emacs-socket-28.nix;
|
||||||
|
emacs-default-editor = ./emacs-default-editor.nix;
|
||||||
}
|
}
|
||||||
|
|
24
tests/modules/services/emacs/emacs-default-editor.nix
Normal file
24
tests/modules/services/emacs/emacs-default-editor.nix
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
nixpkgs.overlays = [
|
||||||
|
(self: super: {
|
||||||
|
# Use `cat` instead of `echo` to prevent arguments from being
|
||||||
|
# interpreted as an option.
|
||||||
|
emacs = pkgs.writeShellScriptBin "emacsclient"
|
||||||
|
''${pkgs.coreutils}/bin/cat <<< "$*"'';
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
services.emacs = {
|
||||||
|
defaultEditor = true;
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = "source ${
|
||||||
|
pkgs.substituteAll {
|
||||||
|
inherit (pkgs) coreutils;
|
||||||
|
src = ./emacs-default-editor.sh;
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
}
|
18
tests/modules/services/emacs/emacs-default-editor.sh
Normal file
18
tests/modules/services/emacs/emacs-default-editor.sh
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
set +u
|
||||||
|
source $TESTED/home-path/etc/profile.d/hm-session-vars.sh
|
||||||
|
set -u
|
||||||
|
|
||||||
|
check_arguments () {
|
||||||
|
if [ "$1" != "$2" ]; then
|
||||||
|
@coreutils@/bin/cat <<- EOF
|
||||||
|
Expected arguments:
|
||||||
|
$1
|
||||||
|
but got:
|
||||||
|
$2
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_arguments "--create-frame" "$($EDITOR)"
|
||||||
|
check_arguments "foo bar baz" "$($EDITOR foo bar baz)"
|
Loading…
Reference in a new issue