robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
4cbeedf57b
master
1" Support for bitbake indenting, see runtime/indent/bitbake.vim 2 3function s: is_bb_python_func_def ( lnum ) 4let stack = synstack ( a: lnum , 1 ) 5if len ( stack ) == 0 6return 0 7endif 8 9return synIDattr ( stack [ 0 ], "name" ) == "bbPyFuncDef" 10endfunction 11 12function bitbake#Indent ( lnum ) 13if ! has ( 'syntax_items' ) 14return -1 15endif 16 17let stack = synstack ( a: lnum , 1 ) 18if len ( stack ) == 0 19return -1 20endif 21 22let name = synIDattr ( stack [ 0 ], "name" ) 23 24" TODO: support different styles of indentation for assignments. For now, 25" we only support like this: 26" VAR = " \ 27" value1 \ 28" value2 \ 29" " 30" 31" i.e. each value indented by shiftwidth(), with the final quote " completely unindented. 32if name == "bbVarValue" 33" Quote handling is tricky. kernel.bbclass has this line for instance: 34" EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" " HOSTCPP="${BUILD_CPP}"" 35" Instead of trying to handle crazy cases like that, just assume that a 36" double-quote on a line by itself (following an assignment) means the 37" user is closing the assignment, and de-dent. 38if getline ( a: lnum ) =~ '^\s*"$' 39return 0 40endif 41 42let prevstack = synstack ( a: lnum - 1 , 1 ) 43if len ( prevstack ) == 0 44return -1 45endif 46 47let prevname = synIDattr ( prevstack [ 0 ], "name" ) 48 49" Only indent if there was actually a continuation character on 50" the previous line, to avoid misleading indentation. 51let prevlinelastchar = synIDattr ( synID ( a: lnum - 1 , col ([ a: lnum - 1 , "$" ]) - 1 , 1 ), "name" ) 52let prev_continued = prevlinelastchar == "bbContinue" 53 54" Did the previous line introduce an assignment? 55if index ([ "bbVarDef" , "bbVarFlagDef" ], prevname ) != -1 56if prev_continued 57return shiftwidth () 58endif 59endif 60 61if ! prev_continued 62return 0 63endif 64 65" Autoindent can take it from here 66return -1 67endif 68 69if index ([ "bbPyDefRegion" , "bbPyFuncRegion" ], name ) != -1 70let ret = python#GetIndent ( a: lnum , function ( 's:is_bb_python_func_def' )) 71" Should normally always be indented by at least one shiftwidth; but allow 72" return of -1 (defer to autoindent) or -2 (force indent to 0) 73if ret == 0 74return shiftwidth () 75elseif ret == -2 76return 0 77endif 78return ret 79endif 80 81" TODO: GetShIndent doesn't detect tasks prepended with 'fakeroot' 82" Need to submit a patch upstream to Vim to provide an extension point. 83" Unlike the Python indenter, the Sh indenter is way too large to copy and 84" modify here. 85if name == "bbShFuncRegion" 86return GetShIndent () 87endif 88 89" TODO: 90" + heuristics for de-denting out of a bbPyDefRegion? e.g. when the user 91" types an obvious BB keyword like addhandler or addtask, or starts 92" writing a shell task. Maybe too hard to implement... 93 94return -1 95endfunction