From 222e6da82a3be5149f79ee66037563d04cf66dd2 Mon Sep 17 00:00:00 2001 From: "mshields@google.com" Date: Mon, 29 Nov 2010 20:32:06 +0000 Subject: [PATCH] New file google_python_style.vim. --- google_python_style.vim | 36 ++++++++++++++++++++++++++++++++++++ pyguide.html | 8 ++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 google_python_style.vim diff --git a/google_python_style.vim b/google_python_style.vim new file mode 100644 index 000000000..a8feea9b1 --- /dev/null +++ b/google_python_style.vim @@ -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" diff --git a/pyguide.html b/pyguide.html index b2db3f7d2..50a9d0151 100644 --- a/pyguide.html +++ b/pyguide.html @@ -100,7 +100,7 @@

Google Python Style Guide

- Revision 2.18 + Revision 2.19

@@ -168,6 +168,10 @@

Background

programs.

+

+ To help you format code correctly, we've created a settings + file for Vim. For Emacs, the default settings should be fine. +

@@ -2025,7 +2029,7 @@

Parting Words

-Revision 2.18 +Revision 2.19