Skip to content

Commit 222e6da

Browse files
New file google_python_style.vim.
1 parent 7f003d3 commit 222e6da

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

google_python_style.vim

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
" Indent Python in the Google way.
2+
3+
setlocal indentexpr=GetGooglePythonIndent(v:lnum)
4+
5+
let s:maxoff = 50 " maximum number of lines to look backwards.
6+
7+
function 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+
33+
endfunction
34+
35+
let pyindent_nested_paren="&sw*2"
36+
let pyindent_open_paren="&sw*2"

pyguide.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<H1>Google Python Style Guide</H1>
101101
<p align="right">
102102

103-
Revision 2.18
103+
Revision 2.19
104104
</p>
105105

106106
<address>
@@ -168,6 +168,10 @@ <H2 name="Background" id="Background">Background</H2>
168168
programs.
169169
</p>
170170

171+
<p>
172+
To help you format code correctly, we've created a <a href="google_python_style.vim">settings
173+
file for Vim</a>. For Emacs, the default settings should be fine.
174+
</p>
171175

172176

173177
</DIV>
@@ -2025,7 +2029,7 @@ <H2>Parting Words</H2>
20252029

20262030

20272031
<p align="right">
2028-
Revision 2.18
2032+
Revision 2.19
20292033
</p>
20302034

20312035

0 commit comments

Comments
 (0)