Skip to content

Commit fef3759

Browse files
authored
Address Flake8's E127 with "if (" (#102)
> continuation line over-indented for visual indent It appears that the "if (" is just the 4 columns wide that triggers the extra indent with sw=4. Might also change/adjust b:control_statement to ignore `if (`, but this appears to be more flexible/correct.
1 parent c5e3545 commit fef3759

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

indent/python.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,13 @@ function! s:indent_like_opening_paren(lnum)
225225
" indent further to distinguish the continuation line
226226
" from the next logical line.
227227
if text =~# b:control_statement && res == base + s:sw()
228-
return base + s:sw() * 2
229-
else
230-
return res
228+
" But only if not inside parens itself (Flake's E127).
229+
let [paren_lnum, _] = s:find_opening_paren(paren_lnum)
230+
if paren_lnum <= 0
231+
return res + s:sw()
232+
endif
231233
endif
234+
return res
232235
endfunction
233236

234237
" Match indent of first block of this type.

spec/indent/indent_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@
251251
indent.should == 0
252252
end
253253

254+
it "handles nested expressions (Flake8's E127)" do
255+
vim.feedkeys 'i[\<CR>x for x in foo\<CR>if (\<CR>'
256+
indent.should == shiftwidth * 2
257+
end
258+
254259
it "still handles multiple parens correctly" do
255260
vim.feedkeys 'iif (111 and (222 and 333\<CR>'
256261
indent.should == 13

0 commit comments

Comments
 (0)