sdl.vim 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. " Vim indent file
  2. " Language: SDL
  3. " Maintainer: Michael Piefel <entwurf@piefel.de>
  4. " Last Change: 2021 Oct 03
  5. " Shamelessly stolen from the Vim-Script indent file
  6. " Only load this indent file when no other was loaded.
  7. if exists("b:did_indent")
  8. finish
  9. endif
  10. let b:did_indent = 1
  11. setlocal indentexpr=GetSDLIndent()
  12. setlocal indentkeys+==~end,=~state,*<Return>
  13. let b:undo_indent = "setl inde< indk<"
  14. " Only define the function once.
  15. if exists("*GetSDLIndent")
  16. " finish
  17. endif
  18. let s:cpo_save = &cpo
  19. set cpo&vim
  20. function! GetSDLIndent()
  21. " Find a non-blank line above the current line.
  22. let lnum = prevnonblank(v:lnum - 1)
  23. " At the start of the file use zero indent.
  24. if lnum == 0
  25. return 0
  26. endif
  27. let ind = indent(lnum)
  28. let virtuality = '^\s*\(\(virtual\|redefined\|finalized\)\s\+\)\=\s*'
  29. " Add a single space to comments which use asterisks
  30. if getline(lnum) =~ '^\s*\*'
  31. let ind = ind - 1
  32. endif
  33. if getline(v:lnum) =~ '^\s*\*'
  34. let ind = ind + 1
  35. endif
  36. " Add a 'shiftwidth' after states, different blocks, decision (and alternatives), inputs
  37. if (getline(lnum) =~? '^\s*\(start\|state\|system\|package\|connection\|channel\|alternative\|macro\|operator\|newtype\|select\|substructure\|decision\|generator\|refinement\|service\|method\|exceptionhandler\|asntype\|syntype\|value\|(.*):\|\(priority\s\+\)\=input\|provided\)'
  38. \ || getline(lnum) =~? virtuality . '\(process\|procedure\|block\|object\)')
  39. \ && getline(lnum) !~? 'end[[:alpha:]]\+;$'
  40. let ind = ind + shiftwidth()
  41. endif
  42. " Subtract a 'shiftwidth' after states
  43. if getline(lnum) =~? '^\s*\(stop\|return\>\|nextstate\)'
  44. let ind = ind - shiftwidth()
  45. endif
  46. " Subtract a 'shiftwidth' on on end (uncompleted line)
  47. if getline(v:lnum) =~? '^\s*end\>'
  48. let ind = ind - shiftwidth()
  49. endif
  50. " Put each alternatives where the corresponding decision was
  51. if getline(v:lnum) =~? '^\s*\((.*)\|else\):'
  52. normal k
  53. let ind = indent(searchpair('^\s*decision', '', '^\s*enddecision', 'bW',
  54. \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"'))
  55. endif
  56. " Put each state where the preceding state was
  57. if getline(v:lnum) =~? '^\s*state\>'
  58. let ind = indent(search('^\s*start', 'bW'))
  59. endif
  60. " Systems and packages are always in column 0
  61. if getline(v:lnum) =~? '^\s*\(\(end\)\=system\|\(end\)\=package\)'
  62. return 0
  63. endif
  64. " Put each end* where the corresponding begin was
  65. if getline(v:lnum) =~? '^\s*end[[:alpha:]]'
  66. normal k
  67. let partner=matchstr(getline(v:lnum), '\(' . virtuality . 'end\)\@<=[[:alpha:]]\+')
  68. let ind = indent(searchpair(virtuality . partner, '', '^\s*end' . partner, 'bW',
  69. \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"'))
  70. endif
  71. return ind
  72. endfunction
  73. let &cpo = s:cpo_save
  74. unlet s:cpo_save
  75. " vim:sw=2