Skip to content

Instantly share code, notes, and snippets.

@mattn
Created March 29, 2016 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/47e64dd5ed56c547cf8d to your computer and use it in GitHub Desktop.
Save mattn/47e64dd5ed56c547cf8d to your computer and use it in GitHub Desktop.
let s:wrap = {}
let s:last = ''
function! s:omniwrap(name)
if has_key(s:wrap, &ft)
let s:wrap[&ft] = []
endif
if index(s:wrap[&ft], a:name) == -1
call add(s:wrap[&ft], a:name)
endif
setlocal omnifunc=OmniWrap
endfunction
function! OmniWrap(findstart, base)
if a:findstart
let s:last = ''
if !has_key(s:wrap, &ft)
return -1
endif
for name in s:wrap[&ft]
try
let ret = call(name, [a:findstart, a:base])
if ret >= 0
let s:last = name
return ret
endif
catch
endtry
endif
return -1
endif
return call(s:last, [a:findstart, a:base])
endfunction
command! -nargs=1 OmniWrap call s:omniwrap(<q-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment