summaryrefslogtreecommitdiff
path: root/modules/devenv/integrations/emacs.nix
blob: d00296733916d61943691f2fb1b33789f2e1063a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
  config,
  lib,
  ...
}: let
  cfg = config.emacs;
  attrs2alist = value:
    if lib.isAttrs value
    then "(${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: "(${name} . ${attrs2alist value})") value)})"
    else
      (
        if lib.isList value
        then "(${lib.concatStringsSep " " value})"
        else
          (
            if lib.isBool value
            then
              (
                if value
                then "t"
                else "nil"
              )
            else builtins.toString value
          )
      );
in {
  options.emacs = {
    enable = lib.mkEnableOption "emacs integration";
    dirLocals = lib.mkOption {
      type = with lib.types; attrsOf (attrsOf str);
      default = {};
      example =
        # the first example from https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
        {
          nil = {
            indent-tabs-mode = true;
            fill-column = 80;
            mode = "auto-fill";
          };
          c-mode = {
            c-file-style = ''"BSD"'';
            subdirs = "nil";
          };
          "\"src/imported\"".nil.change-log-default-name = ''"ChangeLog.local"'';
        };
    };
  };

  config.dotfiles.".dir-locals.el".text =
    lib.mkIf (cfg.dirLocals != {})
    (attrs2alist
      cfg.dirLocals);
}