ishd.vim 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. " Description: InstallShield indenter
  2. " Author: Johannes Zellner <johannes@zellner.org>
  3. " Last Change: Tue, 27 Apr 2004 14:54:59 CEST
  4. " Only load this indent file when no other was loaded.
  5. if exists("b:did_indent")
  6. finish
  7. endif
  8. let b:did_indent = 1
  9. setlocal autoindent
  10. setlocal indentexpr=GetIshdIndent(v:lnum)
  11. setlocal indentkeys&
  12. setlocal indentkeys+==else,=elseif,=endif,=end,=begin,<:>
  13. " setlocal indentkeys-=0#
  14. let b:undo_indent = "setl ai< indentexpr< indentkeys<"
  15. " Only define the function once.
  16. if exists("*GetIshdIndent")
  17. finish
  18. endif
  19. fun! GetIshdIndent(lnum)
  20. " labels and preprocessor get zero indent immediately
  21. let this_line = getline(a:lnum)
  22. let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
  23. let LABELS_OR_PREPROC_EXCEPT = '^\s*\<default\+\>:'
  24. if this_line =~ LABELS_OR_PREPROC && this_line !~ LABELS_OR_PREPROC_EXCEPT
  25. return 0
  26. endif
  27. " Find a non-blank line above the current line.
  28. " Skip over labels and preprocessor directives.
  29. let lnum = a:lnum
  30. while lnum > 0
  31. let lnum = prevnonblank(lnum - 1)
  32. let previous_line = getline(lnum)
  33. if previous_line !~ LABELS_OR_PREPROC || previous_line =~ LABELS_OR_PREPROC_EXCEPT
  34. break
  35. endif
  36. endwhile
  37. " Hit the start of the file, use zero indent.
  38. if lnum == 0
  39. return 0
  40. endif
  41. let ind = indent(lnum)
  42. " Add
  43. if previous_line =~ '^\s*\<\(function\|begin\|switch\|case\|default\|if.\{-}then\|else\|elseif\|while\|repeat\)\>'
  44. let ind = ind + shiftwidth()
  45. endif
  46. " Subtract
  47. if this_line =~ '^\s*\<endswitch\>'
  48. let ind = ind - 2 * shiftwidth()
  49. elseif this_line =~ '^\s*\<\(begin\|end\|endif\|endwhile\|else\|elseif\|until\)\>'
  50. let ind = ind - shiftwidth()
  51. elseif this_line =~ '^\s*\<\(case\|default\)\>'
  52. if previous_line !~ '^\s*\<switch\>'
  53. let ind = ind - shiftwidth()
  54. endif
  55. endif
  56. return ind
  57. endfun