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,
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")
19 setlocal shiftwidth=2 expandtab
21 setlocal indentkeys=0{,0},<:>,!^F,o,O,e
22 setlocal indentexpr=GetLLVMIndent()
24 if exists("*GetLLVMIndent")
28 function! FindOpenBrace(lnum)
29 call cursor(a:lnum, 1)
30 return searchpair('{', '', '}', 'bW')
33 function! GetLLVMIndent()
34 " On '}' align the same as the line containing the matching '{'
35 let thisline = getline(v:lnum)
36 if thisline =~ '^\s*}'
37 call cursor(v:lnum, 1)
39 let opening_lnum = line('.')
40 if opening_lnum != v:lnum
41 return indent(opening_lnum)
45 " Indent labels the same as the current opening block
46 if thisline =~ ':\s*$'
47 let blockbegin = FindOpenBrace(v:lnum)
49 return indent(blockbegin)
53 " Find a non-blank not-completely commented line above the current line.
54 let prev_lnum = prevnonblank(v:lnum - 1)
55 while prev_lnum > 0 && synIDattr(synID(prev_lnum, indent(prev_lnum)+1, 0), "name") =? "string\|comment"
56 let prev_lnum = prevnonblank(prev_lnum-1)
58 " Hit the start of the file, use zero indent.
63 let ind = indent(prev_lnum)
64 let prevline = getline(prev_lnum)
66 " Add a 'shiftwidth' after lines that start a block or labels
67 if prevline =~ '{\s*$' || prevline =~ ':\s*$'
68 let ind = ind + &shiftwidth