Skip to content

Commit 01d932d

Browse files
committed
Fix issue with using :join for continuations
In case 'formatoptions' contains "j" and the continued line starts with a comment character, the "join" ends up removing the comment character. We don't actually have to use `:join` here, the right `substitute` should do it.
1 parent 937f216 commit 01d932d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

autoload/sj/vim.vim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ function! sj#vim#Join()
4646
endif
4747

4848
if next_line =~ continuation_pattern.'\s'
49-
" Then there's some whitespace after the \, rely on :join
50-
keeppatterns exe next_lineno.'s/'.continuation_pattern.'//'
51-
exe current_lineno.','.next_lineno.'join'
49+
" Then there's some whitespace after the \, join with a space
50+
keeppatterns exe current_lineno.'s/\n'.continuation_pattern.'\s*/ /'
5251
else
5352
" No whitespace, let's join them directly
5453
keeppatterns exe current_lineno.'s/\n'.continuation_pattern.'//'

spec/plugin/vim_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,21 @@
6767
let foo = 2+2
6868
EOF
6969
end
70+
71+
# Fix for https://github.com/AndrewRadev/splitjoin.vim/issues/216
72+
specify "backslashes interpreted as a comment" do
73+
set_file_contents <<~EOF
74+
let foo = foo(
75+
\\ '!#;'.var,
76+
\\ \#{curwin: 0})
77+
EOF
78+
79+
vim.search('var')
80+
join
81+
82+
assert_file_contents <<~EOF
83+
let foo = foo(
84+
\\ '!#;'.var, \#{curwin: 0})
85+
EOF
86+
end
7087
end

0 commit comments

Comments
 (0)