cucumber.vim 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. " Vim indent file
  2. " Language: Cucumber
  3. " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  4. " Last Change: 2017 Jun 13
  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 sw = exists('*shiftwidth') ? shiftwidth() : shiftwidth()
  25. let syn = s:syn(prevnonblank(v:lnum-1))
  26. let csyn = s:syn(v:lnum)
  27. let nsyn = s:syn(nextnonblank(v:lnum+1))
  28. if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
  29. " feature heading
  30. return 0
  31. elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
  32. " examples heading
  33. return 2 * sw
  34. elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
  35. " background, scenario or outline heading
  36. return sw
  37. elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
  38. " line after feature heading
  39. return sw
  40. elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
  41. " line after examples heading
  42. return 3 * sw
  43. elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
  44. " line after background, scenario or outline heading
  45. return 2 * sw
  46. elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
  47. " tag or comment before a feature heading
  48. return 0
  49. elseif cline =~# '^\s*@'
  50. " other tags
  51. return sw
  52. elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
  53. " mid-table
  54. " preserve indent
  55. return indent(prevnonblank(v:lnum-1))
  56. elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
  57. " first line of a table, relative indent
  58. return indent(prevnonblank(v:lnum-1)) + sw
  59. elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
  60. " line after a table, relative unindent
  61. return indent(prevnonblank(v:lnum-1)) - sw
  62. elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
  63. " comments on scenarios
  64. return sw
  65. endif
  66. return indent(prevnonblank(v:lnum-1))
  67. endfunction
  68. " vim:set sts=2 sw=2: