Better paren matching

This commit is contained in:
Alex Yatskov 2014-12-02 12:15:21 +09:00
parent 1572562998
commit 897535d60b

View File

@ -65,7 +65,7 @@ function! argwrap#findClosestRange()
endif endif
endfunction endfunction
function! argwrap#extractArgumentText(range) function! argwrap#extractContainerArgText(range)
let l:text = '' let l:text = ''
for l:lineIndex in range(a:range.lineStart, a:range.lineEnd) for l:lineIndex in range(a:range.lineStart, a:range.lineEnd)
@ -107,7 +107,7 @@ function! argwrap#trimArgument(text)
return substitute(a:text, '^\s*\(.\{-}\)\s*$', '\1', '') return substitute(a:text, '^\s*\(.\{-}\)\s*$', '\1', '')
endfunction endfunction
function! argwrap#extractArguments(text) function! argwrap#extractContainerArgs(text)
let l:stack = [] let l:stack = []
let l:arguments = [] let l:arguments = []
let l:argument = '' let l:argument = ''
@ -164,19 +164,30 @@ function! argwrap#unwrapContainer(range, container, arguments)
exec printf('%d,%dd_', a:range.lineStart + 1, a:range.lineEnd) exec printf('%d,%dd_', a:range.lineStart + 1, a:range.lineEnd)
endfunction endfunction
function! argwrap#adjustCursor()
let [l:buffer, l:line, l:col, l:offset] = getpos('.')
let l:lineText = getline('.')
let l:col = match(l:lineText, '[\(\[\{]')
if l:col >= 0
if l:col + 1 == strlen(l:lineText)
call cursor(l:line + 1, 0)
else
call cursor(l:line, l:col + 2)
endif
endif
endfunction
function! argwrap#toggle() function! argwrap#toggle()
let l:range = argwrap#findClosestRange() call argwrap#adjustCursor()
if !argwrap#validateRange(l:range)
call search('[\(\[\{]', 'W')
call search('[^\(\[\{]', 'W')
let l:range = argwrap#findClosestRange() let l:range = argwrap#findClosestRange()
if !argwrap#validateRange(l:range) if !argwrap#validateRange(l:range)
return return
endif endif
endif
let l:argText = argwrap#extractArgumentText(l:range) let l:argText = argwrap#extractContainerArgText(l:range)
let l:arguments = argwrap#extractArguments(l:argText) let l:arguments = argwrap#extractContainerArgs(l:argText)
let l:container = argwrap#extractContainer(l:range) let l:container = argwrap#extractContainer(l:range)
if l:range.lineStart == l:range.lineEnd if l:range.lineStart == l:range.lineEnd