2014-07-10 21:05:51 -07:00
|
|
|
" Vim indent file
|
|
|
|
" Language: Cucumber
|
|
|
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
2017-11-06 17:34:28 -07:00
|
|
|
" Last Change: 2017 Jun 13
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
if exists("b:did_indent")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let b:did_indent = 1
|
|
|
|
|
|
|
|
setlocal autoindent
|
|
|
|
setlocal indentexpr=GetCucumberIndent()
|
|
|
|
setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F
|
|
|
|
|
|
|
|
let b:undo_indent = 'setl ai< inde< indk<'
|
|
|
|
|
|
|
|
" Only define the function once.
|
|
|
|
if exists("*GetCucumberIndent")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
function! s:syn(lnum)
|
|
|
|
return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! GetCucumberIndent()
|
|
|
|
let line = getline(prevnonblank(v:lnum-1))
|
|
|
|
let cline = getline(v:lnum)
|
|
|
|
let nline = getline(nextnonblank(v:lnum+1))
|
2017-11-06 17:34:28 -07:00
|
|
|
let sw = exists('*shiftwidth') ? shiftwidth() : shiftwidth()
|
2014-07-10 21:05:51 -07:00
|
|
|
let syn = s:syn(prevnonblank(v:lnum-1))
|
|
|
|
let csyn = s:syn(v:lnum)
|
|
|
|
let nsyn = s:syn(nextnonblank(v:lnum+1))
|
|
|
|
if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
|
|
|
|
" feature heading
|
|
|
|
return 0
|
|
|
|
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
|
|
|
|
" examples heading
|
2017-04-28 12:06:44 -07:00
|
|
|
return 2 * sw
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
|
|
|
" background, scenario or outline heading
|
2017-04-28 12:06:44 -07:00
|
|
|
return sw
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
|
|
|
|
" line after feature heading
|
2017-04-28 12:06:44 -07:00
|
|
|
return sw
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
|
|
|
|
" line after examples heading
|
2017-04-28 12:06:44 -07:00
|
|
|
return 3 * sw
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
|
|
|
" line after background, scenario or outline heading
|
2017-04-28 12:06:44 -07:00
|
|
|
return 2 * sw
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
|
|
|
|
" tag or comment before a feature heading
|
|
|
|
return 0
|
|
|
|
elseif cline =~# '^\s*@'
|
|
|
|
" other tags
|
2017-04-28 12:06:44 -07:00
|
|
|
return sw
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
|
|
|
|
" mid-table
|
|
|
|
" preserve indent
|
|
|
|
return indent(prevnonblank(v:lnum-1))
|
|
|
|
elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
|
|
|
|
" first line of a table, relative indent
|
2017-04-28 12:06:44 -07:00
|
|
|
return indent(prevnonblank(v:lnum-1)) + sw
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
|
|
|
|
" line after a table, relative unindent
|
2017-04-28 12:06:44 -07:00
|
|
|
return indent(prevnonblank(v:lnum-1)) - sw
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
|
|
|
|
" comments on scenarios
|
2017-04-28 12:06:44 -07:00
|
|
|
return sw
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
return indent(prevnonblank(v:lnum-1))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" vim:set sts=2 sw=2:
|