robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e31652879e
master
1" Vim indent file 2" Language: Bazel (http://bazel.io) 3" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl) 4" Last Change: 2021 Jul 08 5 6if exists ( 'b:did_indent' ) 7finish 8endif 9 10" Load base python indent. 11if ! exists ( '*GetPythonIndent' ) 12runtime ! indent/python.vim 13endif 14 15let b: did_indent = 1 16 17" Only enable bzl google indent if python google indent is enabled. 18if ! get ( g:, 'no_google_python_indent' ) 19setlocal indentexpr = GetBzlIndent (v:lnum) 20endif 21 22if exists ( '*GetBzlIndent' ) 23finish 24endif 25 26let s: save_cpo = & cpo 27set cpo -= C 28 29" Maximum number of lines to look backwards. 30let s: maxoff = 50 31 32"" 33" Determine the correct indent level given an {lnum} in the current buffer. 34function GetBzlIndent ( lnum ) abort 35let l: use_recursive_indent = ! get ( g:, 'no_google_python_recursive_indent' ) 36if l: use_recursive_indent 37" Backup and override indent setting variables. 38if exists ( 'g:pyindent_nested_paren' ) 39let l: pyindent_nested_paren = g: pyindent_nested_paren 40endif 41if exists ( 'g:pyindent_open_paren' ) 42let l: pyindent_open_paren = g: pyindent_open_paren 43endif 44let g: pyindent_nested_paren = 'shiftwidth()' 45let g: pyindent_open_paren = 'shiftwidth()' 46endif 47 48let l: indent = -1 49 50call cursor ( a: lnum , 1 ) 51let [ l: par_line , l: par_col ] = searchpairpos ( '(\|{\|\[' , '' , ')\|}\|\]' , 'bW' , 52 \"line('.') < " . ( a: lnum - s: maxoff ) . " ? dummy :" . 53 \" synIDattr(synID(line('.'), col('.'), 1), 'name')" . 54 \" =~ '\\(Comment\\|String\\)$'" ) 55if l: par_line > 0 56" Indent inside parens. 57if searchpair ( '(\|{\|\[' , '' , ')\|}\|\]' , 'W' , 58 \"line('.') < " . ( a: lnum - s: maxoff ) . " ? dummy :" . 59 \" synIDattr(synID(line('.'), col('.'), 1), 'name')" . 60 \" =~ '\\(Comment\\|String\\)$'" ) && line ( '.' ) == a: lnum 61" If cursor is at close parens, match indent with open parens. 62" E.g. 63" foo( 64" ) 65let l: indent = indent ( l: par_line ) 66else 67" Align with the open paren unless it is at the end of the line. 68" E.g. 69" open_paren_not_at_EOL(100, 70" (200, 71" 300), 72" 400) 73" open_paren_at_EOL( 74" 100, 200, 300, 400) 75call cursor ( l: par_line , 1 ) 76if l: par_col != col ( '$' ) - 1 77let l: indent = l: par_col 78endif 79endif 80endif 81 82" Delegate the rest to the original function. 83if l: indent == -1 84let l: indent = GetPythonIndent ( a: lnum ) 85endif 86 87if l: use_recursive_indent 88" Restore global variables. 89if exists ( 'l:pyindent_nested_paren' ) 90let g: pyindent_nested_paren = l: pyindent_nested_paren 91else 92unlet g: pyindent_nested_paren 93endif 94if exists ( 'l:pyindent_open_paren' ) 95let g: pyindent_open_paren = l: pyindent_open_paren 96else 97unlet g: pyindent_open_paren 98endif 99endif 100 101return l: indent 102endfunction 103 104let & cpo = s: save_cpo 105unlet s: save_cpo