Relax the condition to reuse a window

Close #155
This commit is contained in:
Kien N 2012-03-10 06:49:16 +07:00
parent ac56d68249
commit dd832abfff
6 changed files with 57 additions and 89 deletions

View File

@ -201,7 +201,7 @@ fu! s:Close()
exe s:winres[0]
en
unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ s:winh g:ctrlp_nolimit
\ g:ctrlp_nolimit
cal ctrlp#recordhist()
cal s:onexit()
cal s:log(0)
@ -227,8 +227,8 @@ fu! ctrlp#reset()
cal ctrlp#utils#opts()
cal ctrlp#mrufiles#opts()
endf
" * Files() {{{1
fu! s:Files()
" * Files {{{1
fu! ctrlp#files()
let [cwd, cafile, g:ctrlp_allfiles] = [getcwd(), ctrlp#utils#cachefile(), []]
if g:ctrlp_newcache || !filereadable(cafile) || !s:caching
let lscmd = s:lsCmd()
@ -307,17 +307,11 @@ fu! s:lsCmd()
retu cmd['types'][key][1]
en
endf
fu! s:Buffers() "{{{1
let allbufs = []
for each in range(1, bufnr('$'))
if each != s:bufnr && getbufvar(each, '&bl')
let bufname = bufname(each)
if strlen(bufname) && getbufvar(each, '&ma')
cal add(allbufs, fnamemodify(bufname, ':.'))
en
en
endfo
retu allbufs
" Buffers {{{1
fu! ctrlp#buffers()
retu map(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
\ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))'),
\ 'fnamemodify(bufname(v:val), ":.")')
endf
" * MatchedItems() {{{1
fu! s:MatchIt(items, pat, limit, mfunc, ipt)
@ -585,7 +579,7 @@ fu! s:PrtClearCache()
if s:itemtype == 2
let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 1)
el
cal s:SetLines(s:itemtype)
cal ctrlp#setlines(s:itemtype)
en
let s:force = 1
cal s:BuildPrompt(1)
@ -694,9 +688,9 @@ fu! s:ToggleType(dir)
if s:byfname && !s:ispathitem() | let s:byfname = 0 | en
unl! g:ctrlp_nolimit
if has('syntax') && exists('g:syntax_on')
cal s:syntax()
cal ctrlp#syntax()
en
cal s:SetLines(s:itemtype)
cal ctrlp#setlines(s:itemtype)
cal s:PrtSwitcher()
endf
@ -771,12 +765,12 @@ fu! s:SpecInputs(str)
let [str, type] = [a:str, s:type()]
if str == '..' && type =~ '\v^(0|dir)$'
cal s:parentdir(getcwd())
cal s:SetLines(s:itemtype)
cal ctrlp#setlines(s:itemtype)
cal s:PrtClear()
retu 1
elsei str =~ '^[\/]$' && type =~ '\v^(0|dir)$'
cal s:SetWD(2, 0)
cal s:SetLines(s:itemtype)
cal ctrlp#setlines(s:itemtype)
cal s:PrtClear()
retu 1
elsei str == '?'
@ -1171,7 +1165,7 @@ fu! ctrlp#setlcdir()
en
endf
" Highlighting {{{2
fu! s:syntax()
fu! ctrlp#syntax()
for [ke, va] in items(s:hlgrps) | if !hlexists('CtrlP'.ke)
exe 'hi link CtrlP'.ke va
en | endfo
@ -1263,37 +1257,21 @@ fu! s:buftab(bufnr, md)
let buflist = tabpagebuflist(tabnr)
if index(buflist, a:bufnr) >= 0
for winnr in range(1, tabpagewinnr(tabnr, '$'))
if buflist[winnr - 1] == a:bufnr
retu [tabnr, winnr]
en
if buflist[winnr - 1] == a:bufnr | retu [tabnr, winnr] | en
endfo
en
endfo
retu [0, 0]
endf
fu! s:normbuf()
let winnrs = []
for each in range(1, winnr('$'))
let bufnr = winbufnr(each)
if getbufvar(bufnr, '&bl') && empty(getbufvar(bufnr, '&bt'))
\ && getbufvar(bufnr, '&ma')
cal add(winnrs, each)
en
endfo
retu winnrs
endf
fu! ctrlp#normcmd(cmd, ...)
if s:nosplit()
retu a:cmd
en
let norwins = s:normbuf()
if s:nosplit() | retu a:cmd | en
let norwins = filter(range(1, winnr('$')),
\ 'empty(getbufvar(winbufnr(v:val), "&bt"))')
for each in norwins
let bufnr = winbufnr(each)
if empty(bufname(bufnr)) && empty(getbufvar(bufnr, '&ft'))
let fstemp = each
brea
let fstemp = each | brea
en
endfo
let norwin = empty(norwins) ? 0 : norwins[0]
@ -1307,7 +1285,7 @@ fu! ctrlp#normcmd(cmd, ...)
endf
fu! s:nosplit()
retu !empty(s:nosplit) && match([bufname('%'), &l:ft], s:nosplit) >= 0
retu !empty(s:nosplit) && match([bufname('%'), &l:ft, &l:bt], s:nosplit) >= 0
endf
fu! s:setupblank()
@ -1515,20 +1493,6 @@ fu! s:onexit()
en
endf
fu! ctrlp#allbufs()
let bufs = []
for each in range(1, bufnr('$'))
if getbufvar(each, '&bl')
let bufname = bufname(each)
if strlen(bufname) && bufname != 'ControlP'
cal add(bufs, fnamemodify(bufname, ':p'))
en
en
endfo
cal filter(bufs, 'filereadable(v:val)')
retu bufs
endf
fu! ctrlp#exit()
cal s:PrtExit()
endf
@ -1536,17 +1500,13 @@ endf
fu! ctrlp#prtclear()
cal s:PrtClear()
endf
fu! ctrlp#setlines(type)
cal s:SetLines(a:type)
endf
"}}}1
" * Initialization {{{1
fu! s:SetLines(type)
fu! ctrlp#setlines(type)
let s:itemtype = a:type
let types = [
\ 's:Files()',
\ 's:Buffers()',
\ 'ctrlp#files()',
\ 'ctrlp#buffers()',
\ 'ctrlp#mrufiles#list(-1)',
\ ]
if exists('g:ctrlp_ext_vars')
@ -1562,9 +1522,9 @@ fu! ctrlp#init(type, ...)
cal s:SetWD(a:0 ? a:1 : '')
cal s:MapKeys()
if has('syntax') && exists('g:syntax_on')
cal s:syntax()
cal ctrlp#syntax()
en
cal s:SetLines(a:type)
cal ctrlp#setlines(a:type)
cal s:BuildPrompt(1)
endf
if has('autocmd') "{{{1

