brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · d1d8c83 Raw
73 lines · plain
1" Vim indent file2" Language:   llvm3" 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 line7"  - On '}' align the same as the line containing the matching '{'8"  - If previous line ends with ':' increase indentation9"  - If the current line ends with ':' indent at the same level as the10"    enclosing '{'/'}' block11" Stuff that would be nice to add:12"  - Continue comments on next line13"  - If there is an opening+unclosed parenthesis on previous line indent to that14if exists("b:did_indent")15  finish16endif17let b:did_indent = 118 19setlocal shiftwidth=2 expandtab20 21setlocal indentkeys=0{,0},<:>,!^F,o,O,e22setlocal indentexpr=GetLLVMIndent()23 24if exists("*GetLLVMIndent")25  finish26endif27 28function! FindOpenBrace(lnum)29  call cursor(a:lnum, 1)30  return searchpair('{', '', '}', 'bW')31endfun32 33function! 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)38    silent normal %39    let opening_lnum = line('.')40    if opening_lnum != v:lnum41      return indent(opening_lnum)42    endif43  endif44 45  " Indent labels the same as the current opening block46  if thisline =~ ':\s*$'47    let blockbegin = FindOpenBrace(v:lnum)48    if blockbegin > 049      return indent(blockbegin)50    endif51  endif52 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)57  endwhile58  " Hit the start of the file, use zero indent.59  if prev_lnum == 060    return 061  endif62 63  let ind = indent(prev_lnum)64  let prevline = getline(prev_lnum)65 66  " Add a 'shiftwidth' after lines that start a block or labels67  if prevline =~ '{\s*$' || prevline =~ ':\s*$'68    let ind = ind + &shiftwidth69  endif70 71  return ind72endfunction73