Skip to content

Instantly share code, notes, and snippets.

@presuku
Created June 11, 2015 05:44
Show Gist options
  • Save presuku/605b352daf26feb6625c to your computer and use it in GitHub Desktop.
Save presuku/605b352daf26feb6625c to your computer and use it in GitHub Desktop.
function! MigemoMatch(items, str, limit, mmode, ispath, crfile, regex)
if has('migmeo')
let tmp = tempname()
try
if a:str =~ '^\s*$'
return a:items
endif
call writefile(split(iconv(join(a:items, "\n"), &encoding, 'utf-8'), "\n"), tmp)
return split(iconv(system(
\ printf('migemogrep %s %s',
\ shellescape(a:str),
\ shellescape(tmp))), 'utf-8', &encoding), "\n")
catch
return []
finally
call delete(tmp)
endtry
else
try
if a:str =~ '^\s*$'
return copy(a:items)
endif
let migemoed_str = migemo(a:str)
let new_items = filter(copy(a:items), 'match(v:val, migemoed_str) >= 0')
if ! empty(new_items)
return new_items
else
return []
endif
catch
return copy(a:items)
endtry
endif
endfunction
function! SetMigemoMatcher()
let g:ctrlp_match_func = {'match' : 'MigemoMatch' }
endfunction
function! SetMigemoMatcher()
let g:ctrlp_match_func = {}
endfunction
command! CtrlPSetMigemoMatcher call SetMigemoMatcher()
command! CtrlPSetDefaultMatcher call SetDefaultMatcher()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment