codekingpro/portable-devtools
114k
1" Vim indent file2" Language: Apache Thrift3" Maintainer: Yinzuo Jiang <jiangyinzuo@foxmail.com>4" Last Change: 2024/07/295 6" Only load this indent file when no other was loaded.7if exists("b:did_indent")8 finish9endif10let b:did_indent = 111 12setlocal cindent13setlocal indentexpr=GetThriftIndent()14 15let b:undo_indent = "set cindent< indentexpr<"16 17" Only define the function once.18if exists("*GetThriftIndent")19 finish20endif21 22let s:keepcpo= &cpo23set cpo&vim24 25function! SkipThriftBlanksAndComments(startline)26 let lnum = a:startline27 while lnum > 128 let lnum = prevnonblank(lnum)29 if getline(lnum) =~ '\*/\s*$'30 while getline(lnum) !~ '/\*' && lnum > 131 let lnum = lnum - 132 endwhile33 if getline(lnum) =~ '^\s*/\*'34 let lnum = lnum - 135 else36 break37 endif38 elseif getline(lnum) =~ '^\s*\(//\|#\)'39 let lnum = lnum - 140 else41 break42 endif43 endwhile44 return lnum45endfunction46 47function GetThriftIndent()48 " Thrift is just like C; use the built-in C indenting and then correct a few49 " specific cases.50 let theIndent = cindent(v:lnum)51 52 " If we're in the middle of a comment then just trust cindent53 if getline(v:lnum) =~ '^\s*\*'54 return theIndent55 endif56 57 let line = substitute(getline(v:lnum), '\(//\|#\).*$', '', '')58 let previousNum = SkipThriftBlanksAndComments(v:lnum - 1)59 let previous = substitute(getline(previousNum), '\(//\|#\).*$', '', '')60 61 let l:indent = indent(previousNum)62 if previous =~ "{" && previous !~ "}"63 let l:indent += shiftwidth()64 endif65 if line =~ "}" && line !~ "{"66 let l:indent -= shiftwidth()67 endif68 return l:indent69endfunction70 71let &cpo = s:keepcpo72unlet s:keepcpo73 74" vim: sw=2 sts=2 et75 