From a8745a54ecef1dec8bacea7b4ddb1d07232c8c20 Mon Sep 17 00:00:00 2001 From: Davide Oddone Date: Tue, 8 Aug 2023 22:09:42 +0200 Subject: [PATCH] Initial commit for kakrc --- .gitignore | 1 + kakrc | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 .gitignore create mode 100644 kakrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16873f6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +plugins/ diff --git a/kakrc b/kakrc new file mode 100644 index 0000000..3c5c810 --- /dev/null +++ b/kakrc @@ -0,0 +1,122 @@ +# Load plug.kak +source "%val{config}/plugins/plug.kak/rc/plug.kak" +plug "andreyorst/plug.kak" noload +# plug kak-lsp +plug "kak-lsp/kak-lsp" do %{ + cargo build --release --locked + cargo install --force --path . +} config %{ + + # uncomment to enable debugging + # eval %sh{echo ${kak_opt_lsp_cmd} >> /tmp/kak-lsp.log} + # set global lsp_cmd "kak-lsp -s %val{session} -vvv --log /tmp/kak-lsp.log" + + # this is not necessary; the `lsp-enable-window` will take care of it + # eval %sh{${kak_opt_lsp_cmd} --kakoune -s $kak_session} + + set global lsp_diagnostic_line_error_sign '║' + set global lsp_diagnostic_line_warning_sign '┊' + + define-command ne -docstring 'go to next error/warning from lsp' %{ lsp-find-error --include-warnings } + define-command pe -docstring 'go to previous error/warning from lsp' %{ lsp-find-error --previous --include-warnings } + define-command ee -docstring 'go to current error/warning from lsp' %{ lsp-find-error --include-warnings; lsp-find-error --previous --include-warnings } + + define-command lsp-restart -docstring 'restart lsp server' %{ lsp-stop; lsp-start } + hook global WinSetOption filetype=(c|cpp|cc|rust|javascript|typescript) %{ + set-option window lsp_auto_highlight_references true + set-option window lsp_hover_anchor false + lsp-auto-hover-enable + echo -debug "Enabling LSP for filtetype %opt{filetype}" + lsp-enable-window + } + + hook global WinSetOption filetype=(rust) %{ + set window lsp_server_configuration rust.clippy_preference="on" + } + + hook global WinSetOption filetype=rust %{ + hook window BufWritePre .* %{ + evaluate-commands %sh{ + test -f rustfmt.toml && printf lsp-formatting-sync + } + } + } + + hook global KakEnd .* lsp-exit +} +# Substitute c-n with tab +hook global InsertCompletionShow .* %{ + try %{ + execute-keys -draft 'h\h' + map window insert + map window insert + hook -once -always window InsertCompletionHide .* %{ + map window insert + map window insert + } + } +} +# enable auto pair closing +enable-auto-pairs +# yaml linter +hook global WinSetOption filetype=yaml %{ + # set-option window lintcmd "yamllint -f parsable" + set-option window lintcmd %{ + run() { + # change [message-type] to message-type: + yamllint -f parsable "$1" | sed 's/ \[\(.*\)\] / \1: /' + } && run } +} +# yaml formatter +hook global WinSetOption filetype=yaml %{ + set window formatcmd 'prettier --parser yaml' +} +# C linter +hook global WinSetOption filetype=c %{ + set-option window lintcmd "cppcheck --language=c --enable=warning,style,information --template='{file}:{line}:{column}: {severity}: {message}' --suppress='*:*.h' 2>&1" +} +# C formatter +hook global BufSetOption filetype=c %{ + set-option buffer formatcmd 'astyle' +} + +set global indentwidth 4 +set global tabstop 4 +add-highlighter global/ number-lines +add-highlighter global/ wrap + +# system clipboard usermode +map global user y 'xclip -in -selection clipboard >&- 2>&-' \ +-docstring 'Copy selected text to system clipboard' +map global user P '!xclip -out -selection clipboard' \ +-docstring 'Paste system clipboard before' +map global user p 'xclip -out -selection clipboard' \ +-docstring 'Paste system clipboard after' +map global user R '|xclip -out -selection clipboard' \ +-docstring 'Replace selection from system clipboard' + +## TESTING: copy and paste from TMUX +#if [ -n "$DISPLAY" ]; then +## printf %s "$kak_main_reg_dquote" | xsel --input --clipboard +#elif [ -n "$TMUX" ]; then +# map global user y 'tmux set-buffer --' +#fi +## Enable different options depending if we are inside TMUX or not +#try %{ +# evaluate-commands %sh{ [ $tmux ] || echo "fail" } +# try %{ +# hook global registermodified '"' %{ nop %sh{ +# tmux set-buffer -- "$kak_main_reg_dquote" +# }} +# map global user p '!tmux show-buffer' +# map global user p 'tmux show-buffer' +# map global user r '|tmux show-buffer' +# } +#} catch %{ +# try %{ +# map global user y 'xclip -in -selection clipboard >&- 2>&-' +# map global user p '!xclip -out -selection clipboard' +# map global user p 'xclip -out -selection clipboard' +# map global user r '|xclip -out -selection clipboard' +# } +#}