Permalink
Browse files

Use global helpers to reduce some duplication

  • Loading branch information...
1 parent 885c89b commit 9c3b3a852940f5115005c4c04c8b0bdc8507285a @AndrewRadev AndrewRadev committed Apr 8, 2012
Showing with 4 additions and 33 deletions.
  1. +4 −33 autoload/sj/php.vim
View
37 autoload/sj/php.vim
@@ -5,11 +5,12 @@ function! sj#php#SplitArray()
if line !~? arraypattern
return 0
else
- let [from, to] = sj#php#LocateParenOnLine()
+ let [from, to] = sj#LocateBracesOnLine('(', ')')
+
if from < 0 && to < 0
return 0
else
- let pairs = s:ParseHash(from + 1, to - 1)
+ let pairs = sj#ParseJsonObjectBody(from + 1, to - 1)
let body = "(\n".join(pairs, ",\n")."\n)"
call sj#ReplaceMotion('Va(', body)
@@ -19,42 +20,12 @@ function! sj#php#SplitArray()
call sj#PushCursor()
exe "normal! jV".(body_end - body_start)."j2="
call sj#PopCursor()
-
endif
+
return 1
endif
endfunction
function! sj#php#JoinArray()
call sj#JoinHashWithRoundBraces()
endfunction
-
-function! s:ParseHash(from, to)
- " Js object parser works just fine
- let parser = sj#argparser#js#Construct(a:from, a:to, getline('.'))
- call parser.Process()
- return parser.args
-endfunction
-
-function! sj#php#LocateParenOnLine()
- let [_bufnum, line, col, _off] = getpos('.')
-
- if getline('.') !~ '(.*)'
- return [-1, -1]
- endif
-
- let found = searchpair('(', '', ')', 'cb', '', line('.'))
- if found <= 0
- let found = search('(', '', '', line('.'))
- endif
-
- if found > 0
- let from = col('.') - 1
- normal! %
- let to = col('.')
-
- return [from, to]
- else
- return [-1, -1]
- endif
-endfunction

0 comments on commit 9c3b3a8

Please sign in to comment.