{ lib, pkgs, config, ... }: let kakrc = pkgs.writeTextFile (rec { name = "kakrc.kak"; destination = "/share/kak/autoload/${name}"; text = with config.riley.theme; '' # Line numbering add-highlighter global/ number-lines -separator ' │ ' -hlcursor # Setting the tabstop to 4 (even though I have an ultrawide monitor) set-option global tabstop 4 set global ui_options ncurses_assistant=cat # Use Alt-Tab to switch between open buffers map global insert :buffer-next map global normal :buffer-next def new-tab %{ prompt -file-completion '>' 'terminal kak -c %val{session} %val{text}' } map global normal ': new-tab' colorscheme common face global LineNumbers rgb:${background.slight} face global BufferPadding rgb:${background.slight} face global LineNumberCursor rgb:${foreground.primary} face global crosshairs_line "default,rgb:${background.normal}" face global MenuForeground "default,blue" face global MenuBackground "default,rgb:313131" face global InlayHint rgb:828282 face global comment rgb:${foreground.slight} '' + (lib.optionalString (config.riley.kak.ide) '' eval %sh{ kak-lsp --kakoune -s $kak_session } hook global -group yeet ModuleLoaded rust %{ # Override the Rust highlighting with semantic # tokens supplied by the LSP client remove-hooks global rust-highlight remove-highlighter shared/rust # Request tokens lsp-semantic-tokens # Self-destruct this hook (it should only run once) remove-hooks global yeet } # Load language-specific color schemes hook global WinSetOption filetype=(haskell) %{ colorscheme haskell lsp-enable-window lsp-inlay-diagnostics-enable window map global normal ': lsp-code-actions' map global normal ': lsp-hover' hook window ModeChange .*:.*:insert %{ remove-highlighter window/lsp_diagnostics } hook window ModeChange .*:insert:normal %{ lsp-inlay-diagnostics-enable window } set global lsp_inlay_diagnostic_sign '>' map global insert '' } hook global WinSetOption filetype=(rust) %{ lsp-enable-window lsp-inlay-diagnostics-enable window colorscheme rust git show-diff hook buffer BufReload .* %{ git update-diff } hook buffer NormalIdle .* %{ git update-diff } hook buffer InsertIdle .* %{ git update-diff } hook window -group semtok BufReload .* lsp-semantic-tokens hook window -group semtok NormalIdle .* lsp-semantic-tokens hook window -group semtok InsertIdle .* lsp-semantic-tokens hook -once -always window WinSetOption filetype=.* %{ remove-hooks window semtok } hook window ModeChange .*:.*:insert %{ remove-highlighter window/lsp_diagnostics } hook window ModeChange .*:insert:normal %{ lsp-inlay-diagnostics-enable window } set global lsp_inlay_diagnostic_sign '>' map global normal ': lsp-code-actions' map global normal ': lsp-hover' } hook global WinSetOption filetype=(nix) %{ colorscheme nix lsp-enable-window } face global InlayDiagnosticWarning rgb:a39e31+f face global InlayDiagnosticError rgb:ad494f+f face global InlayDiagnosticHint rgb:4d965a+f face global InlayDiagnosticInfo rgb:4d965a+f ''); }); # Syntax colors colors = (import ./colors { theme = config.riley.theme; inherit lib pkgs; }); in with lib; { options.riley = { kak.enable = (mkEnableOption "kakoune editor") // { default = true; }; kak.ide = mkEnableOption "kakoune with ide plugins"; }; config = mkIf (config.riley.kak.enable || config.riley.kak.ide) { environment.systemPackages = with pkgs; [ (pkgs.kakoune.override { plugins = [ # Custom config kakrc ] ++ (lib.optionals config.riley.kak.ide (import ./lsp.nix { inherit pkgs lib config; })) ++ colors; }) ]; }; }