From 936bfcf0c8a104bb7bf74a1cc6df19d533408e49 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 3 Mar 2016 18:56:50 +0100 Subject: [PATCH] =?UTF-8?q?add=20:alt=20command=20to=20jump=20to=20the=20a?= =?UTF-8?q?lternate=20file=20(implementation=20=E2=86=94=20test)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rc/base/lua.kak | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 }