From 01fe1500df97577452f755b526c09d8ed0c802ea Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Thu, 12 Sep 2013 16:17:03 +0200 Subject: Add support for basic languages coffee, cucumbeer, eruby, haml, haskell, javascript, json, less, nginx, ocaml, ruby, sass, scss, slim, stylus, textile, tmux --- ftplugin/cucumber.vim | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 ftplugin/cucumber.vim (limited to 'ftplugin/cucumber.vim') diff --git a/ftplugin/cucumber.vim b/ftplugin/cucumber.vim new file mode 100644 index 00000000..1c1f0f25 --- /dev/null +++ b/ftplugin/cucumber.vim @@ -0,0 +1,148 @@ +" 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") + nnoremap :exe jump('edit',v:count) + nnoremap [ :exe jump('edit',v:count) + nnoremap ] :exe jump('edit',v:count) + nnoremap ] :exe jump('split',v:count) + nnoremap :exe jump('split',v:count) + nnoremap d :exe jump('split',v:count) + nnoremap :exe jump('split',v:count) + nnoremap } :exe jump('pedit',v:count) + nnoremap [d :exe jump('pedit',v:count) + nnoremap ]d :exe jump('pedit',v:count) + let b:undo_ftplugin .= + \ "|sil! nunmap " . + \ "|sil! nunmap [" . + \ "|sil! nunmap ]" . + \ "|sil! nunmap ]" . + \ "|sil! nunmap " . + \ "|sil! nunmap d" . + \ "|sil! nunmap " . + \ "|sil! nunmap }" . + \ "|sil! nunmap [d" . + \ "|sil! nunmap ]d" +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*(\=\s*\zs\S.\{-\}\ze\s*)\=\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 = match(getline(a:lnum), '\S') + 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,'\\\@