blob: a19d123f7ea7c2ae791206a4dd867f04ba3b989f [file] [log] [blame]
Bram Moolenaar5e3dae82010-03-02 16:19:40 +01001" Vim indent file
2" Language: Cucumber
3" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
Bram Moolenaar7a329912010-05-21 12:05:36 +02004" Last Change: 2010 May 21
Bram Moolenaar5e3dae82010-03-02 16:19:40 +01005
6if exists("b:did_indent")
7 finish
8endif
9let b:did_indent = 1
10
11setlocal autoindent
12setlocal indentexpr=GetCucumberIndent()
13setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F
14
15" Only define the function once.
16if exists("*GetCucumberIndent")
17 finish
18endif
19
20function! s:syn(lnum)
21 return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name')
22endfunction
23
24function! GetCucumberIndent()
25 let line = getline(prevnonblank(v:lnum-1))
26 let cline = getline(v:lnum)
27 let syn = s:syn(prevnonblank(v:lnum-1))
28 let csyn = s:syn(v:lnum)
29 if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
30 return 0
31 elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
32 return 2 * &sw
33 elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
34 return &sw
35 elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
36 return &sw
37 elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
38 return 3 * &sw
39 elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
40 return 2 * &sw
41 elseif cline =~# '^\s*@' && (s:syn(nextnonblank(v:lnum+1)) == 'cucumberFeature' || getline(nextnonblank(v:lnum+1)) =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
42 return 0
43 elseif line =~# '^\s*@'
44 return &sw
45 elseif cline =~# '^\s*|' && line =~# '^\s*|'
46 return indent(prevnonblank(v:lnum-1))
47 elseif cline =~# '^\s*|' && line =~# '^\s*[^|#]'
48 return indent(prevnonblank(v:lnum-1)) + &sw
49 elseif cline =~# '^\s*[^|# \t]' && line =~# '^\s*|'
50 return indent(prevnonblank(v:lnum-1)) - &sw
51 elseif cline =~# '^\s*$' && line =~# '^\s*|'
52 let in = indent(prevnonblank(v:lnum-1))
53 return in == indent(v:lnum) ? in : in - &sw
54 elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && getline(v:lnum+1) =~# '\S'
55 return indent(getline(v:lnum+1))
56 endif
57 return indent(prevnonblank(v:lnum-1))
58endfunction
59
60" vim:set sts=2 sw=2: