Container extraction
This commit is contained in:
parent
0b4d014c2e
commit
39da034ec5
38
wrap.vim
38
wrap.vim
@ -20,36 +20,35 @@
|
|||||||
|
|
||||||
function! FindRange()
|
function! FindRange()
|
||||||
let [l:lineStart, l:colStart] = searchpairpos("(", "", ")", "Wnb")
|
let [l:lineStart, l:colStart] = searchpairpos("(", "", ")", "Wnb")
|
||||||
let [l:lineEnd, l:colEnd] = searchpairpos("(", "", ")", "Wn")
|
let [l:lineEnd, l:colEnd] = searchpairpos("(", "", ")", "Wn")
|
||||||
|
|
||||||
if l:lineStart == l:lineEnd && l:colStart == l:colEnd
|
if l:lineStart == l:lineEnd && l:colStart == l:colEnd
|
||||||
return []
|
return {}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return [l:lineStart, l:colStart, l:lineEnd, l:colEnd]
|
return {"lineStart": l:lineStart, "colStart": l:colStart, "lineEnd": l:lineEnd, "colEnd": l:colEnd}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ExtractText(range)
|
function! ExtractArgumentText(range)
|
||||||
let [l:lineStart, l:colStart, l:lineEnd, l:colEnd] = a:range
|
|
||||||
let l:text = ""
|
let l:text = ""
|
||||||
|
|
||||||
for l:lineIndex in range(l:lineStart, l:lineEnd)
|
for l:lineIndex in range(a:range.lineStart, a:range.lineEnd)
|
||||||
let l:lineText = getline(l:lineIndex)
|
let l:lineText = getline(l:lineIndex)
|
||||||
|
|
||||||
let l:extractStart = 0
|
let l:extractStart = 0
|
||||||
if l:lineIndex == l:lineStart
|
if l:lineIndex == a:range.lineStart
|
||||||
let l:extractStart = l:colStart
|
let l:extractStart = a:range.colStart
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l:extractEnd = strlen(l:lineText)
|
let l:extractEnd = strlen(l:lineText)
|
||||||
if l:lineIndex == l:lineEnd
|
if l:lineIndex == a:range.lineEnd
|
||||||
let l:extractEnd = l:colEnd - 1
|
let l:extractEnd = a:range.colEnd - 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:extractStart < l:extractEnd
|
if l:extractStart < l:extractEnd
|
||||||
let l:extract = l:lineText[l:extractStart : l:extractEnd - 1]
|
let l:extract = l:lineText[l:extractStart : l:extractEnd - 1]
|
||||||
let l:extract = substitute(l:extract, "^\\s\\+", "", "g")
|
let l:extract = substitute(l:extract, "^\\s\\+", "", "g")
|
||||||
let l:extract = substitute(l:extract, ",$", ", ", "g")
|
let l:extract = substitute(l:extract, ",", ", ", "g")
|
||||||
let l:text .= l:extract
|
let l:text .= l:extract
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
@ -95,14 +94,25 @@ function! ExtractArguments(text)
|
|||||||
return l:arguments
|
return l:arguments
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ExtractContainer(range)
|
||||||
|
let l:line = getline(a:range.lineStart)
|
||||||
|
let l:indent = match(l:line, "\\S")
|
||||||
|
let l:prefix = l:line[l:indent : a:range.colStart - 1]
|
||||||
|
|
||||||
|
let l:line = getline(a:range.lineEnd)
|
||||||
|
let l:suffix = l:line[a:range.colEnd - 1:]
|
||||||
|
|
||||||
|
return {"indent": l:indent, "prefix": l:prefix, "suffix": l:suffix}
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! Wrap()
|
function! Wrap()
|
||||||
let l:range = FindRange()
|
let l:range = FindRange()
|
||||||
if len(l:range) == 0
|
if len(l:range) == 0
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l:text = ExtractText(l:range)
|
let l:text = ExtractArgumentText(l:range)
|
||||||
let l:args = ExtractArguments(l:text)
|
let l:args = ExtractArguments(l:text)
|
||||||
echo l:args
|
let l:cont = ExtractContainer(l:range)
|
||||||
|
echo l:cont
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user