From 8e816d76b461c41c12c3d90811656de5fd1cc61f Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Wed, 21 Jun 2017 11:42:28 -0700 Subject: [PATCH 1/2] add g:python_pep8_indent_continuation_indent_width --- README.rst | 9 +++++++++ indent/python.vim | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 3a8bf3c..844425e 100644 --- a/README.rst +++ b/README.rst @@ -74,6 +74,15 @@ With content already, it will be aligned to the opening parenthesis:: Existing indentation (including ``0``) in multiline strings will be kept, so this setting only applies to the indentation of new/empty lines. +python_pep8_indent_continuation_indent_width +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This option specifies the indent width used for line continuations from a parenthesis/bracket/brace. + +.. code-block:: vim + let g:python_pep8_indent_continuation_indent_width = 4 " default + let g:python_pep8_indent_continuation_indent_width = "&sw * 2" + let g:python_pep8_indent_continuation_indent_width = 8 Notes ----- diff --git a/indent/python.vim b/indent/python.vim index 8a479f4..dcf0a17 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -38,6 +38,10 @@ if !exists('g:python_pep8_indent_multiline_string') let g:python_pep8_indent_multiline_string = 0 endif +if !exists('g:python_pep8_indent_continuation_indent_width') + let g:python_pep8_indent_continuation_indent_width = 4 +endif + let s:maxoff = 50 let s:block_rules = { \ '^\s*elif\>': ['if', 'elif'], @@ -212,7 +216,7 @@ function! s:indent_like_opening_paren(lnum) if starts_with_closing_paren let res = base else - let res = base + s:sw() + let res = base + eval(g:python_pep8_indent_continuation_indent_width) endif else " Indent to match position of opening paren. From 33b868934f585a009c25d292a38b7c24043a6730 Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Wed, 21 Jun 2017 11:58:40 -0700 Subject: [PATCH 2/2] fix test cases --- spec/indent/indent_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 342b301..0a08228 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -43,11 +43,11 @@ before { vim.feedkeys 'itest(\' } it "indents by one level" do - proposed_indent.should == shiftwidth + proposed_indent.should satisfy { |v| v == shiftwidth * 2 or v == 4 } vim.feedkeys 'something' - indent.should == shiftwidth + indent.should == 4 vim.normal '==' - indent.should == shiftwidth + indent.should == 4 end it "puts the closing parenthesis at the same level" do @@ -80,9 +80,9 @@ before { vim.feedkeys 'imydict = { # comment\' } it "indent by one level" do - indent.should == shiftwidth + indent.should == 4 vim.feedkeys '1: 1,\' - indent.should == shiftwidth + indent.should == 4 end it "lines up the closing parenthesis" do @@ -102,7 +102,7 @@ describe "when after multiple parens of different types" do it "indents by one level" do vim.feedkeys 'if({\' - indent.should == shiftwidth + indent.should == 4 end it "lines up with the last paren" do @@ -171,14 +171,14 @@ describe "when using a function definition" do it "indents shiftwidth spaces" do vim.feedkeys 'idef long_function_name(\arg' - indent.should == shiftwidth * 2 + indent.should satisfy { |v| v == shiftwidth * 2 or v == 4 } end end describe "when using a class definition" do it "indents shiftwidth spaces" do vim.feedkeys 'iclass Foo(\' - indent.should == shiftwidth * 2 + indent.should satisfy { |v| v == shiftwidth * 2 or v == 4 } end end @@ -379,7 +379,7 @@ it "ignores the call signature after a function" do vim.feedkeys 'idef f( JEDI_CALL_SIGNATURE\' - indent.should == shiftwidth * 2 + indent.should satisfy { |v| v == shiftwidth * 2 or v == 4 } end end end