diff options
| author | Adam Stankiewicz <sheerun@sher.pl> | 2019-03-11 09:20:12 +0100 | 
|---|---|---|
| committer | Adam Stankiewicz <sheerun@sher.pl> | 2019-03-11 09:20:36 +0100 | 
| commit | 420a65e9b0ab88095cd88c49167ab441a4dd1f3e (patch) | |
| tree | e06444dd62853d76c3efdeb05b8a44e2bf98dc37 /indent | |
| parent | 2254b83675e3356f42cc011133da67c26512022f (diff) | |
| download | vim-polyglot-420a65e9b0ab88095cd88c49167ab441a4dd1f3e.tar.gz vim-polyglot-420a65e9b0ab88095cd88c49167ab441a4dd1f3e.zip | |
Add llvm support, closes #376v3.7.0
Diffstat (limited to 'indent')
| -rw-r--r-- | indent/llvm.vim | 76 | 
1 files changed, 76 insertions, 0 deletions
| diff --git a/indent/llvm.vim b/indent/llvm.vim new file mode 100644 index 00000000..90829c25 --- /dev/null +++ b/indent/llvm.vim @@ -0,0 +1,76 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'llvm') != -1 +  finish +endif + +" Vim indent file +" Language:   llvm +" Maintainer: The LLVM team, http://llvm.org/ +" What this indent plugin currently does: +"  - If no other rule matches copy indent from previous non-empty, +"    non-commented line +"  - On '}' align the same as the line containing the matching '{' +"  - If previous line ends with ':' increase indentation +"  - If the current line ends with ':' indent at the same level as the +"    enclosing '{'/'}' block +" Stuff that would be nice to add: +"  - Continue comments on next line +"  - If there is an opening+unclosed parenthesis on previous line indent to that +if exists("b:did_indent") +  finish +endif +let b:did_indent = 1 + +setlocal shiftwidth=2 expandtab + +setlocal indentkeys=0{,0},<:>,!^F,o,O,e +setlocal indentexpr=GetLLVMIndent() + +if exists("*GetLLVMIndent") +  finish +endif + +function! FindOpenBrace(lnum) +  call cursor(a:lnum, 1) +  return searchpair('{', '', '}', 'bW') +endfun + +function! GetLLVMIndent() +  " On '}' align the same as the line containing the matching '{' +  let thisline = getline(v:lnum) +  if thisline =~ '^\s*}' +    call cursor(v:lnum, 1) +    silent normal % +    let opening_lnum = line('.') +    if opening_lnum != v:lnum +      return indent(opening_lnum) +    endif +  endif + +  " Indent labels the same as the current opening block +  if thisline =~ ':\s*$' +    let blockbegin = FindOpenBrace(v:lnum) +    if blockbegin > 0 +      return indent(blockbegin) +    endif +  endif + +  " Find a non-blank not-completely commented line above the current line. +  let prev_lnum = prevnonblank(v:lnum - 1) +  while prev_lnum > 0 && synIDattr(synID(prev_lnum, indent(prev_lnum)+1, 0), "name") =? "string\|comment" +    let prev_lnum = prevnonblank(prev_lnum-1) +  endwhile +  " Hit the start of the file, use zero indent. +  if prev_lnum == 0 +    return 0 +  endif + +  let ind = indent(prev_lnum) +  let prevline = getline(prev_lnum) + +  " Add a 'shiftwidth' after lines that start a block or labels +  if prevline =~ '{\s*$' || prevline =~ ':\s*$' +    let ind = ind + &shiftwidth +  endif + +  return ind +endfunction | 
