config.vim 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. " Vim indent file
  2. " Language: Autoconf configure.{ac,in} file
  3. " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
  4. " Latest Revision: 2006-12-20
  5. " TODO: how about nested [()]'s in one line
  6. " what's wrong with '\\\@!'?
  7. " Only load this indent file when no other was loaded.
  8. if exists("b:did_indent")
  9. finish
  10. endif
  11. runtime! indent/sh.vim " will set b:did_indent
  12. setlocal indentexpr=GetConfigIndent()
  13. setlocal indentkeys=!^F,o,O,=then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
  14. setlocal nosmartindent
  15. " Only define the function once.
  16. if exists("*GetConfigIndent")
  17. finish
  18. endif
  19. " get the offset (indent) of the end of the match of 'regexp' in 'line'
  20. function s:GetOffsetOf(line, regexp)
  21. let end = matchend(a:line, a:regexp)
  22. let width = 0
  23. let i = 0
  24. while i < end
  25. if a:line[i] != "\t"
  26. let width = width + 1
  27. else
  28. let width = width + &ts - (width % &ts)
  29. endif
  30. let i = i + 1
  31. endwhile
  32. return width
  33. endfunction
  34. function GetConfigIndent()
  35. " Find a non-blank line above the current line.
  36. let lnum = prevnonblank(v:lnum - 1)
  37. " Hit the start of the file, use zero indent.
  38. if lnum == 0
  39. return 0
  40. endif
  41. " where to put this
  42. let ind = GetShIndent()
  43. let line = getline(lnum)
  44. " if previous line has unmatched, unescaped opening parentheses,
  45. " indent to its position. TODO: not failsafe if multiple ('s
  46. if line =~ '\\\@<!([^)]*$'
  47. let ind = s:GetOffsetOf(line, '\\\@!(')
  48. endif
  49. " if previous line has unmatched opening bracket,
  50. " indent to its position. TODO: same as above
  51. if line =~ '\[[^]]*$'
  52. let ind = s:GetOffsetOf(line, '\[')
  53. endif
  54. " if previous line had an unmatched closing parantheses,
  55. " indent to the matching opening parantheses
  56. if line =~ '[^(]\+\\\@<!)$'
  57. call search(')', 'bW')
  58. let lnum = searchpair('\\\@<!(', '', ')', 'bWn')
  59. let ind = indent(lnum)
  60. endif
  61. " if previous line had an unmatched closing bracket,
  62. " indent to the matching opening bracket
  63. if line =~ '[^[]\+]$'
  64. call search(']', 'bW')
  65. let lnum = searchpair('\[', '', ']', 'bWn')
  66. let ind = indent(lnum)
  67. endif
  68. return ind
  69. endfunction