3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
4 " Last Change: 2010 May 21
6 if exists("b:did_indent")
12 setlocal indentexpr=GetCucumberIndent()
13 setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F
15 let b:undo_indent = 'setl ai< inde< indk<'
17 " Only define the function once.
18 if exists("*GetCucumberIndent")
23 return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name')
26 function! GetCucumberIndent()
27 let line = getline(prevnonblank(v:lnum-1))
28 let cline = getline(v:lnum)
29 let nline = getline(nextnonblank(v:lnum+1))
30 let syn = s:syn(prevnonblank(v:lnum-1))
31 let csyn = s:syn(v:lnum)
32 let nsyn = s:syn(nextnonblank(v:lnum+1))
33 if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
36 elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
39 elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
40 " background, scenario or outline heading
42 elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
43 " line after feature heading
45 elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
46 " line after examples heading
48 elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
49 " line after background, scenario or outline heading
51 elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
52 " tag or comment before a feature heading
54 elseif cline =~# '^\s*@'
57 elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
60 return indent(prevnonblank(v:lnum-1))
61 elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
62 " first line of a table, relative indent
63 return indent(prevnonblank(v:lnum-1)) + &sw
64 elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
65 " line after a table, relative unindent
66 return indent(prevnonblank(v:lnum-1)) - &sw
67 elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
68 " comments on scenarios
71 return indent(prevnonblank(v:lnum-1))