Skip to content

Commit

Permalink
Improve indentation of tags and comments.
Browse files Browse the repository at this point in the history
Tags on features are indented at 0.

Other tags are indented at the same level as Scenario headers (one
shiftwidth). This matches all the examples I have read.

Comments above a feature are indented at 0.

Comments after a blank line are indented at the same level as Scenario
headers (one shiftwidth).

All other comments preserve the indent of the line before them.
  • Loading branch information
puyo authored and tpope committed Oct 31, 2010
1 parent 01aaa43 commit 880d335
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions indent/cucumber.vim
Expand Up @@ -29,32 +29,42 @@ function! GetCucumberIndent()
let csyn = s:syn(v:lnum)
let nsyn = s:syn(nextnonblank(v:lnum+1))
if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
" feature heading
return 0
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
" examples heading
return 2 * &sw
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
" background, scenario or outline heading
return &sw
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
" line after feature heading
return &sw
elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
" line after examples heading
return 3 * &sw
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
" line after background, scenario or outline heading
return 2 * &sw
elseif cline =~# '^\s*@' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
" tag or comment before a feature heading
return 0
elseif line =~# '^\s*@'
elseif cline =~# '^\s*@'
" other tags
return &sw
elseif cline =~# '^\s*|' && line =~# '^\s*|'
elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
" mid-table
" preserve indent
return indent(prevnonblank(v:lnum-1))
elseif cline =~# '^\s*|' && line =~# '^\s*[^|#]'
elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
" first line of a table, relative indent
return indent(prevnonblank(v:lnum-1)) + &sw
elseif cline =~# '^\s*[^|# \t]' && line =~# '^\s*|'
elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
" line after a table, relative unindent
return indent(prevnonblank(v:lnum-1)) - &sw
elseif cline =~# '^\s*$' && line =~# '^\s*|'
let in = indent(prevnonblank(v:lnum-1))
return in == indent(v:lnum) ? in : in - &sw
elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && getline(v:lnum+1) =~# '\S'
return indent(getline(v:lnum+1))
elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
" comments on scenarios
return &sw
endif
return indent(prevnonblank(v:lnum-1))
endfunction
Expand Down

0 comments on commit 880d335

Please sign in to comment.