From 596456c2b6e75b14cc02a519a96ab1a5135a9796 Mon Sep 17 00:00:00 2001 From: koehr Date: Tue, 3 Sep 2019 17:47:15 +0200 Subject: [PATCH] update kakoune config --- dot.config/kak/autoload/autoload | 1 - dot.config/kak/autoload/buffers.kak | 235 +++++++++++++++++++- dot.config/kak/autoload/explore-buffers.kak | 58 +++++ dot.config/kak/autoload/explore-files.kak | 136 +++++++++++ dot.config/kak/autoload/registers.kak | 27 +++ dot.config/kak/autoload/replace.kak | 19 ++ dot.config/kak/autoload/stuff.kak | 76 ++++++- dot.config/kak/autoload/todotxt.kak | 65 +++++- dot.config/kak/autoload/vue.kak | 77 +++++++ dot.config/kak/autoload/wiki.kak | 117 +++++++++- dot.config/kak/kakrc | 8 - 11 files changed, 800 insertions(+), 19 deletions(-) delete mode 120000 dot.config/kak/autoload/autoload mode change 120000 => 100644 dot.config/kak/autoload/buffers.kak create mode 100644 dot.config/kak/autoload/explore-buffers.kak create mode 100644 dot.config/kak/autoload/explore-files.kak create mode 100644 dot.config/kak/autoload/registers.kak create mode 100644 dot.config/kak/autoload/replace.kak mode change 120000 => 100644 dot.config/kak/autoload/todotxt.kak create mode 100644 dot.config/kak/autoload/vue.kak mode change 120000 => 100644 dot.config/kak/autoload/wiki.kak diff --git a/dot.config/kak/autoload/autoload b/dot.config/kak/autoload/autoload deleted file mode 120000 index f230b50..0000000 --- a/dot.config/kak/autoload/autoload +++ /dev/null @@ -1 +0,0 @@ -/home/nk/.local/share/kak/autoload \ No newline at end of file diff --git a/dot.config/kak/autoload/buffers.kak b/dot.config/kak/autoload/buffers.kak deleted file mode 120000 index 9c9c740..0000000 --- a/dot.config/kak/autoload/buffers.kak +++ /dev/null @@ -1 +0,0 @@ -/home/nk/src/pkg/kakoune-buffers/buffers.kak \ No newline at end of file diff --git a/dot.config/kak/autoload/buffers.kak b/dot.config/kak/autoload/buffers.kak new file mode 100644 index 0000000..d71d8d6 --- /dev/null +++ b/dot.config/kak/autoload/buffers.kak @@ -0,0 +1,234 @@ +# buflist++: names AND modified bool +# debug buffers (like *debug*, *lint*…) are excluded +declare-option -hidden str-list buffers_info + +declare-option int buffers_total + +# keys to use for buffer picking +declare-option str buffer_keys "1234567890qwertyuiopasdfghjklzxcvbnm" + +# used to handle [+] (modified) symbol in list +define-command -hidden refresh-buffers-info %{ + set-option global buffers_info + set-option global buffers_total 0 + # iteration over all buffers (except debug ones) + evaluate-commands -no-hooks -buffer * %{ + set-option -add global buffers_info "%val{bufname}_%val{modified}" + } + evaluate-commands %sh{ + total=$(printf '%s\n' "$kak_opt_buffers_info" | tr ' ' '\n' | wc -l) + printf '%s\n' "set-option global buffers_total $total" + } +} + +# used to handle # (alt) symbol in list +declare-option str alt_bufname +declare-option str current_bufname +# adjust this number to display more buffers in info +declare-option int max_list_buffers 42 + +hook global WinDisplay .* %{ + set-option global alt_bufname %opt{current_bufname} + set-option global current_bufname %val{bufname} +} + +define-command info-buffers -docstring 'populate an info box with a numbered buffers list' %{ + refresh-buffers-info + evaluate-commands %sh{ + # info title + printf "info -title '$kak_opt_buffers_total buffers' -- %%^" + + index=0 + eval "set -- $kak_opt_buffers_info" + while [ "$1" ]; do + # limit lists too big + index=$(($index + 1)) + if [ "$index" -gt "$kak_opt_max_list_buffers" ]; then + printf ' …' + break + fi + + name=${1%_*} + if [ "$name" = "$kak_bufname" ]; then + printf "> %s" "$index - $name" + elif [ "$name" = "$kak_opt_alt_bufname" ]; then + printf "# %s" "$index - $name" + else + printf " %s" "$index - $name" + fi + + modified=${1##*_} + if [ "$modified" = true ]; then + printf " [+]" + fi + echo + shift + done + printf ^\\n + } +} + +declare-user-mode pick-buffers +define-command pick-buffers -docstring 'enter buffer pick mode' %{ + refresh-buffers-info + unmap global pick-buffers + evaluate-commands %sh{ + index=0 + keys=" $kak_opt_buffer_keys" + num_keys=$(($(echo "$kak_opt_buffer_keys" | wc -m) - 1)) + eval "set -- $kak_opt_buffers_info" + while [ "$1" ]; do + # limit lists too big + index=$(($index + 1)) + if [ "$index" -gt "$num_keys" ]; then + break + fi + + name=${1%_*} + modified=${1##*_} + if [ "$name" = "$kak_bufname" ]; then + echo "map global pick-buffers ${keys:$index:1} :buffer-by-index$index -docstring \"> $name $(if [ "$modified" = true ]; then echo "[+]"; fi)\"" + elif [ "$name" = "$kak_opt_alt_bufname" ]; then + echo "map global pick-buffers ${keys:$index:1} :buffer-by-index$index -docstring \"# $name $(if [ "$modified" = true ]; then echo "[+]"; fi)\"" + else + echo "map global pick-buffers ${keys:$index:1} :buffer-by-index$index -docstring \" $name $(if [ "$modified" = true ]; then echo "[+]"; fi)\"" + fi + + shift + done + } + enter-user-mode pick-buffers +} + +define-command buffer-first -docstring 'move to the first buffer in the list' 'buffer-by-index 1' + +define-command buffer-last -docstring 'move to the last buffer in the list' %{ + buffer-by-index %opt{buffers_total} +} + +define-command -hidden -params 1 buffer-by-index %{ + refresh-buffers-info + evaluate-commands %sh{ + target=$1 + index=0 + eval "set -- $kak_opt_buffers_info" + while [ "$1" ]; do + index=$(($index+1)) + name=${1%_*} + if [ $index = $target ]; then + echo "buffer $name" + fi + shift + done + } +} + +define-command delete-buffers -docstring 'delete all saved buffers' %{ + evaluate-commands %sh{ + deleted=0 + eval "set -- $kak_buflist" + while [ "$1" ]; do + echo "try 'delete-buffer $1'" + echo "echo -markup '{Information}$deleted buffers deleted'" + deleted=$((deleted+1)) + shift + done + } +} + +define-command buffer-only -docstring 'delete all saved buffers except current one' %{ + evaluate-commands %sh{ + deleted=0 + eval "set -- $kak_buflist" + while [ "$1" ]; do + if [ "$1" != "$kak_bufname" ]; then + echo "try 'delete-buffer $1'" + echo "echo -markup '{Information}$deleted buffers deleted'" + deleted=$((deleted+1)) + fi + shift + done + } +} + +define-command buffer-only-force -docstring 'delete all buffers except current one' %{ + evaluate-commands %sh{ + deleted=0 + eval "set -- $kak_buflist" + while [ "$1" ]; do + if [ "$1" != "$kak_bufname" ]; then + echo "delete-buffer! $1" + echo "echo -markup '{Information}$deleted buffers deleted'" + deleted=$((deleted+1)) + fi + shift + done + } +} + +define-command buffer-only-directory -docstring 'delete all saved buffers except the ones in the same current buffer directory' %{ + evaluate-commands %sh{ + deleted=0 + current_buffer_dir=$(dirname "$kak_bufname") + eval "set -- $kak_buflist" + while [ "$1" ]; do + dir=$(dirname "$1") + if [ $dir != "$current_buffer_dir" ]; then + echo "try 'delete-buffer $1'" + echo "echo -markup '{Information}$deleted buffers deleted'" + deleted=$((deleted+1)) + fi + shift + done + } +} + +define-command edit-kakrc -docstring 'open kakrc in a new buffer' %{ + evaluate-commands %sh{ + printf '%s\n' "edit $kak_config/kakrc" + } +} + +declare-user-mode buffers + +map global buffers a ga -docstring 'alternate' +map global buffers b :info-buffers -docstring 'info' +map global buffers c :edit-kakrc -docstring 'config' +map global buffers d :delete-buffer -docstring 'delete' +map global buffers D :delete-buffers -docstring 'delete all' +map global buffers f :buffer -docstring 'find' +map global buffers h :buffer-first -docstring 'first' +map global buffers l :buffer-last -docstring 'last' +map global buffers n :buffer-next -docstring 'next' +map global buffers o :buffer-only -docstring 'only' +map global buffers p :buffer-previous -docstring 'previous' +map global buffers s ':edit -scratch *scratch*' -docstring '*scratch*' +map global buffers u ':buffer *debug*' -docstring '*debug*' + +# trick to access count, 3b → display third buffer +define-command -hidden enter-buffers-mode %{ + evaluate-commands %sh{ + if [ "$kak_count" -eq 0 ]; then + echo 'enter-user-mode buffers' + else + echo "buffer-by-index $kak_count" + fi + } +} + +# Suggested hook + +#hook global WinDisplay .* info-buffers + +# Suggested mappings + +#map global user b ':enter-buffers-mode' -docstring 'buffers…' +#map global user B ':enter-user-mode -lock buffers' -docstring 'buffers (lock)…' + +# Suggested aliases + +#alias global bd delete-buffer +#alias global bf buffer-first +#alias global bl buffer-last +#alias global bo buffer-only +#alias global bo! buffer-only-force diff --git a/dot.config/kak/autoload/explore-buffers.kak b/dot.config/kak/autoload/explore-buffers.kak new file mode 100644 index 0000000..3bccbbd --- /dev/null +++ b/dot.config/kak/autoload/explore-buffers.kak @@ -0,0 +1,58 @@ +declare-option -hidden str explore_buffers_current + +set-face global ExploreBuffers 'yellow,default' + +add-highlighter shared/buffers regions +add-highlighter shared/buffers/content default-region group +add-highlighter shared/buffers/content/buffers regex '^.+$' 0:ExploreBuffers + +define-command -hidden explore-buffers -docstring 'Explore buffers' %{ evaluate-commands -save-regs '"/' %{ + set-option current explore_buffers_current %val(bufname) + edit! -scratch *buffers* + set-option buffer filetype buffers + evaluate-commands set-register dquote %val(buflist) + execute-keys ')i' + set-register / "\Q%opt(explore_buffers_current)\E" + execute-keys n +}} + +define-command -hidden explore-buffers-parent -docstring 'Explore the parent directory of the selected buffer' %{ + explore-buffers-validate + explore-files %sh(dirname "$kak_buffile") +} + +define-command -hidden explore-buffers-validate -docstring 'Edit selected buffer' %{ + execute-keys '_' + buffer %reg(.) + delete-buffer *buffers* +} + +define-command -hidden explore-buffers-delete -docstring 'Delete selected buffer' %{ + execute-keys '_' + delete-buffer %reg(.) + explore-buffers +} + +hook global WinSetOption filetype=buffers %{ + add-highlighter window/ ref buffers + map window normal ': explore-buffers-validate' + map window normal ': explore-buffers-parent' + map window normal q ': delete-buffer' + map window normal ': delete-buffer' + map window normal d ': explore-buffers-delete' + hook -always -once window WinSetOption filetype=.* %{ + remove-highlighter window/buffers + } +} + +define-command -hidden explore-buffers-enable %{ + hook window -group explore-buffers RuntimeError '\d+:\d+: ''(buffer|b)'' wrong argument count' %{ + # Hide error message + echo + explore-buffers + } +} + +hook -group explore-buffers global WinCreate .* %{ + explore-buffers-enable +} diff --git a/dot.config/kak/autoload/explore-files.kak b/dot.config/kak/autoload/explore-files.kak new file mode 100644 index 0000000..6249555 --- /dev/null +++ b/dot.config/kak/autoload/explore-files.kak @@ -0,0 +1,136 @@ +declare-option -docstring 'Whether to show hidden files' bool explore_files_show_hidden no + +declare-option -hidden str explore_files +declare-option -hidden int explore_files_count + +set-face global ExploreFiles 'magenta,default' +set-face global ExploreDirectories 'cyan,default' + +add-highlighter shared/directory regions +add-highlighter shared/directory/content default-region group +add-highlighter shared/directory/content/files regex '^.+$' 0:ExploreFiles +add-highlighter shared/directory/content/directories regex '^.+/$' 0:ExploreDirectories + +define-command -hidden explore-files-display -params 1..2 %{ evaluate-commands %sh{ + command=$1 + path=$(realpath "${2:-.}") + name=$(basename "$path") + out=$(mktemp --directory) + fifo=$out/fifo + last_buffer_name=$(basename "$kak_bufname") + mkfifo $fifo + cd "$path" + (eval "$command" > $fifo) < /dev/null > /dev/null 2>&1 & + echo " + edit -fifo %($fifo) %($path) + set-option buffer filetype directory + hook -once window NormalIdle '' %{ + evaluate-commands -save-regs / %{ + set-register / %(\b\Q$last_buffer_name\E\b) + try %(execute-keys n) + } + # Information + echo -markup {Information} %(Showing $name/ entries) + } + hook -always -once buffer BufCloseFifo '' %(nop %sh(rm --recursive $out)) + # Information + echo -markup {Information} %(Showing $name/ entries) + " +}} + +define-command -hidden explore-files-smart -params 0..1 %{ evaluate-commands %sh{ + file=${1:-.} + edit=$(test -d "$file" && echo explore-files || echo edit) + echo "$edit %($file)" +}} + +define-command -hidden explore-files -params 0..1 -docstring 'Explore directory entries' %{ + explore-files-display "ls --dereference --group-directories-first --indicator-style=slash %sh(test $kak_opt_explore_files_show_hidden = true && echo --almost-all)" %arg(1) +} + +define-command -hidden explore-files-recursive -params 0..1 -docstring 'Explore directory entries recursively' %{ + explore-files-display "fd %sh(test $kak_opt_explore_files_show_hidden = true && echo --hidden)" %arg(1) +} + +define-command -hidden explore-files-forward -docstring 'Edit selected files' %{ + set-option current explore_files %val(bufname) + execute-keys ';_' + set-option current explore_files_count %sh(count() { echo $#; }; count $kak_selections_desc) + evaluate-commands -draft -itersel -save-regs 'F' %{ + set-register F "%val(bufname)/%reg(.)" + evaluate-commands -client %val(client) %(explore-files-smart %reg(F)) + } + delete-buffer %opt(explore_files) + evaluate-commands %sh{ + count=$kak_opt_explore_files_count + test $count -gt 1 && + echo "echo -markup {Information} %[$count files opened]" + } +} + +define-command -hidden explore-files-back -docstring 'Explore parent directory' %{ + set-option current explore_files %val(bufname) + explore-files "%opt(explore_files)/.." + delete-buffer %opt(explore_files) + echo -markup {Information} "Showing %sh(basename ""$kak_bufname"")/ entries" +} + +define-command -hidden explore-files-change-directory -docstring 'Change directory and quit' %{ + change-directory %val(bufname) + delete-buffer +} + +define-command -hidden explore-files-toggle-hidden -docstring 'Toggle hidden files' %{ + set-option current explore_files_show_hidden %sh{ + if test $kak_opt_explore_files_show_hidden = true; then + echo no + else + echo yes + fi + } + explore-files %val(bufname) +} + +hook global WinSetOption filetype=directory %{ + add-highlighter window/ ref directory + map window normal ': explore-files-forward' + map window normal ': explore-files-back' + map window normal . ': explore-files-toggle-hidden' + map window normal R ': explore-files-recursive %val(bufname)' + map window normal q ': explore-files-change-directory' + map window normal ': delete-buffer' + hook -always -once window WinSetOption filetype=.* %{ + remove-highlighter window/directory + } +} + +define-command -hidden explore-files-enable %{ + hook window -group explore-files RuntimeError '\d+:\d+: ''(?:edit|e)'' wrong argument count' %{ + explore-files %sh(dirname "$kak_buffile") + } + hook window -group explore-files RuntimeError '\d+:\d+: ''(?:edit|e)'' (.+): is a directory' %{ + # Hide error message + echo + explore-files %val(hook_param_capture_1) + } + hook window -group explore-files RuntimeError 'unable to find file ''(.+)''' %{ + # Hide error message + echo + explore-files-smart %val(hook_param_capture_1) + } +} + +hook -group explore-files global WinCreate .* %{ + explore-files-enable +} + +hook -group explore-files global KakBegin .* %{ hook -once global WinCreate .* %{ hook -once global NormalIdle '' %{ + try %{ evaluate-commands -draft -save-regs '/' %{ + buffer *debug* + set-register / 'error while opening file ''(.+?)'':\n\h+(.+?): is a directory' + execute-keys '%1s' + evaluate-commands -draft -itersel %{ + evaluate-commands -client %val(client) explore-files %reg(.) + } + }} +}}} diff --git a/dot.config/kak/autoload/registers.kak b/dot.config/kak/autoload/registers.kak new file mode 100644 index 0000000..ec92c8d --- /dev/null +++ b/dot.config/kak/autoload/registers.kak @@ -0,0 +1,27 @@ +def list-registers -docstring 'populate the *registers* buffer with the content of registers' %{ + edit! -scratch *registers* + evaluate-commands %sh{ + # empty scratch buffer + echo 'exec \%d' + + # paste the content of each register on a separate line + for reg in {'%','.','#','"','@','/','^','|',{a..z},{0..9}}; do + echo "exec 'i${reg}\"${reg}pGjo'" + done + + # hide empty registers (lines with less than 4 chars) + echo 'exec \%.{4,}d' + + # make sure all registers are easily visible + echo 'exec gg' + } +} + +# beware, it wipes the content of reg x +def info-registers -docstring 'populate an info box with the content of registers' %{ + list-registers + exec -save-regs \%| '%|cut-c-30%"xyga' + info -title registers -- %reg{x} + set-register x '' +} + diff --git a/dot.config/kak/autoload/replace.kak b/dot.config/kak/autoload/replace.kak new file mode 100644 index 0000000..cf81868 --- /dev/null +++ b/dot.config/kak/autoload/replace.kak @@ -0,0 +1,19 @@ +define-command -hidden replace-insert -params 1 %{ + try %{ + execute-keys -draft ';\n' + execute-keys '' + } +} + +define-command -hidden replace-delete -params 1 %{ + execute-keys 'H' +} + +define-command replace -docstring 'Enter in replace mode' %{ + hook window InsertChar '[^\n]' -group replace %(replace-insert %val(hook_param)) + hook window InsertDelete '[^\n]' -group replace %(replace-delete %val(hook_param)) + hook -once window ModeChange insert:normal %{ + remove-hooks window replace + } + execute-keys -with-hooks i +} diff --git a/dot.config/kak/autoload/stuff.kak b/dot.config/kak/autoload/stuff.kak index 7c2f98b..ba6bd6c 100644 --- a/dot.config/kak/autoload/stuff.kak +++ b/dot.config/kak/autoload/stuff.kak @@ -1,23 +1,23 @@ # hooks to show line numbers, whitespaces and matching brackets hook -group DefaultHighlights global WinCreate .* %{ - add-highlighter window/ show_whitespaces - add-highlighter window/ show_matching - add-highlighter window/ regex '\h+$' 0:default,red # show all trailing whispaces red + add-highlighter window/ show-whitespaces + add-highlighter window/ show-matching + add-highlighter window/ regex '\h+$' 0:default,red # highlight trailing whitepaces add-highlighter window/ dynregex '%reg{/}' 0:+u 1:+b set-face window Whitespace rgb:555555+b } hook -group markdown-highlight global WinSetOption filetype=markdown %{ add-highlighter window/ wrap -word -width 80 - add-highlighter window/ number_lines -hlcursor -separator ' ' + add-highlighter window/ number-lines -hlcursor -separator ' ' } hook global WinSetOption filetype=(?!markdown).* %{ - add-highlighter window/ number_lines -hlcursor -separator ' ' + add-highlighter window/ number-lines -hlcursor -separator ' ' } # map tmux split and window commands in vim style -def -file-completion -params 1 tabe %{ tmux-new-window edit %arg{1} } -def -file-completion -params 1 vsplit %{ tmux-new-vertical edit %arg{1} } +def -file-completion -params 1 tabe %{ tmux-terminal-window edit %arg{1} } +def -file-completion -params 1 vsplit %{ tmux-terminal-vertical edit %arg{1} } #map global insert ctrl-n ':new' #map global normal ctrl-n ':new' @@ -69,3 +69,65 @@ hook global WinSetOption filetype=json %{ set window formatcmd 'jq .' hook window BufWritePre .* format } + + +######################################################### +# buffers (https://github.com/Delapouite/kakoune-buffers) +# +# sets former b (word-back) to q and makes b a global key +# for the new buffers command. I don't use macros anyway. +######################################################### + +hook global WinDisplay .* info-buffers + +# ciao macros +map global normal ^ q +map global normal Q +map global normal q b +map global normal Q B +map global normal +map global normal + +map global normal b ':enter-buffers-mode' -docstring 'buffers…' +map global normal B ':enter-user-mode -lock buffers' -docstring 'buffers (lock)…' + + +############################################# +# lsp support (https://github.com/ul/kak-lsp) +# ...but it's not working yet +############################################# + +# eval %sh{kak-lsp --kakoune -s $kak_session} +# +# set-option global lsp_completion_trigger "execute-keys 'h\S[^\h\n,=;*(){}\[\]]\z'" +# set-option global lsp_diagnostic_line_error_sign "!" +# set-option global lsp_diagnostic_line_warning_sign "?" +# +# hook global WinSetOption filetype=(c|cpp|rust|javascript|html|css|json) %{ +# map window user "l" ": enter-user-mode lsp" -docstring "LSP mode" +# lsp-enable-window +# lsp-auto-hover-enable +# lsp-auto-hover-insert-mode-disable +# set-option window lsp_hover_anchor true +# set-face window DiagnosticError default+u +# set-face window DiagnosticWarning default+u +#} +#hook global WinSetOption filetype=rust %{ +# set-option window lsp_server_configuration rust.clippy_preference="on" +#} +#hook global KakEnd .* lsp-exit + + +########################################################## +# replace mode (https://github.com/alexherbo2/replace.kak) +# that is one thing I missed in Kakoune: writing over text +########################################################## +map global user r -docstring 'Replace' ': replace' + +########################################################### +# explore files (https://github.com/alexherbo2/explore.kak) +# use fd instead of find +########################################################### +define-command -hidden -override explore-files-recursive -params 0..1 %{ + explore-files-display "fd %sh(test $kak_opt_explore_files_show_hidden = true && echo --hidden)" %arg(1) +} diff --git a/dot.config/kak/autoload/todotxt.kak b/dot.config/kak/autoload/todotxt.kak deleted file mode 120000 index e3d73c6..0000000 --- a/dot.config/kak/autoload/todotxt.kak +++ /dev/null @@ -1 +0,0 @@ -/home/nk/src/koehr/kakoune-todo.txt/todotxt.kak \ No newline at end of file diff --git a/dot.config/kak/autoload/todotxt.kak b/dot.config/kak/autoload/todotxt.kak new file mode 100644 index 0000000..eea8975 --- /dev/null +++ b/dot.config/kak/autoload/todotxt.kak @@ -0,0 +1,64 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.]?(todo\.txt) %{ + set buffer filetype todotxt + + def -hidden todo-done2bottom %{ + try %{ + exec '%^x dge:echo %reg{#} items moved' + } + } + def -hidden todo-a2top %{ + try %{ + exec '%^\(A\) dgg:echo %reg{#} items moved' + } + } + def -hidden todo-b2top %{ + try %{ + exec '%^\(B\) dgg:echo %reg{#} items moved' + } + } + def -hidden todo-c2top %{ + try %{ + exec '%^\(C\) dgg:echo %reg{#} items moved' + } + } + def -docstring 'sort items by priority and state' todo-sort %{ + exec '%:todo-c2top:todo-b2top:todo-a2top:todo-done2bottom' + } + def -docstring 'mark item under cursor as done' todo-mark-done %{ + try %{ + exec 'xs\([ABC]\) cx ' + } catch %{ + exec 'ghix ' + } + } + def -docstring 'mark item under cursor as high priority' -params 1 todo-mark-prio %{ + try %{ + exec "xs^(\([ABC]\)|x) c(%arg{1}) " + } catch %{ + exec "ghi(%arg{1}) " + } + } +} + +face global TodoPrioA red+b +face global TodoPrioB yellow+b +face global TodoPrioC cyan+b +face global TodoDate default+b + + +add-highlighter global/todotxt group +add-highlighter global/todotxt/comment regex "^x ([^\n]+)" 0:comment # done items +add-highlighter global/todotxt/prio-a regex "^\(A\) ([^\n]+)" 0:TodoPrioA # priority (A) +add-highlighter global/todotxt/prio-b regex "^\(B\) ([^\n]+)" 0:TodoPrioB # priority (B) +add-highlighter global/todotxt/prio-c regex "^\(C\) ([^\n]+)" 0:TodoPrioC # priority (C) +add-highlighter global/todotxt/key-value regex "([^:|^ ]+:)([^ |^\n]+)" 0:value 1:type # key:value +add-highlighter global/todotxt/keyword regex "(\+[^\+|^ |^\n]+)" 0:keyword # +project +add-highlighter global/todotxt/meta regex "(@[^\+|^ |^\n]+)" 0:meta # @context +add-highlighter global/todotxt/date regex "(\d{4}-\d{2}-\d{2})" 0:TodoDate # date + +hook -group todotxt-highlight global WinSetOption filetype=todotxt %{ add-highlighter window ref todotxt } +hook -group todotxt-highlight global WinSetOption filetype=(?!todotxt).* %{ remove-highlighter window/todotxt } + diff --git a/dot.config/kak/autoload/vue.kak b/dot.config/kak/autoload/vue.kak new file mode 100644 index 0000000..6d37385 --- /dev/null +++ b/dot.config/kak/autoload/vue.kak @@ -0,0 +1,77 @@ +# Vue file +# ‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*\.vue %{ + set-option buffer filetype vue +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/vue regions +add-highlighter shared/vue/tag region < > regions +add-highlighter shared/vue/pug region \K (?=) ref pug +add-highlighter shared/vue/html region \K (?=) ref html +add-highlighter shared/vue/scss region \K (?=) ref scss +add-highlighter shared/vue/sass region \K (?=) ref sass +add-highlighter shared/vue/less region \K (?=) ref less +add-highlighter shared/vue/css region \K (?=) ref css +add-highlighter shared/vue/ts region \K (?=) ref ts +add-highlighter shared/vue/js region \K (?=) ref javascript + +add-highlighter shared/vue/tag/base default-region group +add-highlighter shared/vue/tag/ region '"' (? s \h+$ d } +} + +define-command -hidden vue-indent-on-greater-than %[ + evaluate-commands -draft -itersel %[ + # align closing tag to opening when alone on a line + try %[ execute-keys -draft s ^\h+/(\w+)$ {c1,/1 s \A|.\z 1 ] + ] +] + +define-command -hidden vue-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft \; K } + # filter previous line + try %{ execute-keys -draft k : vue-filter-around-selections } + # indent after lines ending with opening tag + try %{ execute-keys -draft k <[^/][^>]+>$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group vue-highlight global WinSetOption filetype=vue %{ add-highlighter window/vue ref vue } + +hook global WinSetOption filetype=vue %{ + hook window ModeChange insert:.* -group vue-hooks vue-filter-around-selections + hook window InsertChar '>' -group vue-indent vue-indent-on-greater-than + hook window InsertChar \n -group vue-indent vue-indent-on-new-line + set window comment_line '//' + set window comment_block_begin '' +} + +hook -group vue-highlight global WinSetOption filetype=(?!vue).* %{ remove-highlighter window/vue } + +hook global WinSetOption filetype=(?!vue).* %{ + remove-hooks window vue-indent + remove-hooks window vue-hooks +} diff --git a/dot.config/kak/autoload/wiki.kak b/dot.config/kak/autoload/wiki.kak deleted file mode 120000 index 5dbdd35..0000000 --- a/dot.config/kak/autoload/wiki.kak +++ /dev/null @@ -1 +0,0 @@ -/home/nk/src/pkg/kakoune-wiki/wiki.kak \ No newline at end of file diff --git a/dot.config/kak/autoload/wiki.kak b/dot.config/kak/autoload/wiki.kak new file mode 100644 index 0000000..8f90b4e --- /dev/null +++ b/dot.config/kak/autoload/wiki.kak @@ -0,0 +1,116 @@ +declare-option -docstring %{ Path to wiki directory } str wiki_path + +# program that outputs relative path given two absolute as params +declare-option -hidden str wiki_relative_path_program %{ perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' } + + +define-command -hidden -params 1 wiki_setup %{ + evaluate-commands %sh{ + echo "set-option global wiki_path $1" + echo "hook global BufCreate $1/.+\.md %{ wiki_enable }" + } +} + +define-command wiki -params 1 \ +-docstring %{ wiki [file.md]: Edit or create wiki page } \ +-shell-script-candidates %{ cd $kak_opt_wiki_path; find . -type f -name '*.md' | sed -e 's/^\.\///' } \ +%{ evaluate-commands %sh{ + if [ ! -e "$kak_opt_wiki_path/$1" ]; then + echo "wiki_new_page %{$1}" + fi + echo "edit %{$kak_opt_wiki_path/$1}" +}} + +define-command wiki_enable %{ + add-highlighter buffer/wiki group + add-highlighter buffer/wiki/tag regex '\B@\S+' 0:link + add-highlighter buffer/wiki/link regex '\[\w+\]' 0:link + hook buffer InsertKey '' -group wiki %{ + evaluate-commands %{ try %{ + execute-keys -draft %{ + \A@!\w+ + :wiki_expand_pic + }} catch %{ + try %{ execute-keys -draft %{ + \A@\w+ + :wiki_expand_tag + } + execute-keys + } + }} + } + hook buffer NormalKey '' -group wiki %{ + try %{ wiki_follow_link } + try %{ wiki_toggle_checkbox } + } +} + +define-command wiki_disable %{ + remove-highlighter buffer/wiki + remove-hooks buffer wiki +} + +define-command wiki_expand_tag \ +-docstring %{ Expands tag from @filename form to [filename](filename.md) +Creates empty markdown file in wiki_path if not exist. Selection must be +somewhere on @tag and @tag should not contain extension } %{ + evaluate-commands %sh{ + this="$kak_buffile" + tag=$(echo $kak_selection | sed -e 's/^\@//') + other="$kak_opt_wiki_path/$tag.md" + relative=$(eval "$kak_opt_wiki_relative_path_program" "$other" $(dirname "$this")) + # sanity chceck + echo "execute-keys -draft '\A@[^@]+'" + echo "execute-keys \"c[$tag]($relative)\"" + echo "wiki_new_page \"$tag\"" + } +} + +define-command wiki_expand_pic \ +-docstring %{ Expands images from @!filename.png form to ![filename.png](filename.png)} %{ + evaluate-commands %sh{ + this="$kak_buffile" + tag=$(echo $kak_selection | sed -e 's/^\@!//') + other="$kak_opt_wiki_path/$tag" + relative=$(eval "$kak_opt_wiki_relative_path_program" "$other" $(dirname "$this")) + # sanity check + echo execute-keys -draft '^@\+[^@!]+' + echo execute-keys "c![$tag]($relative)" + } +} + +define-command -params 1 -hidden \ +-docstring %{ wiki_new_page [name]: create new wiki page in wiki_path if not exists } \ +wiki_new_page %{ + nop %sh{ + file="$kak_opt_wiki_path/${1%.md}" + mkdir -p "$(dirname $file)" + touch "${file}.md" + } +} + +define-command wiki_follow_link \ +-docstring %{ Follow markdown link and open file if exists } %{ + evaluate-commands %{ + execute-keys %{ + c\[,\) + b + } + evaluate-commands -try-client %opt{jumpclient} edit -existing %sh{ + echo "${kak_buffile%/*.md}/$kak_selection" + } + try %{ focus %opt{jumpclient} } + } +} + +define-command wiki_toggle_checkbox \ +-docstring "Toggle markdown checkbox in current line" %{ + try %{ + try %{ + execute-keys -draft %{ + ;xs-\s\[\s\][rX + }} catch %{ + execute-keys -draft %{ + ;xs-\s\[X\][r + }}} +} diff --git a/dot.config/kak/kakrc b/dot.config/kak/kakrc index b4feafb..87fc850 100644 --- a/dot.config/kak/kakrc +++ b/dot.config/kak/kakrc @@ -16,10 +16,6 @@ set global modelinefmt %{ · {{context_info}} {{mode_info}} } -hook global InsertBegin .* %{ - echo '— INSERT —' -} - hook global InsertEnd .* %{ lint } @@ -37,9 +33,5 @@ hook global NormalKey y|d|c %{ nop %sh{ printf %s "$kak_reg_dquote" | xsel --input --clipboard }} -def -docstring 'ripgrep in current dir' \ -find -params 1 -shell-candidates %{ rg --files } %{ edit %arg{1} } - # editorconfig support hook global BufCreate .* %{editorconfig-load} -