Last active
October 24, 2015 13:48
-
-
Save koturn/7cf637f03101fc026006 to your computer and use it in GitHub Desktop.
ctrlp.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
scriptencoding utf-8 | |
" オーソドックスなctrlp.vimのエクステンションのテンプレート | |
let s:save_cpo = &cpo | |
set cpo&vim | |
if exists('g:loaded_ctrlp_template01') && g:loaded_ctrlp_template01 | |
finish | |
endif | |
let g:loaded_ctrlp_template01 = 1 | |
let s:ctrlp_builtins = ctrlp#getvar('g:ctrlp_builtins') | |
let s:template01_var = { | |
\ 'init': 'ctrlp#template01#init()', | |
\ 'accept': 'ctrlp#template01#accept', | |
\ 'lname': 'template01', | |
\ 'sname': 'template01', | |
\ 'type': 'line', | |
\ 'enter': 'ctrlp#template01#enter()', | |
\ 'exit': 'ctrlp#template01#exit()', | |
\ 'opts': 'ctrlp#template01#opts()', | |
\ 'sort': 0, | |
\ 'nolim': 1 | |
\} | |
if exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) | |
call add(g:ctrlp_ext_vars, s:template01_var) | |
else | |
let g:ctrlp_ext_vars = [s:template01_var] | |
endif | |
let s:id = s:ctrlp_builtins + len(g:ctrlp_ext_vars) | |
unlet s:ctrlp_builtins | |
function! ctrlp#template01#id() abort | |
return s:id | |
endfunction | |
function! ctrlp#template01#init() abort | |
let candidates = ['apple', 'banana', 'cake'] | |
return candidates | |
endfunction | |
function! ctrlp#template01#accept(mode, str) abort | |
call ctrlp#exit() | |
" Write actions here | |
endfunction | |
function! ctrlp#template01#enter() abort | |
" Called before ctrlp#template01#init() | |
endfunction | |
function! ctrlp#template01#exit() abort | |
" Called when exit ctrlp | |
endfunction | |
function! ctrlp#template01#opts() abort | |
" Set options etc... | |
endfunction | |
let &cpo = s:save_cpo | |
unlet s:save_cpo |
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
scriptencoding utf-8 | |
" グローバル関数を嫌ったctrlp.vimのエクステンションのテンプレート | |
let s:save_cpo = &cpo | |
set cpo&vim | |
if exists('g:loaded_ctrlp_template02') && g:loaded_ctrlp_template02 | |
finish | |
endif | |
let g:loaded_ctrlp_template02 = 1 | |
let s:ctrlp_builtins = ctrlp#getvar('g:ctrlp_builtins') | |
function! s:get_sid() abort | |
return matchstr(expand('<sfile>'), '^function <SNR>\zs\d\+\ze_get_sid$') | |
endfunction | |
let s:sid_prefix = '<SNR>' . s:get_sid() . '_' | |
let g:ctrlp_ext_vars = add(get(g:, 'ctrlp_ext_vars', []), { | |
\ 'init': s:sid_prefix . 'init()', | |
\ 'accept': s:sid_prefix . 'accept', | |
\ 'lname': 'template02', | |
\ 'sname': 'template02', | |
\ 'type': 'line', | |
\ 'enter': s:sid_prefix . 'enter()', | |
\ 'exit': s:sid_prefix . 'exit()', | |
\ 'opts': s:sid_prefix . 'opts()', | |
\ 'sort': 0, | |
\ 'nolim': 1 | |
\}) | |
let s:id = s:ctrlp_builtins + len(g:ctrlp_ext_vars) | |
delfunction s:get_sid | |
unlet s:ctrlp_builtins s:sid_prefix | |
function! ctrlp#template02#id() abort | |
return s:id | |
endfunction | |
function! s:init() abort | |
let candidates = ['apple', 'banana', 'cake'] | |
return candidates | |
endfunction | |
function! s:accept(mode, str) abort | |
call ctrlp#exit() | |
" Write actions here | |
endfunction | |
function! s:enter() abort | |
" Called before s:init() | |
endfunction | |
function! s:exit() abort | |
" Called when exit ctrlp | |
endfunction | |
function! s:opts() abort | |
" Set options etc... | |
endfunction | |
let &cpo = s:save_cpo | |
unlet s:save_cpo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment