update kakoune config
This commit is contained in:
parent
6cdcfe2fae
commit
596456c2b6
11 changed files with 800 additions and 19 deletions
|
@ -1 +0,0 @@
|
|||
/home/nk/.local/share/kak/autoload
|
|
@ -1 +0,0 @@
|
|||
/home/nk/src/pkg/kakoune-buffers/buffers.kak
|
234
dot.config/kak/autoload/buffers.kak
Normal file
234
dot.config/kak/autoload/buffers.kak
Normal file
|
@ -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<space>$index<ret> -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<space>$index<ret> -docstring \"# $name $(if [ "$modified" = true ]; then echo "[+]"; fi)\""
|
||||
else
|
||||
echo "map global pick-buffers ${keys:$index:1} :buffer-by-index<space>$index<ret> -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<ret> -docstring 'info'
|
||||
map global buffers c :edit-kakrc<ret> -docstring 'config'
|
||||
map global buffers d :delete-buffer<ret> -docstring 'delete'
|
||||
map global buffers D :delete-buffers<ret> -docstring 'delete all'
|
||||
map global buffers f :buffer<space> -docstring 'find'
|
||||
map global buffers h :buffer-first<ret> -docstring 'first'
|
||||
map global buffers l :buffer-last<ret> -docstring 'last'
|
||||
map global buffers n :buffer-next<ret> -docstring 'next'
|
||||
map global buffers o :buffer-only<ret> -docstring 'only'
|
||||
map global buffers p :buffer-previous<ret> -docstring 'previous'
|
||||
map global buffers s ':edit -scratch *scratch*<ret>' -docstring '*scratch*'
|
||||
map global buffers u ':buffer *debug*<ret>' -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<ret>' -docstring 'buffers…'
|
||||
#map global user B ':enter-user-mode -lock buffers<ret>' -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
|
58
dot.config/kak/autoload/explore-buffers.kak
Normal file
58
dot.config/kak/autoload/explore-buffers.kak
Normal file
|
@ -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 '<a-R>)<a-space>i<ret><esc><space>'
|
||||
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 '<space><a-x>_'
|
||||
buffer %reg(.)
|
||||
delete-buffer *buffers*
|
||||
}
|
||||
|
||||
define-command -hidden explore-buffers-delete -docstring 'Delete selected buffer' %{
|
||||
execute-keys '<space><a-x>_'
|
||||
delete-buffer %reg(.)
|
||||
explore-buffers
|
||||
}
|
||||
|
||||
hook global WinSetOption filetype=buffers %{
|
||||
add-highlighter window/ ref buffers
|
||||
map window normal <ret> ': explore-buffers-validate<ret>'
|
||||
map window normal <backspace> ': explore-buffers-parent<ret>'
|
||||
map window normal q ': delete-buffer<ret>'
|
||||
map window normal <esc> ': delete-buffer<ret>'
|
||||
map window normal d ': explore-buffers-delete<ret>'
|
||||
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
|
||||
}
|
136
dot.config/kak/autoload/explore-files.kak
Normal file
136
dot.config/kak/autoload/explore-files.kak
Normal file
|
@ -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 '<a-s>;<a-x>_'
|
||||
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 <ret> ': explore-files-forward<ret>'
|
||||
map window normal <backspace> ': explore-files-back<ret>'
|
||||
map window normal . ': explore-files-toggle-hidden<ret>'
|
||||
map window normal R ': explore-files-recursive %val(bufname)<ret>'
|
||||
map window normal q ': explore-files-change-directory<ret>'
|
||||
map window normal <esc> ': delete-buffer<ret>'
|
||||
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<ret>'
|
||||
evaluate-commands -draft -itersel %{
|
||||
evaluate-commands -client %val(client) explore-files %reg(.)
|
||||
}
|
||||
}}
|
||||
}}}
|
27
dot.config/kak/autoload/registers.kak
Normal file
27
dot.config/kak/autoload/registers.kak
Normal file
|
@ -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}<space><esc>\"${reg}pGj<a-j>o<esc>'"
|
||||
done
|
||||
|
||||
# hide empty registers (lines with less than 4 chars)
|
||||
echo 'exec \%<a-s><a-K>.{4,}<ret>d<space>'
|
||||
|
||||
# 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 \%| '%<a-s>|cut<space>-c-30<ret>%"xyga'
|
||||
info -title registers -- %reg{x}
|
||||
set-register x ''
|
||||
}
|
||||
|
19
dot.config/kak/autoload/replace.kak
Normal file
19
dot.config/kak/autoload/replace.kak
Normal file
|
@ -0,0 +1,19 @@
|
|||
define-command -hidden replace-insert -params 1 %{
|
||||
try %{
|
||||
execute-keys -draft ';<a-K>\n<ret>'
|
||||
execute-keys '<del>'
|
||||
}
|
||||
}
|
||||
|
||||
define-command -hidden replace-delete -params 1 %{
|
||||
execute-keys '<space><a-;>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
|
||||
}
|
|
@ -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 '<esc>:new<ret>'
|
||||
#map global normal ctrl-n ':new<ret>'
|
||||
|
||||
|
@ -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 <a-^> Q
|
||||
map global normal q b
|
||||
map global normal Q B
|
||||
map global normal <a-q> <a-b>
|
||||
map global normal <a-Q> <a-B>
|
||||
|
||||
map global normal b ':enter-buffers-mode<ret>' -docstring 'buffers…'
|
||||
map global normal B ':enter-user-mode -lock buffers<ret>' -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<a-h><a-k>\S[^\h\n,=;*(){}\[\]]\z<ret>'"
|
||||
# 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<ret>" -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<ret>'
|
||||
|
||||
###########################################################
|
||||
# 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)
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
/home/nk/src/koehr/kakoune-todo.txt/todotxt.kak
|
64
dot.config/kak/autoload/todotxt.kak
Normal file
64
dot.config/kak/autoload/todotxt.kak
Normal file
|
@ -0,0 +1,64 @@
|
|||
# Detection
|
||||
# ‾‾‾‾‾‾‾‾‾
|
||||
|
||||
hook global BufCreate .*[.]?(todo\.txt) %{
|
||||
set buffer filetype todotxt
|
||||
|
||||
def -hidden todo-done2bottom %{
|
||||
try %{
|
||||
exec '%<a-s><a-k>^x <ret>dge<a-p>:echo %reg{#} items moved<ret>'
|
||||
}
|
||||
}
|
||||
def -hidden todo-a2top %{
|
||||
try %{
|
||||
exec '%<a-s><a-k>^\(A\) <ret>dgg<a-P>:echo %reg{#} items moved<ret>'
|
||||
}
|
||||
}
|
||||
def -hidden todo-b2top %{
|
||||
try %{
|
||||
exec '%<a-s><a-k>^\(B\) <ret>dgg<a-P>:echo %reg{#} items moved<ret>'
|
||||
}
|
||||
}
|
||||
def -hidden todo-c2top %{
|
||||
try %{
|
||||
exec '%<a-s><a-k>^\(C\) <ret>dgg<a-P>:echo %reg{#} items moved<ret>'
|
||||
}
|
||||
}
|
||||
def -docstring 'sort items by priority and state' todo-sort %{
|
||||
exec '%:todo-c2top<ret>:todo-b2top<ret>:todo-a2top<ret>:todo-done2bottom<ret>'
|
||||
}
|
||||
def -docstring 'mark item under cursor as done' todo-mark-done %{
|
||||
try %{
|
||||
exec 'xs\([ABC]\) <ret>cx <esc>'
|
||||
} catch %{
|
||||
exec 'ghix <esc>'
|
||||
}
|
||||
}
|
||||
def -docstring 'mark item under cursor as high priority' -params 1 todo-mark-prio %{
|
||||
try %{
|
||||
exec "xs^(\([ABC]\)|x) <ret>c(%arg{1}) <esc>"
|
||||
} catch %{
|
||||
exec "ghi(%arg{1}) <esc>"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 }
|
||||
|
77
dot.config/kak/autoload/vue.kak
Normal file
77
dot.config/kak/autoload/vue.kak
Normal file
|
@ -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 <template\b.*?lang="pug".*?>\K (?=</template>) ref pug
|
||||
add-highlighter shared/vue/html region <template\b.*?>\K (?=</template>) ref html
|
||||
add-highlighter shared/vue/scss region <style\b.*?lang="scss".*?>\K (?=</style>) ref scss
|
||||
add-highlighter shared/vue/sass region <style\b.*?lang="sass".*?>\K (?=</style>) ref sass
|
||||
add-highlighter shared/vue/less region <style\b.*?lang="less".*?>\K (?=</style>) ref less
|
||||
add-highlighter shared/vue/css region <style\b.*?>\K (?=</style>) ref css
|
||||
add-highlighter shared/vue/ts region <script\b.*?lang="typescript".*?>\K (?=</script>) ref ts
|
||||
add-highlighter shared/vue/js region <script\b.*?>\K (?=</script>) ref javascript
|
||||
|
||||
add-highlighter shared/vue/tag/base default-region group
|
||||
add-highlighter shared/vue/tag/ region '"' (?<!\\)(\\\\)*" fill string
|
||||
add-highlighter shared/vue/tag/ region "'" "'" fill string
|
||||
|
||||
add-highlighter shared/vue/tag/base/ regex \b([a-zA-Z0-9_-]+)=? 1:attribute
|
||||
add-highlighter shared/vue/tag/base/ regex </?(\w+) 1:keyword
|
||||
|
||||
# Commands
|
||||
# ‾‾‾‾‾‾‾‾
|
||||
|
||||
define-command -hidden vue-filter-around-selections %{
|
||||
# remove trailing white spaces
|
||||
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> 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 <space> <a-h> s ^\h+<lt>/(\w+)<gt>$ <ret> {c<lt><c-r>1,<lt>/<c-r>1<gt> <ret> s \A|.\z <ret> 1<a-&> ]
|
||||
]
|
||||
]
|
||||
|
||||
define-command -hidden vue-indent-on-new-line %{
|
||||
evaluate-commands -draft -itersel %{
|
||||
# preserve previous line indent
|
||||
try %{ execute-keys -draft \; K <a-&> }
|
||||
# filter previous line
|
||||
try %{ execute-keys -draft k : vue-filter-around-selections <ret> }
|
||||
# indent after lines ending with opening tag
|
||||
try %{ execute-keys -draft k <a-x> <a-k> <[^/][^>]+>$ <ret> j <a-gt> }
|
||||
}
|
||||
}
|
||||
|
||||
# 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 '<!--'
|
||||
set window comment_block_end '-->'
|
||||
}
|
||||
|
||||
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
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
/home/nk/src/pkg/kakoune-wiki/wiki.kak
|
116
dot.config/kak/autoload/wiki.kak
Normal file
116
dot.config/kak/autoload/wiki.kak
Normal file
|
@ -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 '<ret>' -group wiki %{
|
||||
evaluate-commands %{ try %{
|
||||
execute-keys -draft %{
|
||||
<a-b><a-k>\A@!\w+<ret>
|
||||
:wiki_expand_pic<ret>
|
||||
}} catch %{
|
||||
try %{ execute-keys -draft %{
|
||||
<a-b><a-k>\A@\w+<ret>
|
||||
:wiki_expand_tag<ret>
|
||||
}
|
||||
execute-keys <backspace>
|
||||
}
|
||||
}}
|
||||
}
|
||||
hook buffer NormalKey '<ret>' -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-k>\A@[^@]+<ret>'"
|
||||
echo "execute-keys \"c[$tag]($relative)<esc>\""
|
||||
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 '<a-k>^@\+[^@!]+'
|
||||
echo execute-keys "c![$tag]($relative)<esc>"
|
||||
}
|
||||
}
|
||||
|
||||
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 %{
|
||||
<esc><a-a>c\[,\)<ret><a-:>
|
||||
<a-i>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 %{
|
||||
<esc><space>;xs-\s\[\s\]<ret><a-i>[rX
|
||||
}} catch %{
|
||||
execute-keys -draft %{
|
||||
<esc><space>;xs-\s\[X\]<ret><a-i>[r<space>
|
||||
}}}
|
||||
}
|
|
@ -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}
|
||||
|
||||
|
|
Loading…
Reference in a new issue