Skip to content

Commit

Permalink
New file google_python_style.vim.
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Nov 29, 2010
1 parent 7f003d3 commit 222e6da
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
36 changes: 36 additions & 0 deletions google_python_style.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
" Indent Python in the Google way.

setlocal indentexpr=GetGooglePythonIndent(v:lnum)

let s:maxoff = 50 " maximum number of lines to look backwards.

function GetGooglePythonIndent(lnum)

" Indent inside parens.
" Align with the open paren unless it is at the end of the line.
" E.g.
" open_paren_not_at_EOL(100,
" (200,
" 300),
" 400)
" open_paren_at_EOL(
" 100, 200, 300, 400)
call cursor(a:lnum, 1)
let [par_line, par_col] = searchpairpos('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
\ . " =~ '\\(Comment\\|String\\)$'")
if par_line > 0
call cursor(par_line, 1)
if par_col != col("$") - 1
return par_col
endif
endif

" Delegate the rest to the original function.
return GetPythonIndent(a:lnum)

endfunction

let pyindent_nested_paren="&sw*2"
let pyindent_open_paren="&sw*2"
8 changes: 6 additions & 2 deletions pyguide.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<H1>Google Python Style Guide</H1>
<p align="right">

Revision 2.18
Revision 2.19
</p>

<address>
Expand Down Expand Up @@ -168,6 +168,10 @@ <H2 name="Background" id="Background">Background</H2>
programs.
</p>

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


</DIV>
Expand Down Expand Up @@ -2025,7 +2029,7 @@ <H2>Parting Words</H2>


<p align="right">
Revision 2.18
Revision 2.19
</p>


Expand Down

0 comments on commit 222e6da

Please sign in to comment.