Skip to content

Commit c32b187

Browse files
committed
Respect curly brace padding setting in YAML
1 parent 6f07135 commit c32b187

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

autoload/sj/yaml.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ function! sj#yaml#JoinMap()
237237
let lines = s:NormalizeWhitespace(lines)
238238
let lines = map(lines, 's:StripComment(v:val)')
239239

240-
let replacement = first_line . ' { '. join(lines, ', ') . ' }'
240+
if sj#settings#Read('curly_brace_padding')
241+
let replacement = first_line . ' { '. join(lines, ', ') . ' }'
242+
else
243+
let replacement = first_line . ' {'. join(lines, ', ') . '}'
244+
endif
241245

242246
call sj#ReplaceLines(line_no, last_line_no, replacement)
243247
silent! normal! zO

spec/plugin/yaml_spec.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
vim.set 'shiftwidth', 2
99
end
1010

11+
after :each do
12+
vim.command('silent! unlet g:splitjoin_curly_brace_padding')
13+
end
14+
1115
describe "arrays" do
1216
specify "basic" do
1317
set_file_contents <<~EOF
@@ -396,7 +400,6 @@
396400
end: true
397401
EOF
398402
end
399-
400403
end
401404

402405
describe "maps" do
@@ -447,6 +450,20 @@
447450
EOF
448451
end
449452

453+
specify "without padding" do
454+
vim.command 'let g:splitjoin_curly_brace_padding = 0'
455+
456+
set_file_contents <<~EOF
457+
root:
458+
one: 1
459+
EOF
460+
461+
vim.search 'root:'
462+
join
463+
464+
assert_file_contents 'root: {one: 1}'
465+
end
466+
450467
specify "complex keys" do
451468
set_file_contents <<~EOF
452469
map:
@@ -669,6 +686,5 @@
669686
- prop: { a: 'one', b: 'two' }
670687
EOF
671688
end
672-
673689
end
674690
end

0 commit comments

Comments
 (0)