" Vim filetype plugin " Language: Cucumber " Maintainer: Tim Pope " Last Change: 2010 Aug 09 " Only do this when not done yet for this buffer if (exists("b:did_ftplugin")) finish endif let b:did_ftplugin = 1 setlocal formatoptions-=t formatoptions+=croql setlocal comments=:# commentstring=#\ %s setlocal omnifunc=CucumberComplete let b:undo_ftplugin = "setl fo< com< cms< ofu<" let b:cucumber_root = expand('%:p:h:s?.*[\/]\%(features\|stories\)\zs[\/].*??') if !exists("g:no_plugin_maps") && !exists("g:no_cucumber_maps") nmap :exe jump('edit',v:count) nmap ] :exe jump('split',v:count) nmap :exe jump('split',v:count) nmap } :exe jump('pedit',v:count) let b:undo_ftplugin .= "| sil! iunmap! | sil! iunmap! ]| sil! iunmap! | sil! iunmap! }" endif function! s:jump(command,count) let steps = s:steps('.') if len(steps) == 0 || len(steps) < a:count return 'echoerr "No matching step found"' elseif len(steps) > 1 && !a:count return 'echoerr "Multiple matching steps found"' else let c = a:count ? a:count-1 : 0 return a:command.' +'.steps[c][1].' '.escape(steps[c][0],' %#') endif endfunction function! s:allsteps() let step_pattern = '\C^\s*\K\k*\>\s*\zs\S.\{-\}\ze\s*\%(do\|{\)\s*\%(|[^|]*|\s*\)\=\%($\|#\)' let steps = [] for file in split(glob(b:cucumber_root.'/**/*.rb'),"\n") let lines = readfile(file) let num = 0 for line in lines let num += 1 if line =~ step_pattern let type = matchstr(line,'\w\+') let steps += [[file,num,type,matchstr(line,step_pattern)]] endif endfor endfor return steps endfunction function! s:steps(lnum) let c = indent(a:lnum) + 1 while synIDattr(synID(a:lnum,c,1),'name') !~# '^$\|Region$' let c = c + 1 endwhile let step = matchstr(getline(a:lnum)[c-1 : -1],'^\s*\zs.\{-\}\ze\s*$') return filter(s:allsteps(),'s:stepmatch(v:val[3],step)') endfunction function! s:stepmatch(receiver,target) if a:receiver =~ '^[''"].*[''"]$' let pattern = '^'.escape(substitute(a:receiver[1:-2],'$\w\+','(.*)','g'),'/').'$' elseif a:receiver =~ '^/.*/$' let pattern = a:receiver[1:-2] elseif a:receiver =~ '^%r..*.$' let pattern = escape(a:receiver[3:-2],'/') else return 0 endif try let vimpattern = substitute(substitute(pattern,'\\\@