Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions autoload/sj/perl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ function! sj#perl#SplitSquareBracketedList()
endif

let items = sj#ParseJsonObjectBody(from + 1, to - 1)
let body = "[\n".join(items, ",\n")."\n]"
let body = "[\n".join(items, ",\n")
if sj#settings#Read('trailing_comma')
let body .= ","
endif
let body .= "\n]"
call sj#ReplaceMotion('Va[', body)

return 1
Expand All @@ -143,7 +147,11 @@ function! sj#perl#SplitRoundBracketedList()
endif

let items = sj#ParseJsonObjectBody(from + 1, to - 1)
let body = "(\n".join(items, ",\n")."\n)"
let body = "(\n".join(items, ",\n")
if sj#settings#Read('trailing_comma')
let body .= ","
endif
let body .= "\n)"
call sj#ReplaceMotion('Va(', body)

return 1
Expand Down
4 changes: 2 additions & 2 deletions doc/splitjoin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ Hashes ~
<
Lists ~
>
my @var = ['one', 'two', 'three'];
my $var = ['one', 'two', 'three'];

my @var = [
my $var = [
'one',
'two',
'three'
Expand Down
42 changes: 42 additions & 0 deletions spec/plugin/perl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
vim.set(:shiftwidth, 2)
end

after :each do
vim.command('silent! unlet g:splitjoin_trailing_comma')
end

after :all do
# The perl filetype messes with iskeyword...
vim.command('set iskeyword-=:')
Expand Down Expand Up @@ -92,6 +96,25 @@
assert_file_contents "my @var = ['one', 'two', 'three'];"
end

specify "square-bracketed list, trailing comma" do
vim.command('let g:splitjoin_trailing_comma = 1')
set_file_contents "my @var = ['one', 'two', 'three'];"

split

assert_file_contents <<~EOF
my @var = [
'one',
'two',
'three',
];
EOF

join

assert_file_contents "my @var = ['one', 'two', 'three'];"
end

specify "round-bracketed list" do
set_file_contents "my @var = ('one', 'two', 'three');"

Expand All @@ -110,6 +133,25 @@
assert_file_contents "my @var = ('one', 'two', 'three');"
end

specify "round-bracketed list, trailing comma" do
vim.command('let g:splitjoin_trailing_comma = 1')
set_file_contents "my @var = ('one', 'two', 'three');"

split

assert_file_contents <<~EOF
my @var = (
'one',
'two',
'three',
);
EOF

join

assert_file_contents "my @var = ('one', 'two', 'three');"
end

specify "word lists" do
set_file_contents "my @var = qw(one two three);"

Expand Down