vim-easymotion/autoload/vital/_easymotion/Over/Commandline/Modules/Doautocmd.vim

77 lines
1.4 KiB
VimL
Raw Normal View History

2014-02-04 23:32:29 -05:00
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:cache_command = {}
2014-08-27 21:22:57 -04:00
function! s:doautocmd_user(prefix, command)
let group = a:prefix . "-vital-over-commandline-doautocmd-dummy"
2014-02-04 23:32:29 -05:00
if !has_key(s:cache_command, a:command)
2014-08-27 21:22:57 -04:00
execute "autocmd " . group
2014-02-04 23:32:29 -05:00
\ . " User " . a:command." silent! execute ''"
if v:version > 703 || v:version == 703 && has("patch438")
let s:cache_command[a:command] = "doautocmd <nomodeline> User " . a:command
else
let s:cache_command[a:command] = "doautocmd User " . a:command
endif
endif
execute s:cache_command[a:command]
endfunction
let s:hooks = [
\ "enter",
\ "leave",
\ "char",
\ "char_pre",
2014-06-06 12:35:19 -04:00
\ "draw",
\ "draw_pre",
2014-02-04 23:32:29 -05:00
\ "execute_pre",
\ "execute_failed",
\ "execute",
2014-06-06 12:35:19 -04:00
\ "exception",
2014-02-04 23:32:29 -05:00
\]
let s:hooks_camel = [
\ "Enter",
\ "Leave",
\ "Char",
\ "CharPre",
2014-06-06 12:35:19 -04:00
\ "Draw",
\ "DrawPre",
2014-02-04 23:32:29 -05:00
\ "ExecutePre",
\ "ExecuteFailed",
\ "Execute",
2014-06-06 12:35:19 -04:00
\ "Exception",
2014-02-04 23:32:29 -05:00
\]
let s:module = {
\ "name" : "Doautocmd",
\}
for s:i in range(len(s:hooks))
2014-08-27 21:22:57 -04:00
execute join([
2014-02-04 23:32:29 -05:00
\ "function! s:module.on_" . s:hooks[s:i] . "(...)",
2014-08-27 21:22:57 -04:00
\ " call s:doautocmd_user(self.prefix, self.prefix . " . string(s:hooks_camel[s:i]) . ")",
2014-02-04 23:32:29 -05:00
\ "endfunction",
\ ], "\n")
endfor
function! s:make(prefix)
2014-08-27 21:22:57 -04:00
execute "augroup " a:prefix . "-vital-over-commandline-doautocmd-dummy"
autocmd!
augroup END
2014-02-04 23:32:29 -05:00
let module = deepcopy(s:module)
let module.prefix = a:prefix
return module
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo