-
Notifications
You must be signed in to change notification settings - Fork 0
/
kakoune.nix
191 lines (177 loc) · 5.83 KB
/
kakoune.nix
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
{ pkgs, lib, ... }:
let
ghcVersion = "94";
edtiorInNewTerm = pkgs.writeShellScriptBin "edtiorInNewTerm" ''
$TERM sh -c "$EDITOR $@" &>/dev/null &
'';
kakouneDesktop = pkgs.writeTextDir "share/applications/kakoune.desktop"
(lib.generators.toINI { } {
"Desktop Entry" = {
Name = "Kakoune";
Type = "Application";
TryExec = "kak";
# TODO make this more generic. Use whatever $TERM is.
Exec = "${edtiorInNewTerm}/bin/edtiorInNewTerm %U";
# Exec = "${pkgs.bash}/bin/sh -c '$TERM kak'";
Terminal = true;
Icon = "kakoune";
Comment = "Edit text";
GenericName = "Text Editor";
StartupNotify= true;
MimeType =
"text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;text/x-haskell;text/markdown;text/x-python;application/x-yaml;application/json;text/rust;text/vnd.trolltech.linguist;application/javascript";
Catagories = "Development;TextEditor;";
StartupWMClass = "Kakoune";
};
});
nix-lsp = pkgs.nil;
tomlFormat = pkgs.formats.toml { };
kak-lsp-config = tomlFormat.generate "kak-lsp-config.toml" {
snippet_support = false;
verbosity = 2;
server = {
# In seconds
timeout = 30 * 60 * 60;
};
language = {
nix = {
filetypes = [ "nix" ];
roots = [ "flake.nix" "shell.nix" ".git" ];
command = lib.getExe nix-lsp;
};
rust = rec {
filetypes = [ "rust" ];
roots = [ "Cargo.toml" ];
command = "rust-analyzer";
settings_section = "rust-analyzer";
settings.${settings_section}.hoverActions.enable = false;
};
typescript = {
filetypes = [ "typescript" ];
roots = [ "package.json" "tsconfig.json" ];
command = "typescript-language-server";
args = [ "--stdio" ];
};
json = {
filetypes = [ "json" ];
roots = [ "packages.json" ];
command = "vscode-json-languageserver";
args = [ "--stdio" ];
};
toml = {
filetypes = [ "toml" ];
roots = [ "Cargo.toml;" ];
command = "taplo-lsp";
args = [ "run" ];
};
haskell = {
filetypes = [ "haskell" ];
roots = [ "Setup.hs" "stack.yaml" "*.cabal" "cabal.project" "hie.yaml" ];
command = "haskell-language-server";
args = [ "--lsp" ];
};
};
};
in
{
programs.kakoune = {
enable = true;
config = {
autoComplete = [ "insert" "prompt" ];
autoInfo = [ "command" "onkey" ];
autoReload = "ask";
# Indent of 2 is a haskell thing, need to set this only for haskell code.
indentWidth = 2;
showWhitespace = {
enable = true;
space = " ";
};
numberLines = {
enable = true;
highlightCursor = true;
relative = false;
};
ui = {
enableMouse = false;
setTitle = true;
assistant = "clippy";
statusLine = "bottom";
useBuiltinKeyParser = true;
};
keyMappings = [
{
key = "<c-p>";
mode = "normal";
effect = ": fzf-mode<ret>";
}
];
hooks = [
{
name = "ModuleLoaded";
option = "fzf-grep";
commands = ''
set global fzf_grep_command 'rg'
'';
}
{
name = "ModuleLoaded";
option = "fzf-file";
commands = ''
set global fzf_file_command 'rg'
set global fzf_highlight_command 'bat'
'';
}
{
name = "WinSetOption";
# Maybe can split out the list of filetypes to use lsp for to a nix list.
option = "filetype=(haskell|nix|typescript|toml|json)";
commands = "lsp-enable-window";
}
{
# Might be able to use nix to remove the repatition
name = "WinSetOption";
option = "filetype=rust";
commands = ''
set-option window indentwidth 4
# Auto-formatting on save
# TODO: Expand home-manager to allow hooks inside commands of hooks to be defined in nix.
# hook window BufWritePre .* lsp-formatting-sync
# Configure inlay hints (only on save)
hook window -group rust-inlay-hints BufWritePost .* rust-analyzer-inlay-hints
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window rust-inlay-hints
}
'';
}
];
};
extraConfig = ''
# set -add global autoinfo normal
# Only want this to be the ctagscmd when working with haskell files.
set global ctagscmd '${pkgs.haskellPackages.hasktags}/bin/hasktags -cR'
eval %sh{${pkgs.kakounePlugins.kak-lsp}/bin/kak-lsp --kakoune -s $kak_session --config ${kak-lsp-config}}
lsp-inlay-hints-enable global
lsp-auto-hover-enable
'';
# Adding something to this list only combines the derivations with kak using symlink join.
plugins = [
# kak-lsp config goes into .config/kak-lsp/kak-lsp.toml
# Or config dir can be reconfigured with kak-lsp --configure <PATH>
# It seems like there is some default config already. Maybe not actually.
# pkgs.kakounePlugins.kak-lsp
pkgs.kakounePlugins.fzf-kak
];
};
home.packages = [
(pkgs.hiPrio kakouneDesktop)
nix-lsp
pkgs.rustfmt
pkgs.rust-analyzer
pkgs.nodePackages.vscode-json-languageserver
pkgs.nodePackages.typescript-language-server
pkgs.taplo-lsp
pkgs.haskell.packages."ghc${ghcVersion}".haskell-language-server
(pkgs.haskell.lib.compose.justStaticExecutables pkgs.haskell.packages."ghc${ghcVersion}".cabal-install)
pkgs.haskell.compiler."ghc${ghcVersion}"
];
}