{ pkgs, lib, ... }:

{
  # TODO: upstream this
  imports         = [ ../modules/micro.nix ];
  disabledModules = [ "programs/micro.nix" ];

  home.shellAliases.ed = "$EDITOR"; # ed is the standard editor
  home.shellAliases.de = "$EDITOR"; # de is the standard typo
  home.sessionVariables.EDITOR = "micro";

  home.packages = with pkgs; [
    micro
    aspell
    aspellDicts.en
    aspellDicts.nb
  ];

  programs.bash.initExtra = ''
    if [ "$COLORTERM" = "truecolor" ] || [ "$TERM" == "xterm" ]; then
	    export TERM=xterm-256color
	    export MICRO_TRUECOLOR=1
    fi
  '';

  programs.micro.enable = true;
  programs.micro.trueColor = true;
  programs.micro.settings.colorscheme = "railscast";
  programs.micro.settings.rmtrailingws = true;
  programs.micro.settings.tabstospaces = true;
  programs.micro.settings.autoclose = false;
  #xdg.configFile."micro/bindings.json".source = (pkgs.formats.json {}).generate "micro-bindings" {
  programs.micro.bindings = {
    "Alt-/"          = "lua:comment.comment";
    "Alt-d"          = "SpawnMultiCursor";
    "Alt-j"          = "lua:joinLines.joinLines";
    "Alt-l"          = "command:lower";
    "Alt-u"          = "command:upper";
    "AltLeft"        = "PreviousTab";
    "AltRight"       = "NextTab";
    "Ctrl-j"         = "EndOfLine,CursorRight,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,OutdentLine,Backspace";
    "CtrlDown"       = "None";
    "CtrlUnderscore" = "lua:comment.comment";
    "CtrlUp"         = "None";
    "Escape"         = "RemoveAllMultiCursors";
    "Shift-PageDown" = "SelectPageDown";
    "Shift-PageUp"   = "SelectPageUp";
  };
  programs.micro.ensurePlugins = [
    "aspell"
    "detectindent"
    "editorconfig"
    "joinLines"
    "manipulator"
    "quoter"
  ];
}