@@ -53,31 +53,49 @@ function! GetCucumberIndent(...) abort
5353 let sw = shiftwidth ()
5454 let prev = s: Line (prevnonblank (lnum- 1 ))
5555 let curr = s: Line (lnum)
56- let next = s: Line (nextnonblank (lnum+ 1 ))
57- if curr.heading == # ' feature'
58- " feature heading
56+
57+ if (curr.tag || curr.comment ) && (prev .tag || prev .comment )
58+ return prev .indent
59+ endif
60+
61+ let head = prev
62+ while head.lnum > 0 && empty (head.heading)
63+ let head = s: Line (prevnonblank (head.lnum- 1 ))
64+ endwhile
65+ if curr.comment && getline (curr.lnum- 1 ) = ~# ' ^\s*$' || curr.tag
66+ let next = s: Line (nextnonblank (curr.lnum+ 1 ))
67+ while next .comment || next .tag
68+ let next = s: Line (nextnonblank (next .lnum+ 1 ))
69+ endwhile
70+ " if a comment or tag appears precedes a heading...
71+ if ! empty (next .heading)
72+ " indent it like we would the heading
73+ let curr = next
74+ endif
75+ endif
76+
77+ if ! empty (prev .heading) && empty (curr.heading)
78+ " for a non-heading after a heading, increase the indent
79+ return prev .indent + sw
80+ elseif ! empty (curr.heading) && curr.heading == # head.heading
81+ " if the previous section is a peer, match the heading's indent
82+ return head.indent
83+ elseif curr.heading == # ' feature'
5984 return 0
60- elseif curr.heading == # ' examples'
61- " examples heading
62- return 2 * sw
63- elseif curr.heading == # ' bg_or_scenario'
64- " background, scenario or outline heading
65- return sw
66- elseif prev .heading == # ' feature'
67- " line after feature heading
85+ elseif curr.heading == # ' rule'
6886 return sw
69- elseif prev .heading == # ' examples'
70- " line after examples heading
71- return 3 * sw
72- elseif prev .heading == # ' bg_or_scenario'
73- " line after background, scenario or outline heading
74- return 2 * sw
75- elseif (curr.tag || curr.comment ) && (next .heading == # ' feature' || prev .indent <= 0 )
76- " tag or comment before a feature heading
87+ elseif curr.heading == # ' bg_or_scenario' && head.heading == # ' examples'
88+ return head.indent - sw
89+ elseif (curr.heading == # ' bg_or_scenario' && head.heading == # ' rule' ) || (curr.heading == # ' examples' && head.heading == # ' bg_or_scenario' )
90+ return head.indent + sw
91+ elseif (head.heading == # ' rule' || head.heading == # ' feature' ) && ! empty (curr.heading)
92+ return head.indent + sw
93+ elseif curr.tag && empty (head.heading)
7794 return 0
95+ elseif curr.tag && head.heading == # ' examples'
96+ return head.indent - sw
7897 elseif curr.tag
79- " other tags
80- return sw
98+ return head.indent
8199 elseif (curr.table || curr.comment ) && prev .table
82100 " mid-table
83101 " preserve indent
@@ -88,9 +106,8 @@ function! GetCucumberIndent(...) abort
88106 elseif ! curr.table && prev .table
89107 " line after a table, relative unindent
90108 return prev .indent - sw
91- elseif curr.comment && getline (v: lnum- 1 ) = ~# ' ^\s*$' && next .heading == # ' bg_or_scenario'
92- " comments on scenarios
93- return sw
109+ endif
110+
94111 endif
95112 return prev .indent < 0 ? 0 : prev .indent
96113endfunction
0 commit comments