robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
1b5a394ffd
master
1" Vim indent file 2" Language: Apache Thrift 3" Maintainer: Yinzuo Jiang <jiangyinzuo@foxmail.com> 4" Last Change: 2024/07/29 5 6" Only load this indent file when no other was loaded. 7if exists ( "b:did_indent" ) 8finish 9endif 10let b: did_indent = 1 11 12setlocal cindent 13setlocal indentexpr = GetThriftIndent () 14 15let b: undo_indent = "set cindent< indentexpr<" 16 17" Only define the function once. 18if exists ( "*GetThriftIndent" ) 19finish 20endif 21 22let s: keepcpo = & cpo 23set cpo & vim 24 25function ! SkipThriftBlanksAndComments ( startline ) 26let lnum = a: startline 27while lnum > 1 28let lnum = prevnonblank ( lnum ) 29if getline ( lnum ) =~ '\*/\s*$' 30while getline ( lnum ) !~ '/\*' && lnum > 1 31let lnum = lnum - 1 32endwhile 33if getline ( lnum ) =~ '^\s*/\*' 34let lnum = lnum - 1 35else 36break 37endif 38elseif getline ( lnum ) =~ '^\s*\(//\|#\)' 39let lnum = lnum - 1 40else 41break 42endif 43endwhile 44return lnum 45endfunction 46 47function GetThriftIndent () 48" Thrift is just like C; use the built-in C indenting and then correct a few 49" specific cases. 50let theIndent = cindent ( v: lnum ) 51 52" If we're in the middle of a comment then just trust cindent 53if getline ( v: lnum ) =~ '^\s*\*' 54return theIndent 55endif 56 57let line = substitute ( getline ( v: lnum ), '\(//\|#\).*$' , '' , '' ) 58let previousNum = SkipThriftBlanksAndComments ( v: lnum - 1 ) 59let previous = substitute ( getline ( previousNum ), '\(//\|#\).*$' , '' , '' ) 60 61let l: indent = indent ( previousNum ) 62if previous =~ "{" && previous !~ "}" 63let l: indent += shiftwidth () 64endif 65if line =~ "}" && line !~ "{" 66let l: indent -= shiftwidth () 67endif 68return l: indent 69endfunction 70 71let & cpo = s: keepcpo 72unlet s: keepcpo 73 74" vim: sw=2 sts=2 et