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:
rcerc 2022-01-10 02:17:13 -05:00 committed by GitHub
parent 05d655146b
commit f3be3cda6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 1 deletions

View file

@ -3,4 +3,5 @@
emacs-service-28 = ./emacs-service-28.nix;
emacs-socket-27 = ./emacs-socket-27.nix;
emacs-socket-28 = ./emacs-socket-28.nix;
emacs-default-editor = ./emacs-default-editor.nix;
}

View 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;
}
}";
}

View 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)"