xref: /vim-8.2.3635/runtime/indent/cucumber.vim (revision 3ec574f2)
1" Vim indent file
2" Language:	Cucumber
3" Maintainer:	Tim Pope <[email protected]>
4" Last Change:	2017 Jun 13
5
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
15let b:undo_indent = 'setl ai< inde< indk<'
16
17" Only define the function once.
18if exists("*GetCucumberIndent")
19  finish
20endif
21
22function! s:syn(lnum)
23  return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name')
24endfunction
25
26function! 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 sw = exists('*shiftwidth') ? shiftwidth() : shiftwidth()
31  let syn = s:syn(prevnonblank(v:lnum-1))
32  let csyn = s:syn(v:lnum)
33  let nsyn = s:syn(nextnonblank(v:lnum+1))
34  if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
35    " feature heading
36    return 0
37  elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
38    " examples heading
39    return 2 * sw
40  elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
41    " background, scenario or outline heading
42    return sw
43  elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
44    " line after feature heading
45    return sw
46  elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
47    " line after examples heading
48    return 3 * sw
49  elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
50    " line after background, scenario or outline heading
51    return 2 * sw
52  elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
53    " tag or comment before a feature heading
54    return 0
55  elseif cline =~# '^\s*@'
56    " other tags
57    return sw
58  elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
59    " mid-table
60    " preserve indent
61    return indent(prevnonblank(v:lnum-1))
62  elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
63    " first line of a table, relative indent
64    return indent(prevnonblank(v:lnum-1)) + sw
65  elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
66    " line after a table, relative unindent
67    return indent(prevnonblank(v:lnum-1)) - sw
68  elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
69    " comments on scenarios
70    return sw
71  endif
72  return indent(prevnonblank(v:lnum-1))
73endfunction
74
75" vim:set sts=2 sw=2:
76