From 13e6c34c3545b661689f09daa900ca1105a9e564 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Wed, 16 Mar 2016 15:05:13 +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/ruby.kak | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rc/base/ruby.kak b/rc/base/ruby.kak index 6b8b46f1..dd755529 100644 --- a/rc/base/ruby.kak +++ b/rc/base/ruby.kak @@ -61,6 +61,31 @@ addhl -group /ruby/code regex \<(alias|and|begin|break|case|class|def|defined|do # Commands # ‾‾‾‾‾‾‾‾ +def ruby-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ + case $kak_buffile in + *spec/*_spec.rb) + altfile=$(eval echo $(echo $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) + [ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit + ;; + *.rb) + 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 s+[^/]'*'/++';'s/.rb$/_spec.rb/) + 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 _ruby_filter_around_selections %{ eval -draft -itersel %{ exec @@ -112,6 +137,8 @@ hook global WinSetOption filetype=ruby %{ hook window InsertChar \n -group ruby-indent _ruby_indent_on_new_line hook window InsertChar \n -group ruby-insert _ruby_insert_on_new_line + alias window alt ruby-alternative-file + set window comment_line_chars '#' set window comment_selection_chars '^begin=:^=end' @@ -125,4 +152,6 @@ hook global WinSetOption filetype=(?!ruby).* %{ rmhl ruby rmhooks window ruby-indent rmhooks window ruby-hooks + + unalias window alt ruby-alternative-file }