function! sj#perl#SplitSuffixIfClause() let pattern = '\(.*\) \(if\|unless\|while\|until\) \(.*\);\s*$' if sj#settings#Read('perl_brace_on_same_line') let replacement = "\\2 (\\3) {\n\\1;\n}" else let replacement = "\\2 (\\3) \n{\n\\1;\n}" endif return s:Split(pattern, replacement) endfunction function! sj#perl#SplitPrefixIfClause() let pattern = '\\\s\\+", "=> ", "")') let lines = map(lines, 'substitute(v:val, "\\s\\+=>", " =>", "")') endif let body = join(lines, ', ') call sj#ReplaceMotion('Va{', '{'.body.'}') return 1 endfunction function! sj#perl#SplitSquareBracketedList() let [from, to] = sj#LocateBracesOnLine('[', ']') if from < 0 && to < 0 return 0 endif let items = sj#ParseJsonObjectBody(from + 1, to - 1) 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 endfunction function! sj#perl#SplitRoundBracketedList() let [from, to] = sj#LocateBracesOnLine('(', ')') if from < 0 && to < 0 return 0 endif let items = sj#ParseJsonObjectBody(from + 1, to - 1) 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 endfunction function! sj#perl#SplitWordList() let [from, to] = sj#LocateBracesOnLine('qw(', ')') if from < 0 && to < 0 return 0 endif call search('qw\zs(', 'b', line('.')) let remainder_of_line = getline('.')[col('.') - 1 : -1] if remainder_of_line !~ '\%(\w\|\s\)\+)' return 0 endif let items = split(matchstr(remainder_of_line, '\%(\k\|\s\)\+'), '\s\+') let body = "(\n".join(items, "\n")."\n)" call sj#ReplaceMotion('Va(', body) return 1 endfunction function! sj#perl#JoinSquareBracketedList() let line = getline('.') if search('[\s*$', 'c', line('.')) <= 0 return 0 endif let body = sj#GetMotion('Vi[') let lines = split(body, ",\n") let lines = sj#TrimList(lines) let body = join(lines, ', ') call sj#ReplaceMotion('Va[', '['.body.']') return 1 endfunction function! sj#perl#JoinRoundBracketedList() let line = getline('.') if search('(\s*$', 'c', line('.')) <= 0 return 0 endif let body = sj#GetMotion('Vi(') let lines = split(body, ",\n") let lines = sj#TrimList(lines) let body = join(lines, ', ') call sj#ReplaceMotion('Va(', '('.body.')') return 1 endfunction function! sj#perl#JoinWordList() let line = getline('.') if search('qw\zs(\s*$', 'c', line('.')) <= 0 return 0 endif let body = sj#GetMotion('Vi(') let lines = split(body, "\n") let lines = sj#TrimList(lines) let body = join(lines, ' ') call sj#ReplaceMotion('Va(', '('.body.')') return 1 endfunction function! s:Split(pattern, replacement_pattern) let line = getline('.') if line !~ a:pattern return 0 endif call sj#ReplaceMotion('V', substitute(line, a:pattern, a:replacement_pattern, '')) return 1 endfunction