develop: init kakoune profile

This commit is contained in:
Timothy DeHerrera 2019-12-15 00:03:57 -07:00
parent 6b26ef84a8
commit 95741bbfce
No known key found for this signature in database
GPG Key ID: 8985725DB5B0C122
13 changed files with 217 additions and 0 deletions

View File

@ -2,11 +2,18 @@
{
imports = [
./zsh
./kakoune
];
environment.shellAliases = {
v = "XDG_CONFIG_HOME=/etc/xdg $EDITOR";
};
environment.sessionVariables = {
LESS = "-iFJMRWX -z-4 -x4";
LESSOPEN = "|${pkgs.lesspipe}/bin/lesspipe.sh %s";
EDITOR = "kak";
VISUAL = "kak";
};
environment.systemPackages = with pkgs; [

View File

@ -0,0 +1,46 @@
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
cquery
kak-lsp
kakoune
kakoune-unwrapped
nixpkgs-fmt
python3Packages.python-language-server
rustup
];
environment.etc = {
"xdg/kak/kakrc".source = ./kakrc;
"xdg/kak/autoload/plugins".source = ./plugins;
"xdg/kak/autoload/lint".source = ./lint;
"xdg/kak/autoload/lsp".source = ./lsp;
"xdg/kak/autoload/default".source = "${pkgs.kakoune-unwrapped}/share/kak/rc";
};
nixpkgs.overlays = let
kak = self: super: {
kakoune = super.kakoune.override {
configure.plugins = with super.kakounePlugins; [
(kak-fzf.override { fzf = super.skim; })
kak-auto-pairs
kak-buffers
kak-powerline
];
};
kakoune-unwrapped = super.kakoune-unwrapped.overrideAttrs (
o: rec {
version = "2019.12.10";
src = super.fetchFromGitHub {
repo = "kakoune";
owner = "mawww";
rev = "v${version}";
hash = "sha256-TnRQ73bIQGavXNp+wrKtYHgGem+R6JDWt333z2izYzE=";
};
}
);
};
in
[ kak ];
}

View File

