Add repeat.vim support to surround with function

Closes #106.
This commit is contained in:
Tom McDonald 2014-04-11 14:43:46 -04:00
parent 42e9b46e7a
commit 4e73eeb01d

View File

@ -127,7 +127,7 @@ endfunction
function! s:wrap(string,char,type,...) function! s:wrap(string,char,type,...)
let keeper = a:string let keeper = a:string
let newchar = a:char let newchar = a:char
let s:tag = "" let s:input = ""
let type = a:type let type = a:type
let linemode = type ==# 'V' ? 1 : 0 let linemode = type ==# 'V' ? 1 : 0
let special = a:0 ? a:1 : 0 let special = a:0 ? a:1 : 0
@ -185,10 +185,10 @@ function! s:wrap(string,char,type,...)
if dounmapb if dounmapb
silent! cunmap > silent! cunmap >
endif endif
let s:tag = tag let s:input = tag
if tag != "" if tag != ""
let tag = substitute(tag,'>*$','','') let tag = substitute(tag,'>*$','','')
let s:tag = tag . '>' let s:input = tag . '>'
let before = '<'.tag.'>' let before = '<'.tag.'>'
if tag =~ '/$' if tag =~ '/$'
let after = '' let after = ''
@ -217,6 +217,7 @@ function! s:wrap(string,char,type,...)
elseif newchar ==# 'f' || newchar ==# 'F' elseif newchar ==# 'f' || newchar ==# 'F'
let fnc = input('function: ') let fnc = input('function: ')
if fnc != "" if fnc != ""
let s:input = fnc."\<CR>"
let before = substitute(fnc,'($','','').'(' let before = substitute(fnc,'($','','').'('
let after = ')' let after = ')'
if newchar ==# 'F' if newchar ==# 'F'
@ -226,6 +227,7 @@ function! s:wrap(string,char,type,...)
endif endif
elseif newchar ==# "\<C-F>" elseif newchar ==# "\<C-F>"
let fnc = input('function: ') let fnc = input('function: ')
let s:input = fnc."\<CR>"
let before = '('.fnc.' ' let before = '('.fnc.' '
let after = ')' let after = ')'
elseif idx >= 0 elseif idx >= 0
@ -454,7 +456,7 @@ function! s:dosurround(...) " {{{1
if newchar == "" if newchar == ""
silent! call repeat#set("\<Plug>Dsurround".char,scount) silent! call repeat#set("\<Plug>Dsurround".char,scount)
else else
silent! call repeat#set("\<Plug>Csurround".char.newchar.s:tag,scount) silent! call repeat#set("\<Plug>Csurround".char.newchar.s:input,scount)
endif endif
endfunction " }}}1 endfunction " }}}1
@ -527,9 +529,9 @@ function! s:opfunc(type,...) " {{{1
let &selection = sel_save let &selection = sel_save
let &clipboard = cb_save let &clipboard = cb_save
if a:type =~ '^\d\+$' if a:type =~ '^\d\+$'
silent! call repeat#set("\<Plug>Y".(a:0 && a:1 ? "S" : "s")."surround".char.s:tag,a:type) silent! call repeat#set("\<Plug>Y".(a:0 && a:1 ? "S" : "s")."surround".char.s:input,a:type)
else else
silent! call repeat#set("\<Plug>SurroundRepeat".char.s:tag) silent! call repeat#set("\<Plug>SurroundRepeat".char.s:input)
endif endif
endfunction endfunction