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