annotate runtime/ftplugin/cucumber.vim @ 3354:72146e7f47fa v7.3.444

updated for version 7.3.444 Problem: ":all!" and ":sall!" give error E477, even though the documentation says these are valid commands. Solution: Support the exclamation mark. (Hirohito Higashi)
author Bram Moolenaar <bram@vim.org>
date Mon, 13 Feb 2012 00:01:43 +0100
parents 713a4965ee7f
children 2eb30f341e8d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
1 " Vim filetype plugin
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
2 " Language: Cucumber
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
2526
713a4965ee7f Runtime file updates. (Tim Pope)
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
4 " Last Change: 2010 Aug 09
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
5
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
6 " Only do this when not done yet for this buffer
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
7 if (exists("b:did_ftplugin"))
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
8 finish
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
9 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
10 let b:did_ftplugin = 1
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
11
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
12 setlocal formatoptions-=t formatoptions+=croql
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
13 setlocal comments=:# commentstring=#\ %s
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
14 setlocal omnifunc=CucumberComplete
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
15
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
16 let b:undo_ftplugin = "setl fo< com< cms< ofu<"
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
17
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
18 let b:cucumber_root = expand('%:p:h:s?.*[\/]\%(features\|stories\)\zs[\/].*??')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
19
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
20 if !exists("g:no_plugin_maps") && !exists("g:no_cucumber_maps")
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
21 nmap <silent><buffer> <C-]> :<C-U>exe <SID>jump('edit',v:count)<CR>
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
22 nmap <silent><buffer> <C-W>] :<C-U>exe <SID>jump('split',v:count)<CR>
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
23 nmap <silent><buffer> <C-W><C-]> :<C-U>exe <SID>jump('split',v:count)<CR>
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
24 nmap <silent><buffer> <C-W>} :<C-U>exe <SID>jump('pedit',v:count)<CR>
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
25 let b:undo_ftplugin .= "| sil! iunmap! <C-]>| sil! iunmap! <C-W>]| sil! iunmap! <C-W><C-]>| sil! iunmap! <C-W>}"
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
26 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
27
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
28 function! s:jump(command,count)
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
29 let steps = s:steps('.')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
30 if len(steps) == 0 || len(steps) < a:count
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
31 return 'echoerr "No matching step found"'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
32 elseif len(steps) > 1 && !a:count
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
33 return 'echoerr "Multiple matching steps found"'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
34 else
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
35 let c = a:count ? a:count-1 : 0
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
36 return a:command.' +'.steps[c][1].' '.escape(steps[c][0],' %#')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
37 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
38 endfunction
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
39
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
40 function! s:allsteps()
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
41 let step_pattern = '\C^\s*\K\k*\>\s*\zs\S.\{-\}\ze\s*\%(do\|{\)\s*\%(|[^|]*|\s*\)\=\%($\|#\)'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
42 let steps = []
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
43 for file in split(glob(b:cucumber_root.'/**/*.rb'),"\n")
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
44 let lines = readfile(file)
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
45 let num = 0
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
46 for line in lines
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
47 let num += 1
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
48 if line =~ step_pattern
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
49 let type = matchstr(line,'\w\+')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
50 let steps += [[file,num,type,matchstr(line,step_pattern)]]
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
51 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
52 endfor
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
53 endfor
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
54 return steps
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
55 endfunction
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
56
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
57 function! s:steps(lnum)
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
58 let c = indent(a:lnum) + 1
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
59 while synIDattr(synID(a:lnum,c,1),'name') !~# '^$\|Region$'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
60 let c = c + 1
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
61 endwhile
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
62 let step = matchstr(getline(a:lnum)[c-1 : -1],'^\s*\zs.\{-\}\ze\s*$')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
63 return filter(s:allsteps(),'s:stepmatch(v:val[3],step)')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
64 endfunction
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
65
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
66 function! s:stepmatch(receiver,target)
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
67 if a:receiver =~ '^[''"].*[''"]$'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
68 let pattern = '^'.escape(substitute(a:receiver[1:-2],'$\w\+','(.*)','g'),'/').'$'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
69 elseif a:receiver =~ '^/.*/$'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
70 let pattern = a:receiver[1:-2]
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
71 elseif a:receiver =~ '^%r..*.$'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
72 let pattern = escape(a:receiver[3:-2],'/')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
73 else
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
74 return 0
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
75 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
76 try
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
77 let vimpattern = substitute(substitute(pattern,'\\\@<!(?:','%(','g'),'\\\@<!\*?','{-}','g')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
78 if a:target =~# '\v'.vimpattern
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
79 return 1
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
80 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
81 catch
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
82 endtry
2526
713a4965ee7f Runtime file updates. (Tim Pope)
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
83 if has("ruby") && pattern !~ '\\\@<!#{'
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
84 ruby VIM.command("return #{if (begin; Kernel.eval('/'+VIM.evaluate('pattern')+'/'); rescue SyntaxError; end) === VIM.evaluate('a:target') then 1 else 0 end}")
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
85 else
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
86 return 0
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
87 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
88 endfunction
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
89
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
90 function! s:bsub(target,pattern,replacement)
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
91 return substitute(a:target,'\C\\\@<!'.a:pattern,a:replacement,'g')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
92 endfunction
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
93
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
94 function! CucumberComplete(findstart,base) abort
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
95 let indent = indent('.')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
96 let group = synIDattr(synID(line('.'),indent+1,1),'name')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
97 let type = matchstr(group,'\Ccucumber\zs\%(Given\|When\|Then\)')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
98 let e = matchend(getline('.'),'^\s*\S\+\s')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
99 if type == '' || col('.') < col('$') || e < 0
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
100 return -1
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
101 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
102 if a:findstart
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
103 return e
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
104 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
105 let steps = []
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
106 for step in s:allsteps()
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
107 if step[2] ==# type
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
108 if step[3] =~ '^[''"]'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
109 let steps += [step[3][1:-2]]
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
110 elseif step[3] =~ '^/\^.*\$/$'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
111 let pattern = step[3][2:-3]
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
112 let pattern = substitute(pattern,'\C^(?:|I )','I ','')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
113 let pattern = s:bsub(pattern,'\\[Sw]','w')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
114 let pattern = s:bsub(pattern,'\\d','1')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
115 let pattern = s:bsub(pattern,'\\[sWD]',' ')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
116 let pattern = s:bsub(pattern,'\[\^\\\="\]','_')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
117 let pattern = s:bsub(pattern,'[[:alnum:]. _-][?*]?\=','')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
118 let pattern = s:bsub(pattern,'\[\([^^]\).\{-\}\]','\1')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
119 let pattern = s:bsub(pattern,'+?\=','')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
120 let pattern = s:bsub(pattern,'(\([[:alnum:]. -]\{-\}\))','\1')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
121 let pattern = s:bsub(pattern,'\\\([[:punct:]]\)','\1')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
122 if pattern !~ '[\\()*?]'
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
123 let steps += [pattern]
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
124 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
125 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
126 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
127 endfor
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
128 call filter(steps,'strpart(v:val,0,strlen(a:base)) ==# a:base')
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
129 return sort(steps)
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
130 endfunction
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
131
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
132 " vim:set sts=2 sw=2: