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> |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 4 | " Last Change: 2010 May 21 |
Bram Moolenaar | 5e3dae8 | 2010-03-02 16:19:40 +0100 | [diff] [blame] | 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 | " Only define the function once. |
| 16 | if exists("*GetCucumberIndent") |
| 17 | finish |
| 18 | endif |
| 19 | |
| 20 | function! s:syn(lnum) |
| 21 | return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name') |
| 22 | endfunction |
| 23 | |
| 24 | function! 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)) |
| 58 | endfunction |
| 59 | |
| 60 | " vim:set sts=2 sw=2: |