Skip to content

Commit 42b2305

Browse files
committed
Indent dictionary values on a new line extra
1 parent 7dfebca commit 42b2305

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

indent/python.vim

+7-3
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,14 @@ function! s:indent_like_opening_paren(lnum)
221221
" indent further to distinguish the continuation line
222222
" from the next logical line.
223223
if text =~# b:control_statement && res == base + s:sw()
224-
return base + s:sw() * 2
225-
else
226-
return res
224+
let res = base + s:sw() * 2
225+
endif
226+
227+
" If a colon is the final character on previous line
228+
if getline(a:lnum-1) =~ ':\s*$'
229+
let res = res + s:sw()
227230
endif
231+
return res
228232
endfunction
229233

230234
" Match indent of first block of this type.

spec/indent/indent_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@
9191
end
9292
end
9393

94+
describe "after a dictionary key" do
95+
before { vim.feedkeys 'imydict = {"12345": ' }
96+
97+
it "indents to opening paren + shiftwidth" do
98+
vim.feedkeys '\<CR>'
99+
indent.should == 10 + shiftwidth
100+
end
101+
it "on a new line indents to opening paren + shiftwidth" do
102+
vim.feedkeys '123,\<CR>"4567": '
103+
indent.should == 10
104+
vim.feedkeys '\<CR>'
105+
indent.should == 10 + shiftwidth
106+
end
107+
end
108+
109+
94110
describe "when using gq to reindent a '(' that is" do
95111
before { vim.feedkeys 'itest(' }
96112
it "something and has a string without spaces at the end" do

0 commit comments

Comments
 (0)