diff --git a/rc/base/lua.kak b/rc/base/lua.kak index b588834b..ef8cfbdf 100644 --- a/rc/base/lua.kak +++ b/rc/base/lua.kak @@ -32,6 +32,31 @@ addhl -group /lua/code regex \<(and|break|do|else|elseif|end|false|for|function| # Commands # ‾‾‾‾‾‾‾‾ +def lua-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ + case $kak_buffile in + *spec/*_spec.lua) + altfile=$(eval echo $(echo $kak_buffile | sed -e s+spec/+'*'/+';'s/_spec//)) + [ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit + ;; + *.lua) + path=$kak_buffile + dirs=$(while [ $path ]; do echo $path; path=${path%/*}; done | tail -n +2) + for dir in $dirs; do + altdir=$dir/spec + if [ -d $altdir ]; then + altfile=$altdir/$(realpath $kak_buffile --relative-to $dir | sed -e s+[^/]'*'/++';'s/.lua$/_spec.lua/) + break + fi + done + [ ! -d $altdir ] && echo "echo -color Error 'spec/ not found'" && exit + ;; + *) + echo "echo -color Error 'alternative file not found'" && exit + ;; + esac + echo "edit $altfile" +}} + def -hidden _lua_filter_around_selections %{ eval -draft -itersel %{ exec @@ -77,6 +102,8 @@ hook global WinSetOption filetype=lua %{ hook window InsertChar .* -group lua-indent _lua_indent_on_char hook window InsertChar \n -group lua-indent _lua_indent_on_new_line + alias window alt lua-alternative-file + set window comment_line_chars '--' set window comment_selection_chars '\Q--[[:]]' } @@ -85,4 +112,6 @@ hook global WinSetOption filetype=(?!lua).* %{ rmhl lua rmhooks window lua-indent rmhooks window lua-hooks + + unalias window alt lua-alternative-file }