config/modules/kak/kakrc.nix

224 lines
6.5 KiB
Nix
Raw Permalink Normal View History

2022-05-15 23:32:21 +02:00
# Defines the kakrc.
{
# Feature flags
2022-06-22 16:51:02 +02:00
clipboard ? false,
2022-05-15 23:32:21 +02:00
typescript ? false,
haskell ? false,
2022-06-22 16:51:02 +02:00
clojure ? false,
2022-05-15 23:32:21 +02:00
python ? false,
rust ? false,
nix ? true,
# Color theme
theme,
# Build tools
pkgs,
lib,
}:
2022-05-16 17:44:49 +02:00
let keybinds = ''
2022-05-23 13:17:26 +02:00
map global insert <a-tab> <esc>:buffer-next<ret>
map global normal <a-tab> :buffer-next<ret>
2022-06-22 16:51:02 +02:00
'' + (lib.optionalString clipboard ''
map global user y <a-|>c<ret>
map global user p !p<ret>
'');
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
# Initialization code for IDE mode needed for every supported
# language, and inlay diagnostics.
2022-05-16 17:44:49 +02:00
ide-init = ''
lsp-enable-window
2022-05-15 23:32:21 +02:00
2022-05-23 13:28:54 +02:00
hook window ModeChange .*:.*:insert %{
2022-05-23 13:55:47 +02:00
lsp-inlay-diagnostics-disable window
2022-05-23 13:28:54 +02:00
remove-highlighter window/lsp_diagnostics
}
hook window ModeChange .*:insert:normal %{
lsp-inlay-diagnostics-enable window
}
2022-05-16 17:57:58 +02:00
'';
2022-05-23 13:17:26 +02:00
# Implies `ide-init`. Adds code actions and hover.
2022-05-16 17:57:58 +02:00
ide-core = ''
2022-05-23 13:17:26 +02:00
${ide-init}
2022-05-16 17:57:58 +02:00
2022-05-16 17:44:49 +02:00
map buffer normal <tab> ': lsp-code-actions<ret>'
map buffer normal <ret> ': lsp-hover<ret>'
2022-05-15 23:32:21 +02:00
'';
2022-05-23 13:17:26 +02:00
# Implies `ide-core`, which implies `ide-init`.
ide-full = ''
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
${ide-core}
hook window -group semtok BufReload .* lsp-semantic-tokens
hook window -group semtok NormalIdle .* lsp-semantic-tokens
hook window -group semtok InsertIdle .* lsp-semantic-tokens
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window semtok }
2022-05-16 17:44:49 +02:00
2022-06-18 10:00:51 +02:00
map global normal <up> ': lsp-previous-symbol<ret>'
map global normal <down> ': lsp-next-symbol<ret>'
map global normal <a-down> ': lsp-hover-next-symbol<ret>'
map global normal <a-up> ': lsp-hover-previous-symbol<ret>'
2022-05-16 17:44:49 +02:00
map global normal <a-left> ': lsp-previous-location *goto*<ret>'
2022-06-18 10:00:51 +02:00
map global normal <a-right> ': lsp-next-location *goto*<ret>'
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
''; in
2022-05-16 17:44:49 +02:00
# Nix hacking-related configuration. Nix has a very weak language
# server, and it basically only supports `ide-init` (for completions).
let nix-config = (lib.optionalString nix ''
hook global WinSetOption filetype=nix %{
${ide-init}
2022-07-25 22:01:42 +02:00
face global keyword rgb:${theme.cyan.normal}
2022-05-16 17:44:49 +02:00
}
'');
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
# Sometimes work requires me to touch the frontend. Ew. `ide-core`
# suffices here.
2022-05-23 13:17:26 +02:00
typescript-config = (lib.optionalString typescript ''
2022-05-16 17:44:49 +02:00
hook global WinSetOption filetype=(javascript|typescript) %{
${ide-core}
}
2022-05-15 23:32:21 +02:00
'');
2022-05-16 17:44:49 +02:00
# Python-related config. Python does not support more features than
# those in `ide-core`.
python-config = (lib.optionalString python ''
2022-05-23 13:17:26 +02:00
hook global WinSetOption filetype=python %{
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
${ide-core}
2022-05-15 23:32:21 +02:00
2022-05-19 19:58:26 +02:00
face window keyword rgb:${theme.green.bright}
2022-05-16 17:44:49 +02:00
face window meta keyword
2022-05-23 13:17:26 +02:00
}
2022-05-15 23:32:21 +02:00
'');
2022-06-22 16:51:02 +02:00
# Clojure-lsp has all the IDE features I use.
clojure-config = (lib.optionalString clojure ''
hook global WinSetOption filetype=clojure %{
${ide-full}
}
'');
2022-05-16 17:44:49 +02:00
# Haskell development. Haskell has a language server with
# the features in `ide-full`.
2022-05-15 23:32:21 +02:00
haskell-config = (lib.optionalString haskell ''
2022-05-23 13:17:26 +02:00
hook global WinSetOption filetype=haskell %{
2022-05-15 23:32:21 +02:00
2022-05-23 13:17:26 +02:00
${ide-full}
set-option buffer tabstop 2
2022-05-15 23:32:21 +02:00
2022-05-19 19:58:26 +02:00
face global variable rgb:${theme.purple.normal}
2022-05-16 17:44:49 +02:00
face global attribute keyword
face global operator keyword
2022-05-19 19:58:26 +02:00
face global keyword rgb:${theme.blue.bright}
2022-05-16 17:44:49 +02:00
face global value string
2022-05-19 19:58:26 +02:00
face global meta rgb:${theme.pink.normal}
2022-05-15 23:32:21 +02:00
2022-05-23 13:17:26 +02:00
}
2022-05-15 23:32:21 +02:00
'');
2022-05-16 17:44:49 +02:00
# Rust development. Rust's language servers all support the
# `ide-full` features.
2022-05-15 23:32:21 +02:00
rust-config = (lib.optionalString rust ''
2022-05-23 13:17:26 +02:00
hook global WinSetOption filetype=rust %{
${ide-full}
2022-05-15 23:32:21 +02:00
2022-05-23 13:17:26 +02:00
hook global -group yeet ModuleLoaded rust %{
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
# Override the Rust highlighting with semantic
# tokens supplied by the LSP client
remove-hooks global rust-highlight
remove-highlighter shared/rust
2022-05-15 23:32:21 +02:00
2022-05-23 13:17:26 +02:00
# Request tokens
lsp-semantic-tokens
2022-05-15 23:32:21 +02:00
2022-05-23 13:17:26 +02:00
# Self-destruct this hook (it should only run once)
remove-hooks global yeet
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
}
2022-05-16 17:44:49 +02:00
2022-06-18 10:00:51 +02:00
hook global NormalIdle .* %{ lsp-highlight-references }
hook global InsertMove .* %{ lsp-highlight-references }
2022-07-25 22:01:42 +02:00
face global type rgb:${theme.blue.normal}
face global trait rgb:${theme.purple.normal}
2022-06-18 10:00:51 +02:00
face global macro rgb:${theme.green.bright}
2022-07-25 22:01:42 +02:00
face global format rgb:${theme.orange.bright}
2022-06-18 10:00:51 +02:00
face global attribute rgb:${theme.orange.bright}
face global operator rgb:${theme.yellow.normal}
face global function rgb:${theme.green.bright}
face global keyword rgb:${theme.misc.blueGrey}
2022-07-25 22:01:42 +02:00
face global variable white
face global value white
face global meta white
2022-06-18 10:00:51 +02:00
face global alias rgb:${theme.orange.normal}
face global enum type
face global struct type
face global union type
face global lifetime rgb:${theme.pink.pastel}
face global module rgb:ffffff
2022-05-23 13:17:26 +02:00
}
2022-05-15 23:32:21 +02:00
'');
in pkgs.writeTextFile (rec {
2022-05-23 13:17:26 +02:00
name = "kakrc.kak";
2022-05-15 23:32:21 +02:00
destination = "/share/kak/autoload/${name}";
2022-05-19 19:58:26 +02:00
text = ''
2022-05-23 13:17:26 +02:00
set global tabstop 4
2022-05-23 13:33:12 +02:00
set global indentwidth 4
2022-05-15 23:32:21 +02:00
2022-05-23 13:28:54 +02:00
eval %sh{ kak-lsp --kakoune -s $kak_session }
2022-05-23 13:17:26 +02:00
add-highlighter global/ number-lines -separator ' ' -hlcursor
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
face global InlayHint rgb:828282
face global InlayDiagnosticWarning rgb:a39e31+f
face global InlayDiagnosticError rgb:ad494f+f
face global InlayDiagnosticHint rgb:4d965a+f
face global InlayDiagnosticInfo rgb:4d965a+f
2022-05-16 17:44:49 +02:00
hook global WinSetOption filetype=markdown %{
hook window -group spellck BufReload .* spell
hook window -group spellck NormalIdle .* spell
hook window -group spellck InsertIdle .* spell
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window spellck
}
}
2022-05-23 13:17:26 +02:00
${keybinds}
2022-05-19 19:58:26 +02:00
${typescript-config}
${haskell-config}
2022-06-22 16:51:02 +02:00
${clojure-config}
2022-05-19 19:58:26 +02:00
${python-config}
${rust-config}
${nix-config}
2022-05-23 13:28:54 +02:00
hook global KakBegin .* %{
cursorline
colorscheme colors
}
2022-05-19 19:58:26 +02:00
'';
2022-05-15 23:32:21 +02:00
})