From: Hynek Schlawack Date: Tue, 24 Sep 2013 08:10:43 +0000 (+0200) Subject: Merge branch 'clayg-fix-10' X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/2debacc93325556ac2408cd916d6729fa9f22568?hp=be10eff728257029fc95ebb889a710044118c1c6 Merge branch 'clayg-fix-10' Fixes #10 --- diff --git a/AUTHORS.rst b/AUTHORS.rst index 7333ee4..e12a0c9 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -6,6 +6,7 @@ Credits It is currently maintained by Hynek Schlawack with the generous help of the following contributors: - 0player +- Clay Gerrard - Johann Klähn - Joseph Irwin - Steve Losh diff --git a/indent/python.vim b/indent/python.vim index 9c3aa0c..2c30547 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -160,15 +160,17 @@ function! GetPythonPEPIndent(lnum) return -1 endif - " If this line is explicitly joined, try to find an indentation that looks - " good. + " If this line is explicitly joined, find the first indentation that is a + " multiple of four and will distinguish itself from next logical line. if pline =~ '\\$' - let compound_statement = '^\s*\(if\|while\|for\s.*\sin\|except\)\s*' - let maybe_indent = matchend(getline(sslnum), compound_statement) - if maybe_indent != -1 - return maybe_indent + let maybe_indent = indent(sslnum) + &sw + let control_structure = '^\s*\(if\|while\|for\s.*\sin\|except\)\s*' + if match(getline(sslnum), control_structure) != -1 + " add extra indent to avoid E125 + return maybe_indent + &sw else - return indent(sslnum) + &sw * 2 + " control structure not found + return maybe_indent endif endif diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index c3488f3..40269fc 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -67,6 +67,30 @@ describe "vim" do end end + describe "when using simple control structures" do + it "indents shiftwidth spaces" do + vim.feedkeys 'iwhile True:\pass' + indent.should == shiftwidth + end + end + + describe "when a line breaks with a manual '\\'" do + it "indents shiftwidth spaces on normal line" do + vim.feedkeys 'ivalue = test + \\\\\' + indent.should == shiftwidth + end + + it "indents 2x shiftwidth spaces for control structures" do + vim.feedkeys 'iif somevalue == xyz and \\\\\' + indent.should == shiftwidth * 2 + end + + it "indents relative to line above" do + vim.feedkeys 'i\tvalue = test + \\\\\' + indent.should == shiftwidth * 2 + end + end + def shiftwidth @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i end