| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  | " Vim indent file | 
					
						
							|  |  |  | " Language:	Cucumber | 
					
						
							|  |  |  | " Maintainer:	Tim Pope <vimNOSPAM@tpope.org> | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  | " Last Change:	2023 Dec 28 | 
					
						
							| 
									
										
										
										
											2025-04-16 18:20:59 +02:00
										 |  |  | " 2025 Apr 16 by Vim Project (set 'cpoptions' for line continuation, #17121) | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | if exists("b:did_indent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | let b:did_indent = 1 | 
					
						
							| 
									
										
										
										
											2025-04-16 18:20:59 +02:00
										 |  |  | let s:cpo_save = &cpo | 
					
						
							|  |  |  | set cpo&vim | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | setlocal autoindent | 
					
						
							|  |  |  | setlocal indentexpr=GetCucumberIndent() | 
					
						
							|  |  |  | setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  | let b:undo_indent = 'setl ai< inde< indk<' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  | " Only define the function once. | 
					
						
							|  |  |  | if exists("*GetCucumberIndent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  | let s:headings = { | 
					
						
							|  |  |  |       \ 'Feature': 'feature', | 
					
						
							|  |  |  |       \ 'Rule': 'rule', | 
					
						
							|  |  |  |       \ 'Background': 'bg_or_scenario', | 
					
						
							|  |  |  |       \ 'Scenario': 'bg_or_scenario', | 
					
						
							|  |  |  |       \ 'ScenarioOutline': 'bg_or_scenario', | 
					
						
							|  |  |  |       \ 'Examples': 'examples', | 
					
						
							|  |  |  |       \ 'Scenarios': 'examples'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function! s:Line(lnum) abort | 
					
						
							|  |  |  |   if getline(a:lnum) =~# ':' | 
					
						
							|  |  |  |     let group = matchstr(synIDattr(synID(a:lnum,1+indent(a:lnum), 1), 'name'), '^cucumber\zs.*') | 
					
						
							|  |  |  |     if !has_key(s:headings, group) | 
					
						
							|  |  |  |       let group = substitute(matchstr(getline(a:lnum), '^\s*\zs\%([^:]\+\)\ze:\S\@!'), '\s\+', '', 'g') | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     let group = '' | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   let char = matchstr(getline(a:lnum), '^\s*\zs[[:punct:]]') | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |         \ 'lnum': a:lnum, | 
					
						
							|  |  |  |         \ 'indent': indent(a:lnum), | 
					
						
							|  |  |  |         \ 'heading': get(s:headings, group, ''), | 
					
						
							|  |  |  |         \ 'tag': char ==# '@', | 
					
						
							|  |  |  |         \ 'table': char ==# '|', | 
					
						
							|  |  |  |         \ 'comment': char ==# '#', | 
					
						
							|  |  |  |         \ } | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  | function! GetCucumberIndent(...) abort | 
					
						
							|  |  |  |   let lnum = a:0 ? a:1 : v:lnum | 
					
						
							|  |  |  |   let sw = shiftwidth() | 
					
						
							|  |  |  |   let prev = s:Line(prevnonblank(lnum-1)) | 
					
						
							|  |  |  |   let curr = s:Line(lnum) | 
					
						
							|  |  |  |   let next = s:Line(nextnonblank(lnum+1)) | 
					
						
							|  |  |  |   if curr.heading ==# 'feature' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " feature heading | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |     return 0 | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   elseif curr.heading ==# 'examples' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " examples heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return 2 * sw | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   elseif curr.heading ==# 'bg_or_scenario' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " background, scenario or outline heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return sw | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   elseif prev.heading ==# 'feature' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " line after feature heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return sw | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   elseif prev.heading ==# 'examples' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " line after examples heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return 3 * sw | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   elseif prev.heading ==# 'bg_or_scenario' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " line after background, scenario or outline heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return 2 * sw | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   elseif (curr.tag || curr.comment) && (next.heading ==# 'feature' || prev.indent <= 0) | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " tag or comment before a feature heading | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |     return 0 | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   elseif curr.tag | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " other tags | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return sw | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   elseif (curr.table || curr.comment) && prev.table | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " mid-table | 
					
						
							|  |  |  |     " preserve indent | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |     return prev.indent | 
					
						
							|  |  |  |   elseif curr.table && !prev.table | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " first line of a table, relative indent | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |     return prev.indent + sw | 
					
						
							|  |  |  |   elseif !curr.table && prev.table | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " line after a table, relative unindent | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |     return prev.indent - sw | 
					
						
							|  |  |  |   elseif curr.comment && getline(v:lnum-1) =~# '^\s*$' && next.heading ==# 'bg_or_scenario' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " comments on scenarios | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return sw | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2023-12-28 13:03:39 -05:00
										 |  |  |   return prev.indent < 0 ? 0 : prev.indent | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 18:20:59 +02:00
										 |  |  | let &cpo = s:cpo_save | 
					
						
							|  |  |  | unlet s:cpo_save | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  | " vim:set sts=2 sw=2: |