]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/indent/cucumber.vim
Use yellow identifiers instead of red
[rbdr/dotfiles] / vim / indent / cucumber.vim
1 " Vim indent file
2 " Language: Cucumber
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
4 " Last Change: 2010 May 21
5
6 if exists("b:did_indent")
7 finish
8 endif
9 let b:did_indent = 1
10
11 setlocal autoindent
12 setlocal indentexpr=GetCucumberIndent()
13 setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F
14
15 let b:undo_indent = 'setl ai< inde< indk<'
16
17 " Only define the function once.
18 if exists("*GetCucumberIndent")
19 finish
20 endif
21
22 function! s:syn(lnum)
23 return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name')
24 endfunction
25
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:'
34 " feature heading
35 return 0
36 elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
37 " examples heading
38 return 2 * &sw
39 elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
40 " background, scenario or outline heading
41 return &sw
42 elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
43 " line after feature heading
44 return &sw
45 elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
46 " line after examples heading
47 return 3 * &sw
48 elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
49 " line after background, scenario or outline heading
50 return 2 * &sw
51 elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
52 " tag or comment before a feature heading
53 return 0
54 elseif cline =~# '^\s*@'
55 " other tags
56 return &sw
57 elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
58 " mid-table
59 " preserve indent
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
69 return &sw
70 endif
71 return indent(prevnonblank(v:lnum-1))
72 endfunction
73
74 " vim:set sts=2 sw=2: