robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
34b4df774d
master
1" Vim indent file 2" Language: Cucumber 3" Maintainer: Tim Pope <vimNOSPAM@tpope.org> 4" Last Change: 2023 Dec 28 5" 2025 Apr 16 by Vim Project (set 'cpoptions' for line continuation, #17121) 6 7if exists ( "b:did_indent" ) 8finish 9endif 10let b: did_indent = 1 11let s: cpo_save = & cpo 12set cpo & vim 13 14setlocal autoindent 15setlocal indentexpr = GetCucumberIndent () 16setlocal indentkeys = o,O,*<Return>,<:>,0<Bar>,0#,=,!^F 17 18let b: undo_indent = 'setl ai< inde< indk<' 19 20" Only define the function once. 21if exists ( "*GetCucumberIndent" ) 22finish 23endif 24 25let s: headings = { 26 \'Feature' : 'feature' , 27 \'Rule' : 'rule' , 28 \'Background' : 'bg_or_scenario' , 29 \'Scenario' : 'bg_or_scenario' , 30 \'ScenarioOutline' : 'bg_or_scenario' , 31 \'Examples' : 'examples' , 32 \'Scenarios' : 'examples' } 33 34function ! s: Line ( lnum ) abort 35if getline ( a: lnum ) =~# ':' 36let group = matchstr ( synIDattr ( synID ( a: lnum , 1 + indent ( a: lnum ), 1 ), 'name' ), '^cucumber\zs.*' ) 37if ! has_key ( s: headings , group ) 38let group = substitute ( matchstr ( getline ( a: lnum ), '^\s*\zs\%([^:]\+\)\ze:\S\@!' ), '\s\+' , '' , 'g' ) 39endif 40else 41let group = '' 42endif 43let char = matchstr ( getline ( a: lnum ), '^\s*\zs[[:punct:]]' ) 44return { 45 \'lnum' : a: lnum , 46 \'indent' : indent ( a: lnum ), 47 \'heading' : get ( s: headings , group , '' ), 48 \'tag' : char ==# '@' , 49 \'table' : char ==# '|' , 50 \'comment' : char ==# '#' , 51 \} 52endfunction 53 54function ! GetCucumberIndent (...) abort 55let lnum = a: 0 ? a: 1 : v: lnum 56let sw = shiftwidth () 57let prev = s: Line ( prevnonblank ( lnum - 1 )) 58let curr = s: Line ( lnum ) 59let next = s: Line ( nextnonblank ( lnum + 1 )) 60if curr . heading ==# 'feature' 61" feature heading 62return 0 63elseif curr . heading ==# 'examples' 64" examples heading 65return 2 * sw 66elseif curr . heading ==# 'bg_or_scenario' 67" background, scenario or outline heading 68return sw 69elseif prev . heading ==# 'feature' 70" line after feature heading 71return sw 72elseif prev . heading ==# 'examples' 73" line after examples heading 74return 3 * sw 75elseif prev . heading ==# 'bg_or_scenario' 76" line after background, scenario or outline heading 77return 2 * sw 78elseif ( curr . tag || curr . comment ) && ( next . heading ==# 'feature' || prev . indent <= 0 ) 79" tag or comment before a feature heading 80return 0 81elseif curr . tag 82" other tags 83return sw 84elseif ( curr . table || curr . comment ) && prev . table 85" mid-table 86" preserve indent 87return prev . indent 88elseif curr . table && ! prev . table 89" first line of a table, relative indent 90return prev . indent + sw 91elseif ! curr . table && prev . table 92" line after a table, relative unindent 93return prev . indent - sw 94elseif curr . comment && getline ( v: lnum - 1 ) =~# '^\s*$' && next . heading ==# 'bg_or_scenario' 95" comments on scenarios 96return sw 97endif 98return prev . indent < 0 ? 0 : prev . indent 99endfunction 100 101let & cpo = s: cpo_save 102unlet s: cpo_save 103 104" vim:set sts=2 sw=2: