cucumber.vim 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. " Vim indent file
  2. " Language: Cucumber
  3. " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  4. " Last Change: 2013 May 30
  5. if exists("b:did_indent")
  6. finish
  7. endif
  8. let b:did_indent = 1
  9. setlocal autoindent
  10. setlocal indentexpr=GetCucumberIndent()
  11. setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F
  12. let b:undo_indent = 'setl ai< inde< indk<'
  13. " Only define the function once.
  14. if exists("*GetCucumberIndent")
  15. finish
  16. endif
  17. function! s:syn(lnum)
  18. return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name')
  19. endfunction
  20. function! GetCucumberIndent()
  21. let line = getline(prevnonblank(v:lnum-1))
  22. let cline = getline(v:lnum)
  23. let nline = getline(nextnonblank(v:lnum+1))
  24. let syn = s:syn(prevnonblank(v:lnum-1))
  25. let csyn = s:syn(v:lnum)
  26. let nsyn = s:syn(nextnonblank(v:lnum+1))
  27. if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
  28. " feature heading
  29. return 0
  30. elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
  31. " examples heading
  32. return 2 * &sw
  33. elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
  34. " background, scenario or outline heading
  35. return &sw
  36. elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
  37. " line after feature heading
  38. return &sw
  39. elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
  40. " line after examples heading
  41. return 3 * &sw
  42. elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
  43. " line after background, scenario or outline heading
  44. return 2 * &sw
  45. elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
  46. " tag or comment before a feature heading
  47. return 0
  48. elseif cline =~# '^\s*@'
  49. " other tags
  50. return &sw
  51. elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
  52. " mid-table
  53. " preserve indent
  54. return indent(prevnonblank(v:lnum-1))
  55. elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
  56. " first line of a table, relative indent
  57. return indent(prevnonblank(v:lnum-1)) + &sw
  58. elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
  59. " line after a table, relative unindent
  60. return indent(prevnonblank(v:lnum-1)) - &sw
  61. elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
  62. " comments on scenarios
  63. return &sw
  64. endif
  65. return indent(prevnonblank(v:lnum-1))
  66. endfunction
  67. " vim:set sts=2 sw=2: