3 " Maintainer: The MLIR team
4 " Adapted from the LLVM vim indent file
5 " What this indent plugin currently does:
6 " - If no other rule matches copy indent from previous non-empty,
8 " - On '}' align the same as the line containing the matching '{'.
9 " - If previous line starts with a block label, increase indentation.
10 " - If the current line is a block label and ends with ':' indent at the same
11 " level as the enclosing '{'/'}' block.
12 " Stuff that would be nice to add:
13 " - Continue comments on next line.
14 " - If there is an opening+unclosed parenthesis on previous line indent to
16 if exists("b:did_indent")
21 setlocal shiftwidth=2 expandtab
23 setlocal indentkeys=0{,0},<:>,!^F,o,O,e
24 setlocal indentexpr=GetMLIRIndent()
26 if exists("*GetMLIRIndent")
30 function! FindOpenBrace(lnum)
31 call cursor(a:lnum, 1)
32 return searchpair('{', '', '}', 'bW')
35 function! GetMLIRIndent()
36 " On '}' align the same as the line containing the matching '{'
37 let thisline = getline(v:lnum)
38 if thisline =~ '^\s*}'
39 call cursor(v:lnum, 1)
41 let opening_lnum = line('.')
42 if opening_lnum != v:lnum
43 return indent(opening_lnum)
47 " Indent labels the same as the current opening block
48 if thisline =~ '\^\h\+.*:\s*$'
49 let blockbegin = FindOpenBrace(v:lnum)
51 return indent(blockbegin)
55 " Find a non-blank not-completely commented line above the current line.
56 let prev_lnum = prevnonblank(v:lnum - 1)
57 while prev_lnum > 0 && synIDattr(synID(prev_lnum, 1 + indent(prev_lnum), 0), "name") == "mlirComment"
58 let prev_lnum = prevnonblank(prev_lnum-1)
60 " Hit the start of the file, use zero indent.
65 let ind = indent(prev_lnum)
66 let prevline = getline(prev_lnum)
68 " Add a 'shiftwidth' after lines that start a function, block/labels, or a
70 if prevline =~ '{\s*$' || prevline =~ '\^\h\+.*:\s*$'
71 let ind = ind + &shiftwidth