From 13e6c34c3545b661689f09daa900ca1105a9e564 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Wed, 16 Mar 2016 15:05:13 +0100 Subject: [PATCH 1/2] =?UTF-8?q?add=20:alt=20command=20to=20jump=20to=20the?= =?UTF-8?q?=20alternate=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 6b8b46f18..dd755529a 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 } From 1a3d7e58ab77a2007835039c38f79b926a649eb6 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 17 Mar 2016 11:48:27 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Help=20Kakoune=20to=20better=20detect=20/?= =?UTF-8?q?=E2=80=A6/=20literals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rc/base/ruby.kak | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rc/base/ruby.kak b/rc/base/ruby.kak index dd755529a..b4f9e86a5 100644 --- a/rc/base/ruby.kak +++ b/rc/base/ruby.kak @@ -27,7 +27,8 @@ addhl -group / regions -default code ruby \ literal '%[iqrswxIQRSWX]\(' \) \( \ literal '%[iqrswxIQRSWX]\{' \} \{ \ literal '%[iqrswxIQRSWX]\[' \] \[ \ - literal '%[iqrswxIQRSWX]<' > < + literal '%[iqrswxIQRSWX]<' > < \ + division '[\w\)\]](/|(\h+/\h+))' '\w' '' # Help Kakoune to better detect /…/ literals # Regular expression flags are: i → ignore case, m → multi-lines, o → only interpolate #{} blocks once, x → extended mode (ignore white spaces) # Literals are: i → array of symbols, q → string, r → regular expression, s → symbol, w → array of words, x → capture shell result