Handling arbitrary ext_vars

This commit is contained in:
Kien N 2012-03-16 23:30:49 +07:00
parent af2847a65d
commit fbdd0fa10a
2 changed files with 14 additions and 14 deletions

View File

@ -204,7 +204,7 @@ fu! s:Close()
unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ g:ctrlp_nolimit \ g:ctrlp_nolimit
cal ctrlp#recordhist() cal ctrlp#recordhist()
cal s:onexit() cal s:extvar('exit')
cal s:log(0) cal s:log(0)
ec ec
endf endf
@ -227,6 +227,7 @@ fu! ctrlp#reset()
cal s:opts() cal s:opts()
cal ctrlp#utils#opts() cal ctrlp#utils#opts()
cal ctrlp#mrufiles#opts() cal ctrlp#mrufiles#opts()
cal s:extvar('opts')
endf endf
" * Files {{{1 " * Files {{{1
fu! ctrlp#files() fu! ctrlp#files()
@ -698,7 +699,7 @@ endf
fu! s:ToggleType(dir) fu! s:ToggleType(dir)
let ext = exists('g:ctrlp_ext_vars') ? len(g:ctrlp_ext_vars) : 0 let ext = exists('g:ctrlp_ext_vars') ? len(g:ctrlp_ext_vars) : 0
let s:itemtype = s:walker(g:ctrlp_builtins + ext, s:itemtype, a:dir) let s:itemtype = s:walker(2 + ext, s:itemtype, a:dir)
if s:byfname && !s:ispathitem() | let s:byfname = 0 | en if s:byfname && !s:ispathitem() | let s:byfname = 0 | en
unl! g:ctrlp_nolimit unl! g:ctrlp_nolimit
if has('syntax') && exists('g:syntax_on') if has('syntax') && exists('g:syntax_on')
@ -810,7 +811,7 @@ fu! s:AcceptSelection(mode)
if empty(line) | retu | en if empty(line) | retu | en
" Do something with it " Do something with it
let actfunc = s:itemtype < 3 ? 'ctrlp#acceptfile' let actfunc = s:itemtype < 3 ? 'ctrlp#acceptfile'
\ : g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )]['accept'] \ : g:ctrlp_ext_vars[s:itemtype - 3]['accept']
cal call(actfunc, [a:mode, line]) cal call(actfunc, [a:mode, line])
endf endf
" - CreateNewFile() {{{1 " - CreateNewFile() {{{1
@ -847,8 +848,7 @@ fu! s:CreateNewFile(...)
endf endf
" * OpenMulti() {{{1 " * OpenMulti() {{{1
fu! s:MarkToOpen() fu! s:MarkToOpen()
if s:bufnr <= 0 || s:opmul == '0' if s:bufnr <= 0 || s:opmul == '0' || ( s:itemtype > 2 && s:type() !~ 'rts' )
\ || ( s:itemtype > g:ctrlp_builtins && s:type() !~ 'rts' )
retu retu
en en
let line = !empty(s:matched) ? s:matched[line('.') - 1] : '' let line = !empty(s:matched) ? s:matched[line('.') - 1] : ''
@ -1095,9 +1095,8 @@ fu! s:lash(...)
endf endf
fu! s:ispathitem() fu! s:ispathitem()
let ext = s:itemtype - ( g:ctrlp_builtins + 1 ) retu s:itemtype < 3 ||
retu s:itemtype < 3 \ ( s:itemtype > 2 && g:ctrlp_ext_vars[s:itemtype - 3]['type'] == 'path' )
\ || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext]['type'] == 'path' )
endf endf
fu! ctrlp#dirnfile(entries) fu! ctrlp#dirnfile(entries)
@ -1525,18 +1524,18 @@ fu! s:insertcache(str)
endf endf
" Extensions {{{2 " Extensions {{{2
fu! s:type(...) fu! s:type(...)
let ext = s:itemtype - ( g:ctrlp_builtins + 1 ) retu s:itemtype > 2
retu s:itemtype > 2 ? g:ctrlp_ext_vars[ext][a:0 ? 'type' : 'sname'] : s:itemtype \ ? g:ctrlp_ext_vars[s:itemtype - 3][a:0 ? 'type' : 'sname'] : s:itemtype
endf endf
fu! s:tagfiles() fu! s:tagfiles()
retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)') retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)')
endf endf
fu! s:onexit() fu! s:extvar(key)
if exists('g:ctrlp_ext_vars') if exists('g:ctrlp_ext_vars')
cal map(filter(copy(g:ctrlp_ext_vars), cal map(filter(copy(g:ctrlp_ext_vars),
\ 'has_key(v:val, "exit")'), 'eval(v:val["exit"])') \ 'has_key(v:val, a:key)'), 'eval(v:val[a:key])')
en en
endf endf

View File

@ -20,6 +20,7 @@ let s:buftag_var = {
\ 'sname': 'bft', \ 'sname': 'bft',
\ 'exit': 'ctrlp#buffertag#exit()', \ 'exit': 'ctrlp#buffertag#exit()',
\ 'type': 'tabs', \ 'type': 'tabs',
\ 'opts': 'ctrlp#buffertag#opts()',
\ } \ }
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
@ -27,7 +28,7 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
fu! s:opts() fu! ctrlp#buffertag#opts()
let opts = { let opts = {
\ 'g:ctrlp_buftag_systemenc': ['s:enc', &enc], \ 'g:ctrlp_buftag_systemenc': ['s:enc', &enc],
\ 'g:ctrlp_buftag_ctags_bin': ['s:bin', ''], \ 'g:ctrlp_buftag_ctags_bin': ['s:bin', ''],
@ -37,7 +38,7 @@ fu! s:opts()
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1]) exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
endfo endfo
endf endf
cal s:opts() cal ctrlp#buffertag#opts()
fu! s:bins() fu! s:bins()
let bins = [ let bins = [