brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 2c5b4ae Raw
76 lines · plain
1" Vim indent file2" Language:   mlir3" Maintainer: The MLIR team4" Adapted from the LLVM vim indent file5" What this indent plugin currently does:6"  - If no other rule matches copy indent from previous non-empty,7"    non-commented line.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 same11"    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 to15"    that.16if exists("b:did_indent")17  finish18endif19let b:did_indent = 120 21setlocal shiftwidth=2 expandtab22 23setlocal indentkeys=0{,0},<:>,!^F,o,O,e24setlocal indentexpr=GetMLIRIndent()25 26if exists("*GetMLIRIndent")27  finish28endif29 30function! FindOpenBrace(lnum)31  call cursor(a:lnum, 1)32  return searchpair('{', '', '}', 'bW')33endfun34 35function! 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)40    silent normal %41    let opening_lnum = line('.')42    if opening_lnum != v:lnum43      return indent(opening_lnum)44    endif45  endif46 47  " Indent labels the same as the current opening block48  if thisline =~ '\^\h\+.*:\s*$'49    let blockbegin = FindOpenBrace(v:lnum)50    if blockbegin > 051      return indent(blockbegin)52    endif53  endif54 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)59  endwhile60  " Hit the start of the file, use zero indent.61  if prev_lnum == 062    return 063  endif64 65  let ind = indent(prev_lnum)66  let prevline = getline(prev_lnum)67 68  " Add a 'shiftwidth' after lines that start a function, block/labels, or a69  " region.70  if prevline =~ '{\s*$' || prevline =~ '\^\h\+.*:\s*$'71    let ind = ind + &shiftwidth72  endif73 74  return ind75endfunction76