summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Leferry 2 <alexherbo2@gmail.com>2016-03-03 18:56:50 +0100
committerAlex Leferry 2 <alexherbo2@gmail.com>2016-03-03 18:56:50 +0100
commit936bfcf0c8a104bb7bf74a1cc6df19d533408e49 (patch)
treee049a7da0eb92e55b6f0e18d4b595eecd60d02d5
parent11153adcd811db078be04f08664f67e520f4253c (diff)
add :alt command to jump to the alternate file (implementation ↔ test)
-rw-r--r--rc/base/lua.kak29
1 files changed, 29 insertions, 0 deletions
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 <a-x>
@@ -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
}