/
kakoune.nix
263 lines (241 loc) · 7.77 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
{ pkgs, lib, ... }:
let
sources = import ../nix/sources.nix;
nixpkgs = import sources.nixpkgs { };
kakoune = import ../lib/kakoune.nix {
pkgs = nixpkgs.pkgs;
lib = nixpkgs.lib;
};
similar-sort = pkgs.callPackage ../pkgs/similar-sort { };
similar-sort-files-cmd = arg:
"git ls-files --others --cached --exclude-standard | ${similar-sort}/bin/similar-sort ${arg} | fzf --tiebreak index";
# plugins
pluginSources = lib.filterAttrs
(_: source: lib.attrByPath [ "kakoune" ] "" source == "plugin") sources;
colorSources = lib.filterAttrs
(_: source: lib.attrByPath [ "kakoune" ] "" source == "colors") sources;
pluginAttrs = lib.mapAttrs (name: source:
kakoune.mkPlugin {
name = name;
src = source;
}) pluginSources;
plugins = (lib.mapAttrsToList (_: plugin: plugin) pluginAttrs) ++ [ ];
colorAttrs = lib.mapAttrs (name: source:
kakoune.mkColorPlugin {
name = name;
src = source;
}) colorSources;
colors = lib.mapAttrsToList (_: color: color) colorAttrs;
in {
home.packages =
[ pkgs.shellcheck (pkgs.callPackages ../pkgs/kak-session { }) ];
programs.kakoune = {
enable = true;
config = {
colorScheme = "lucius";
scrollOff = {
columns = 0;
lines = 5;
};
numberLines = {
enable = true;
separator = ''" "'';
};
showMatching = true;
ui.enableMouse = true;
ui.assistant = "clippy";
wrapLines = {
enable = true;
indent = true;
marker = "⎁";
};
# hooks = [
# # Elm
# {
# name = "WinCreate";
# option = ".*.elm";
# commands = ''
# evaluate-commands %sh{
# if which elm-format > /dev/null; then
# echo 'set-option buffer formatcmd "elm-format --stdin"'
# fi
# }
# '';
# }
# {
# commands = "format";
# name = "BufWritePre";
# option = ".*.elm";
# }
# # Haskell
# {
# name = "WinCreate";
# option = ".*.hs";
# commands = ''
# evaluate-commands %sh{
# if which ormolu > /dev/null; then
# echo 'set-option buffer formatcmd ormolu'
# fi
# }
# '';
# }
# {
# commands = "format";
# name = "BufWritePre";
# option = ".*.hs";
# }
# # Python
# {
# name = "WinCreate";
# option = ".*.py";
# commands = ''
# evaluate-commands %sh{
# if which black > /dev/null; then
# echo 'set-option buffer formatcmd "black - --quiet --fast"'
# fi
# }
# '';
# }
# {
# commands = "format";
# name = "BufWritePre";
# option = ".*.py";
# }
# # JavaScript
# {
# name = "WinCreate";
# option = ".*.js";
# commands = ''
# evaluate-commands %sh{
# if which prettier > /dev/null; then
# echo 'set-option buffer formatcmd "prettier --parser=typescript"'
# fi
# }
# '';
# }
# # Indents
# {
# name = "WinCreate";
# option = ".*.(rb|hs)";
# commands = ''
# expandtab
# set-option buffer tabstop 2
# set-option buffer softtabstop 2
# '';
# }
# {
# name = "WinCreate";
# option = ".*.elm";
# commands = ''
# expandtab
# set-option buffer tabstop 4
# set-option buffer softtabstop 4
# '';
# }
# # kakboard
# {
# name = "WinCreate";
# option = ".*";
# commands = "kakboard-enable";
# }
# ];
# keyMappings = [
# # git browsing
# {
# mode = "goto";
# key = "u";
# effect = "<esc>: git next-hunk<ret>";
# docstring = "next hunk";
# }
# {
# mode = "goto";
# key = "<a-u>";
# effect = "<esc>: git prev-hunk<ret>";
# docstring = "previous hunk";
# }
# # file browsing
# {
# mode = "normal";
# key = "_";
# effect =
# ": connect-terminal sh -c %{ ranger --choosefile=/tmp/magic-file-selector $(dirname $1); if test -f /tmp/magic-file-selector; then edit $(cat /tmp/magic-file-selector); rm /tmp/magic-file-selector; fi } -- %val{bufname}<ret>";
# }
# {
# mode = "normal";
# key = "<minus>";
# effect = ": connect-terminal sh -c %{ edit $(${
# similar-sort-files-cmd "$1"
# }) } -- %val{bufname}<ret>";
# }
# {
# mode = "normal";
# key = "<a-minus>";
# effect =
# ": connect-terminal sh -c %{ buffer $(buffer | ${similar-sort}/bin/similar-sort $1 | fzf --tiebreak=index) } -- %val{bufname}<ret>";
# }
# # vertical selection
# {
# mode = "user";
# key = "v";
# effect = ": vertical-selection-down<ret>";
# docstring = "vertical selection down";
# }
# {
# mode = "user";
# key = "<a-v>";
# effect = ": vertical-selection-up<ret>";
# docstring = "vertical selection up";
# }
# {
# mode = "user";
# key = "V";
# effect = ": vertical-selection-up-and-down<ret>";
# docstring = "vertical selection up and down";
# }
# ];
};
extraConfig = ''
declare-user-mode surround
map global surround s ': surround<ret>' -docstring 'Surround'
map global surround c ': change-surround<ret>' -docstring 'Change'
map global surround d ': delete-surround<ret>' -docstring 'Delete'
map global surround t ': select-surrounding-tag<ret>' -docstring 'Select tag'
map global user s ':enter-user-mode surround<ret>' -docstring 'Surround'
declare-user-mode window
map global user w ': enter-user-mode window<ret>' -docstring 'Windowing'
map global window v ': tmux-terminal-horizontal sh -c %{ kak -c $1 $(${
similar-sort-files-cmd "$2"
}) } -- %val{session} %val{bufname}<ret>' -docstring "vertical split with fzf"
map global window <a-v> ': tmux-terminal-horizontal sh -c %{ kak -c $1 } -- %val{session}<ret>' -docstring "vertical split"
map global window s ': tmux-terminal-vertical sh -c %{ kak -c $1 $(${
similar-sort-files-cmd "$2"
}) } -- %val{session} %val{bufname}<ret>' -docstring "horizontal split with fzf"
map global window <a-s> ': tmux-terminal-vertical sh -c %{ kak -c $1 } -- %val{session}<ret>' -docstring "horizontal split"
# escape with fd
hook global InsertChar d %{ try %{
exec -draft hH <a-k>fd<ret> d
exec <esc>
}}
# automatically create directories on save
hook global BufWritePre .* %{ mkdir %val{bufname} }
# Git status
hook global WinSetOption filetype=.+ %{ git show-diff }
hook global BufWritePost .* %{ git update-diff }
hook global BufReload .* %{ git update-diff }
# TODO: NormalIdle?
## LANGUAGES
# Nix
hook global WinSetOption filetype=nix %{
set-option buffer formatcmd nixfmt
set-option buffer tabstop 2
hook buffer BufWritePre .* format
}
'';
};
# plugins
home.file.".config/kak/colors".source =
"${kakoune.mkColors colors}/share/kak/colors";
home.file.".config/kak/autoload".source =
"${kakoune.mkPlugins plugins}/share/kak/autoload";
home.file.".config/kak/kak-tree.toml".text = "";
}