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