@ -0,0 +1,99 @@
hook global WinCreate ^[^*]+$ %{ add-highlighter window/ number-lines }
# colorscheme
face global Information yellow,default
face global MenuBackground black,white
face global MenuForeground white,black
face global comment white+d
face global meta blue
addhl global/ column 80 SecondaryCursor
# convert tabs to spaces and cleanup trailing whitespace on save
hook global BufWritePre ^[^*]+$ %{
try %{ execute-keys -draft \%@s\h+$<ret>d }
}
# useful mappings
map global normal <a-q> ': delete-buffer<ret>'
map global normal <c-s> ': write<ret>'
map global normal <c-q> ': quit<ret>'
map global normal <c-a-n> ': buffer-next<ret>'
map global normal <c-a-p> ': buffer-previous<ret>'
map global -docstring "comment line" user c ': comment-line<ret>'
map global -docstring "comment block" user C ': comment-block<ret>'
map -docstring "format buffer" global user f ': format<ret>'
# splits just like vim using tmux
define-command -params 0.. -file-completion \
-docstring "split tmux pane vertically" split \
%{ tmux-terminal-vertical kak -c %val{session} -e edit! %arg{@} }
define-command -params 0.. -file-completion \
-docstring "split tmux pane horizontally" vsplit \
%{ tmux-terminal-horizontal kak -c %val{session} -e edit! %arg{@} }
alias global sp split
alias global vs vsplit
# jj to leave insert mode
hook global InsertChar j %{ try %{
exec -draft hH <a-k>jj<ret> d
exec <esc>
}}
set global ui_options ncurses_assistant=none
set global tabstop 2
set global indentwidth 2
hook global InsertCompletionShow .* %{
try %{
# this command temporarily removes cursors preceded by whitespace;
# if there are no cursors left, it raises an error, does not
# continue to execute the mapping commands, and the error is eaten
# by the `try` command so no warning appears.
execute-keys -draft 'h<a-K>\h<ret>'
map window insert <tab> <c-n>
map window insert <s-tab> <c-p>
}
}
hook global InsertCompletionHide .* %{
unmap window insert <tab> <c-n>
unmap window insert <s-tab> <c-p>
}
try %{ require-module kak }
add-highlighter shared/kakrc/code/if_else regex \b(if|else)\b 0:keyword
# create an if for conditional parsing
define-command -docstring "if <condition> <expression> [else [if <condition>] <expression>]: if statement that accepts shell-valid condition string" \
if -params 2.. %{ evaluate-commands %sh{
while [ true ]; do
condition="[ $1 ]"
if [ -n "$3" ] && [ "$3" != "else" ]; then
printf "%s\n" "fail %{if: unknown operator '$3'}"
elif [ $# -eq 3 ]; then
printf "%s\n" "fail %{if: wrong argument count}"
elif eval $condition; then
[ -n "${2##*&*}" ] && arg="$2" || arg="$(printf '%s' "$2" | sed 's/&/&&/g')"
printf "%s\n" "evaluate-commands %& $arg &"
elif [ $# -eq 4 ]; then
[ -n "${4##*&*}" ] && arg="$4" || arg="$(printf '%s' "$4" | sed 's/&/&&/g')"
printf "%s\n" "evaluate-commands %& $arg &"
elif [ $# -gt 4 ]; then
if [ "$4" = "if" ]; then
shift 4
continue
else
printf "%s\n" "fail %{if: wrong argument count}"
fi
fi
exit
done
}}
# show git diff on sidebar if it git repository
if %[ "$(command git status 2>/dev/null)" ] %{
hook global WinCreate .* %{ git show-diff }
hook global BufWritePost .* %{ git show-diff }
hook global ModeChange insert:normal %{ git show-diff }
}

View File

@ -0,0 +1,20 @@
hook -group lint global WinSetOption filetype=nix %{
# remove '' for nix, annoying for string literals
set buffer auto_pairs ( ) { } [ ] '"' '"' ` `
set buffer lintcmd '
run () {
nix-instantiate --parse $1 2>&1 >&- > /dev/null |
awk ''
{printf $NF ":" " "}
!($NF="") !($(NF-1)="") {sub(/, $/, "")}1
''
} && run \
'
lint-enable
set buffer formatcmd "nixpkgs-fmt"
hook buffer BufWritePre .* %{
format
lint
}
}

View File

@ -0,0 +1,3 @@
hook -group lsp global WinSetOption filetype=(c|cpp) %{
lsp-enable-window
}

View File

@ -0,0 +1,10 @@
eval %sh{kak-lsp --kakoune -s $kak_session}
hook -group lsp global WinSetOption filetype=(elm|rust|c|cpp|python) %{
lsp-auto-hover-enable
# easily enter lsp mode
map -docstring "language-server mode" buffer user l ': enter-user-mode lsp<ret>'
set buffer lsp_hover_anchor true
set buffer lsp_auto_highlight_references true
}

View File

@ -0,0 +1,5 @@
# elm formating is currently broken in els so use formatcmd as workaround
hook -group lsp global WinSetOption filetype=elm %{
set buffer formatcmd "elm-format --stdin --yes --elm-version 0.19"
lsp-enable-window
}

View File

@ -0,0 +1,3 @@
hook -group lsp global WinSetOption filetype=python %{
lsp-enable-window
}

View File

@ -0,0 +1,10 @@
hook -group lsp global WinSetOption filetype=rust %{
# racer.kak conflicts with rls completion; keep before lsp-enable
racer-disable-autocomplete
# remove apostrophe from auto closing pairs; annoying for rust lifetimes
set buffer auto_pairs ( ) { } [ ] '"' '"' ` `
lsp-enable-window
set buffer lsp_server_configuration rust.clippy_preference="on"
}

View File

@ -0,0 +1,6 @@
hook global WinCreate .* %{
auto-pairs-enable
}
map global user s -docstring 'Surround' ': auto-pairs-surround <lt> <gt><ret>'
map global user S -docstring 'Surround++' ': auto-pairs-surround <lt> <gt> _ _ * *<ret>'

View File

@ -0,0 +1,4 @@
hook global WinDisplay .* info-buffers
map global user b ':enter-buffers-mode<ret>' -docstring 'buffers…'
map global user B ':enter-user-mode -lock buffers<ret>' -docstring 'buffers (lock)…'

View File

@ -0,0 +1 @@
map -docstring "fzf-mode" global normal <c-p> ': fzf-mode<ret>'

View File

@ -0,0 +1,3 @@
map -docstring "vertical selection down" global user v ': vertical-selection-down<ret>'
map -docstring "vertical selection up" global user <a-v> ': vertical-selection-up<ret>'
map -docstring "vertical selection both" global user V ': vertical-selection-up-and-down<ret>'