View File

@ -198,17 +198,20 @@ fu! s:parseline(line)
endf
" Public {{{1
fu! ctrlp#buffertag#init(fname)
let fname = exists('s:bufname') ? s:bufname : a:fname
let bufs = exists('s:btmode') && s:btmode ? ctrlp#allbufs() : [fname]
let bufs = exists('s:btmode') && s:btmode
\ ? filter(ctrlp#buffers(), 'filereadable(v:val)')
\ : [exists('s:bufname') ? s:bufname : a:fname]
let lines = []
for each in bufs
let tftype = get(split(getbufvar(each, '&ft'), '\.'), 0, '')
cal extend(lines, s:process(each, tftype))
endfo
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
if has('syntax') && exists('g:syntax_on')
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
retu lines
endf

View File

@ -31,30 +31,31 @@ 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)
" Public {{{1
fu! ctrlp#line#init()
let [bufs, lines] = [ctrlp#allbufs(), []]
let [bufs, lines] = [filter(ctrlp#buffers(), 'filereadable(v:val)'), []]
for each in bufs
let from_file = readfile(each)
let [fnamet, from_file] = [fnamemodify(each, ':t'), readfile(each)]
cal map(from_file, 'tr(v:val, '' '', '' '')')
let [id, len_ff, bufnr] = [1, len(from_file), bufnr('^'.each.'$')]
wh id <= len_ff
let from_file[id-1] .= ' #:'.bufnr.':'.id
let from_file[id-1] .= ' |'.fnamet.'|'.bufnr.':'.id.'|'
let id += 1
endw
cal filter(from_file, 'v:val !~ ''^\s*\t#:\d\+:\d\+$''')
cal filter(from_file, 'v:val !~ ''^\s*\t|[^|]\+|\d\+:\d\+|$''')
cal extend(lines, from_file)
endfo
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
if has('syntax') && exists('g:syntax_on')
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
retu lines
endf
fu! ctrlp#line#accept(mode, str)
let info = get(split(a:str, '\t#:\ze\d\+:\d\+$'), 1, 0)
let bufnr = str2nr(get(split(info, ':'), 0, 0))
let linenr = get(split(info, ':'), 1, 0)
if bufnr
let info = matchlist(a:str, '\t|[^|]\+|\(\d\+\):\(\d\+\)|$')
let [bufnr, linenr] = [str2nr(get(info, 1)), get(info, 2)]
if bufnr > 0
cal ctrlp#acceptfile(a:mode, fnamemodify(bufname(bufnr), ':p'), linenr)
en
endf

View File

@ -30,10 +30,12 @@ endf
" Public {{{1
fu! ctrlp#quickfix#init()
let g:ctrlp_nolimit = 1
if !hlexists('CtrlPqfLineCol')
hi link CtrlPqfLineCol Search
if has('syntax') && exists('g:syntax_on')
if !hlexists('CtrlPqfLineCol')
hi link CtrlPqfLineCol Search
en
sy match CtrlPqfLineCol '|\zs\d\+:\d\+\ze|'
en
sy match CtrlPqfLineCol '|\zs\d\+:\d\+\ze|'
retu map(getqflist(), 's:lineout(v:val)')
endf

View File

@ -65,10 +65,12 @@ fu! ctrlp#tag#init(tagfiles)
let alltags = s:filter(ctrlp#utils#readfile(each))
cal extend(g:ctrlp_alltags, alltags)
endfo
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
if has('syntax') && exists('g:syntax_on')
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
retu g:ctrlp_alltags
endf

View File

@ -92,8 +92,8 @@ When opening a file with <cr>, |CtrlP| avoids opening it in windows created by
plugins, help and quickfix. Use this to setup some exceptions: >
let g:ctrlp_reuse_window = 'netrw'
<
Acceptable values are partial names or filetypes of the special buffers. Use
|regexp| to specify the pattern.
Acceptable values are partial name, filetype or buftype of the special buffers.
Use |regexp| to specify the pattern.
Example: >
let g:ctrlp_reuse_window = 'netrw\|help\|quickfix'
<