| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  | " Vim indent file | 
					
						
							|  |  |  | " Language:	Cucumber | 
					
						
							|  |  |  | " Maintainer:	Tim Pope <vimNOSPAM@tpope.org> | 
					
						
							| 
									
										
										
										
											2017-06-13 18:12:01 +02:00
										 |  |  | " Last Change:	2017 Jun 13 | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01: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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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) | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |   let nline = getline(nextnonblank(v:lnum+1)) | 
					
						
							| 
									
										
										
										
											2017-06-13 18:12:01 +02:00
										 |  |  |   let sw = exists('*shiftwidth') ? shiftwidth() : shiftwidth() | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |   let syn = s:syn(prevnonblank(v:lnum-1)) | 
					
						
							|  |  |  |   let csyn = s:syn(v:lnum) | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |   let nsyn = s:syn(nextnonblank(v:lnum+1)) | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |   if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " feature heading | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |     return 0 | 
					
						
							|  |  |  |   elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " examples heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return 2 * sw | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |   elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " background, scenario or outline heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return sw | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |   elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " line after feature heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return sw | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |   elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):' | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |     " line after examples heading | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return 3 * sw | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |   elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):' | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |   elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0) | 
					
						
							|  |  |  |     " tag or comment before a feature heading | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |     return 0 | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |   elseif cline =~# '^\s*@' | 
					
						
							|  |  |  |     " other tags | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return sw | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |   elseif cline =~# '^\s*[#|]' && line =~# '^\s*|' | 
					
						
							|  |  |  |     " mid-table | 
					
						
							|  |  |  |     " preserve indent | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |     return indent(prevnonblank(v:lnum-1)) | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |   elseif cline =~# '^\s*|' && line =~# '^\s*[^|]' | 
					
						
							|  |  |  |     " first line of a table, relative indent | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return indent(prevnonblank(v:lnum-1)) + sw | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |   elseif cline =~# '^\s*[^|]' && line =~# '^\s*|' | 
					
						
							|  |  |  |     " line after a table, relative unindent | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return indent(prevnonblank(v:lnum-1)) - sw | 
					
						
							| 
									
										
										
										
											2013-06-01 14:50:56 +02:00
										 |  |  |   elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):') | 
					
						
							|  |  |  |     " comments on scenarios | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     return sw | 
					
						
							| 
									
										
										
										
											2010-03-02 16:19:40 +01:00
										 |  |  |   endif | 
					
						
							|  |  |  |   return indent(prevnonblank(v:lnum-1)) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " vim:set sts=2 sw=2: |