codekingpro/portable-devtools
114k
1" Vim indent file2" Language: Bazel (http://bazel.io)3" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl)4" Last Change: 2021 Jul 085 6if exists('b:did_indent')7 finish8endif9 10" Load base python indent.11if !exists('*GetPythonIndent')12 runtime! indent/python.vim13endif14 15let b:did_indent = 116 17" Only enable bzl google indent if python google indent is enabled.18if !get(g:, 'no_google_python_indent')19 setlocal indentexpr=GetBzlIndent(v:lnum)20endif21 22if exists('*GetBzlIndent')23 finish24endif25 26let s:save_cpo = &cpo27set cpo-=C28 29" Maximum number of lines to look backwards.30let s:maxoff = 5031 32""33" Determine the correct indent level given an {lnum} in the current buffer.34function GetBzlIndent(lnum) abort35 let l:use_recursive_indent = !get(g:, 'no_google_python_recursive_indent')36 if l:use_recursive_indent37 " Backup and override indent setting variables.38 if exists('g:pyindent_nested_paren')39 let l:pyindent_nested_paren = g:pyindent_nested_paren40 endif41 if exists('g:pyindent_open_paren')42 let l:pyindent_open_paren = g:pyindent_open_paren43 endif44 let g:pyindent_nested_paren = 'shiftwidth()'45 let g:pyindent_open_paren = 'shiftwidth()'46 endif47 48 let l:indent = -149 50 call cursor(a:lnum, 1)51 let [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\\)$'")55 if l:par_line > 056 " Indent inside parens.57 if searchpair('(\|{\|\[', '', ')\|}\|\]', 'W',58 \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" .59 \ " synIDattr(synID(line('.'), col('.'), 1), 'name')" .60 \ " =~ '\\(Comment\\|String\\)$'") && line('.') == a:lnum61 " If cursor is at close parens, match indent with open parens.62 " E.g.63 " foo(64 " )65 let l:indent = indent(l:par_line)66 else67 " 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)75 call cursor(l:par_line, 1)76 if l:par_col != col('$') - 177 let l:indent = l:par_col78 endif79 endif80 endif81 82 " Delegate the rest to the original function.83 if l:indent == -184 let l:indent = GetPythonIndent(a:lnum)85 endif86 87 if l:use_recursive_indent88 " Restore global variables.89 if exists('l:pyindent_nested_paren')90 let g:pyindent_nested_paren = l:pyindent_nested_paren91 else92 unlet g:pyindent_nested_paren93 endif94 if exists('l:pyindent_open_paren')95 let g:pyindent_open_paren = l:pyindent_open_paren96 else97 unlet g:pyindent_open_paren98 endif99 endif100 101 return l:indent102endfunction103 104let &cpo = s:save_cpo105unlet s:save_cpo106 