Skip to content

Commit 451c701

Browse files
committed
Function argument splitting for python
1 parent e84d7ea commit 451c701

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

autoload/sj/python.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,22 @@ function! sj#python#SplitTuple()
8787
return s:SplitList('(.\{-})', '(', ')')
8888
endfunction
8989

90+
function! sj#python#SplitArgs()
91+
if search('\%#[[:keyword:].]\+(', 'e', line('.'))
92+
return sj#python#SplitTuple()
93+
endif
94+
endfunction
95+
9096
function! sj#python#JoinTuple()
9197
return s:JoinList('([^()]*\s*$', '(', ')')
9298
endfunction
9399

100+
function! sj#python#JoinArgs()
101+
if search('\%#[[:keyword:].]\+(', 'e', line('.'))
102+
return sj#python#JoinTuple()
103+
endif
104+
endfunction
105+
94106
function! sj#python#SplitImport()
95107
let import_pattern = '^\s*from \%(.*\) import \zs.*$'
96108

ftplugin/python/splitjoin.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ if !exists('b:splitjoin_split_callbacks')
33
\ 'sj#python#SplitString',
44
\ 'sj#python#SplitListComprehension',
55
\ 'sj#python#SplitTuple',
6+
\ 'sj#python#SplitArgs',
67
\ 'sj#python#SplitAssignment',
78
\ 'sj#python#SplitTernaryAssignment',
89
\ 'sj#python#SplitDict',
@@ -18,6 +19,7 @@ if !exists('b:splitjoin_join_callbacks')
1819
\ 'sj#python#JoinImportWithRoundBrackets',
1920
\ 'sj#python#JoinMultilineString',
2021
\ 'sj#python#JoinTuple',
22+
\ 'sj#python#JoinArgs',
2123
\ 'sj#python#JoinDict',
2224
\ 'sj#python#JoinArray',
2325
\ 'sj#python#JoinTernaryAssignment',

spec/plugin/python_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@
6464
assert_file_contents 'spam = [1, [2, 3], 4]'
6565
end
6666

67+
specify "function arguments" do
68+
set_file_contents 'spam = callable(one, [2, 3], four)'
69+
70+
vim.search 'callable'
71+
split
72+
73+
assert_file_contents <<~EOF
74+
spam = callable(one,
75+
[2, 3],
76+
four)
77+
EOF
78+
79+
join
80+
81+
assert_file_contents 'spam = callable(one, [2, 3], four)'
82+
end
83+
6784
specify "imports" do
6885
set_file_contents <<~EOF
6986
def surrounding_function():

0 commit comments

Comments
 (0)