Created
July 3, 2012 07:35
-
-
Save kien/3038284 to your computer and use it in GitHub Desktop.
async.vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if exists('loaded_ctrlpasync') || &cp || version < 700 | |
| fini | |
| en | |
| let loaded_ctrlpasync = 1 | |
| let s:locked = 0 | |
| fu! s:async(path) | |
| if !has('clientserver') || s:locked | retu | en | |
| let svid = get(filter(split(serverlist(), "\n"), 'v:val !=? v:servername'), 0, '') | |
| if svid == '' | retu | en | |
| if remote_expr(svid, 'exists(":CtrlP")') | |
| let path = a:path != '' ? a:path : getcwd() | |
| let str = ':CtrlPClearCache<cr>:CtrlP '.path.'<cr>:winc c<cr>:redr!<cr>' | |
| cal remote_send(svid, str) | |
| let s:lastcall = { v:servername : localtime() } | |
| en | |
| endf | |
| com! -n=? -com=dir CtrlPAsync cal s:async(<q-args>) | |
| fu! s:timer(min) | |
| if has('clientserver') && !s:locked && !( exists('s:lastcall') | |
| \ && ( localtime() - get(s:lastcall, v:servername, localtime()) ) / 60 < a:min ) | |
| let s:lastcall = { v:servername : localtime() } | |
| CtrlPAsync | |
| en | |
| endf | |
| aug AsyncAug | |
| au! | |
| au CursorHold * cal s:timer(10) | |
| au FocusLost * let s:locked = 1 | |
| au FocusGained * let s:locked = 0 | |
| aug END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment