llvm.vim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. " Vim indent file
  2. " Language: llvm
  3. " Maintainer: The LLVM team, http://llvm.org/
  4. " What this indent plugin currently does:
  5. " - If no other rule matches copy indent from previous non-empty,
  6. " non-commented line
  7. " - On '}' align the same as the line containing the matching '{'
  8. " - If previous line ends with ':' increase indentation
  9. " - If the current line ends with ':' indent at the same level as the
  10. " enclosing '{'/'}' block
  11. " Stuff that would be nice to add:
  12. " - Continue comments on next line
  13. " - If there is an opening+unclosed parenthesis on previous line indent to that
  14. if exists("b:did_indent")
  15. finish
  16. endif
  17. let b:did_indent = 1
  18. setlocal shiftwidth=2 expandtab
  19. setlocal indentkeys=0{,0},<:>,!^F,o,O,e
  20. setlocal indentexpr=GetLLVMIndent()
  21. if exists("*GetLLVMIndent")
  22. finish
  23. endif
  24. function! FindOpenBrace(lnum)
  25. call cursor(a:lnum, 1)
  26. return searchpair('{', '', '}', 'bW')
  27. endfun
  28. function! GetLLVMIndent()
  29. " On '}' align the same as the line containing the matching '{'
  30. let thisline = getline(v:lnum)
  31. if thisline =~ '^\s*}'
  32. call cursor(v:lnum, 1)
  33. silent normal %
  34. let opening_lnum = line('.')
  35. if opening_lnum != v:lnum
  36. return indent(opening_lnum)
  37. endif
  38. endif
  39. " Indent labels the same as the current opening block
  40. if thisline =~ ':\s*$'
  41. let blockbegin = FindOpenBrace(v:lnum)
  42. if blockbegin > 0
  43. return indent(blockbegin)
  44. endif
  45. endif
  46. " Find a non-blank not-completely commented line above the current line.
  47. let prev_lnum = prevnonblank(v:lnum - 1)
  48. while prev_lnum > 0 && synIDattr(synID(prev_lnum, indent(prev_lnum)+1, 0), "name") =? "string\|comment"
  49. let prev_lnum = prevnonblank(prev_lnum-1)
  50. endwhile
  51. " Hit the start of the file, use zero indent.
  52. if prev_lnum == 0
  53. return 0
  54. endif
  55. let ind = indent(prev_lnum)
  56. let prevline = getline(prev_lnum)
  57. " Add a 'shiftwidth' after lines that start a block or labels
  58. if prevline =~ '{\s*$' || prevline =~ ':\s*$'
  59. let ind = ind + &shiftwidth
  60. endif
  61. return ind
  62. endfunction