1*8c35d5eeSXin Li" Indent Python in the Google way. 2*8c35d5eeSXin Li 3*8c35d5eeSXin Lisetlocal indentexpr=GetGooglePythonIndent(v:lnum) 4*8c35d5eeSXin Li 5*8c35d5eeSXin Lilet s:maxoff = 50 " maximum number of lines to look backwards. 6*8c35d5eeSXin Li 7*8c35d5eeSXin Lifunction GetGooglePythonIndent(lnum) 8*8c35d5eeSXin Li 9*8c35d5eeSXin Li " Indent inside parens. 10*8c35d5eeSXin Li " Align with the open paren unless it is at the end of the line. 11*8c35d5eeSXin Li " E.g. 12*8c35d5eeSXin Li " open_paren_not_at_EOL(100, 13*8c35d5eeSXin Li " (200, 14*8c35d5eeSXin Li " 300), 15*8c35d5eeSXin Li " 400) 16*8c35d5eeSXin Li " open_paren_at_EOL( 17*8c35d5eeSXin Li " 100, 200, 300, 400) 18*8c35d5eeSXin Li call cursor(a:lnum, 1) 19*8c35d5eeSXin Li let [par_line, par_col] = searchpairpos('(\|{\|\[', '', ')\|}\|\]', 'bW', 20*8c35d5eeSXin Li \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" 21*8c35d5eeSXin Li \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" 22*8c35d5eeSXin Li \ . " =~ '\\(Comment\\|String\\)$'") 23*8c35d5eeSXin Li if par_line > 0 24*8c35d5eeSXin Li call cursor(par_line, 1) 25*8c35d5eeSXin Li if par_col != col("$") - 1 26*8c35d5eeSXin Li return par_col 27*8c35d5eeSXin Li endif 28*8c35d5eeSXin Li endif 29*8c35d5eeSXin Li 30*8c35d5eeSXin Li " Delegate the rest to the original function. 31*8c35d5eeSXin Li return GetPythonIndent(a:lnum) 32*8c35d5eeSXin Li 33*8c35d5eeSXin Liendfunction 34*8c35d5eeSXin Li 35*8c35d5eeSXin Lilet pyindent_nested_paren="&sw*2" 36*8c35d5eeSXin Lilet pyindent_open_paren="&sw*2" 37