Last active
August 29, 2015 14:26
-
-
Save koturn/b9cf9e9f6f7a27cec869 to your computer and use it in GitHub Desktop.
無理矢理NeoBundleのautoloadのcommandの補完関数にスクリプトローカル関数を指定する例
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
set encoding=utf-8 | |
scriptencoding utf-8 | |
if has('vim_starting') | |
set rtp+=~/.vim/bundle/neobundle.vim | |
endif | |
call neobundle#begin() | |
NeoBundleFetch 'Shougo/neobundle.vim' | |
let g:neobundle#default_options = {'_': {'verbose': 1}} | |
augroup CompleteDummy | |
autocmd! | |
augroup END | |
function! s:SID() abort | |
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$') | |
endfun | |
let s:sid = s:SID() | |
delfunction s:SID | |
function! s:to_global_name(scriptlocal_funcname) abort | |
return '<SNR>' . s:sid . '_' . a:scriptlocal_funcname | |
endfunction | |
" 適当なイベントが発生したら,補完関数を消去 | |
function! s:delete_function_lazy(funcname) abort | |
execute 'autocmd CompleteDummy CursorHold,CursorHoldI,CursorMoved,CursorMovedI,InsertEnter *' | |
\ 'delfunction' a:funcname | |
\ '| autocmd! CompleteDummy CursorHold,CursorHoldI,CursorMoved,CursorMovedI,InsertEnter *' | |
endfunction | |
if neobundle#load_cache() | |
NeoBundleLazy 'osyo-manga/vim-reanimate' | |
" キャッシュされる設定はこっちに書く | |
if neobundle#tap('vim-reanimate') | |
let s:_ = 'customlist,' . s:to_global_name('reanimate_save_point_completelist') | |
call neobundle#config({ | |
\ 'autoload': { | |
\ 'commands': [ | |
\ {'name': 'ReanimateSave', 'complete': s:_}, | |
\ 'ReanimateSaveCursorHold', | |
\ 'ReanimateSaveInput', | |
\ {'name': 'ReanimateLoad', 'complete': s:_}, | |
\ 'ReanimateLoadInput', | |
\ 'ReanimateLoadLatest', | |
\ {'name': 'ReanimateSwitch', 'complete': s:_}, | |
\ {'name': 'ReanimateEditVimrcLocal', 'complete': s:_}, | |
\ 'ReanimateUnLoad' | |
\ ] | |
\ } | |
\}) | |
unlet s:_ | |
call neobundle#untap() | |
endif | |
NeoBundleSaveCache | |
endif | |
call neobundle#end() | |
" キャッシュされないグローバル変数の設定等がこっち | |
if neobundle#tap('vim-reanimate') | |
" plugin/reanimate.vim を見て実装 | |
function! s:reanimate_save_point_completelist(arglead, ...) abort | |
return filter(reanimate#save_points(), "v:val =~? '" . a:arglead . "'") | |
endfunction | |
" neobundle#tapped.hooks.on_source() でもいい | |
function! neobundle#tapped.hooks.on_post_source(bundle) abort | |
" 仮のコマンド定義から実際のコマンド定義になる. | |
" 従って,一時的な補完関数は不必要になるので消去 | |
call s:delete_function_lazy('s:reanimate_save_point_completelist') | |
endfunction | |
let g:reanimate_save_dir = '~/.vim/save' | |
let g:reanimate_default_save_name = 'reanimate' | |
let g:reanimate_sessionoptions = 'curdir,folds,help,localoptions,slash,tabpages,winsize' | |
call neobundle#untap() | |
endif | |
if !has('vim_starting') | |
call neobundle#call_hook('on_source') | |
endif | |
filetype plugin indent on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment