Include [No Name] buffers

Closes #295
This commit is contained in:
Kien N 2013-03-26 11:10:15 +07:00
parent 50e494d635
commit 287b9c12aa
5 changed files with 65 additions and 18 deletions

View File

@ -415,8 +415,19 @@ endf
" - Buffers {{{1
fu! ctrlp#buffers(...)
let ids = sort(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
\ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))'), 's:compmreb')
retu a:0 && a:1 == 'id' ? ids : map(ids, 'fnamemodify(bufname(v:val), ":.")')
\ .' && getbufvar(v:val, "&bl")'), 's:compmreb')
if a:0 && a:1 == 'id'
retu ids
el
let bufs = [[], []]
for id in ids
let bname = bufname(id)
let ebname = bname == ''
let fname = fnamemodify(ebname ? '['.id.'*No Name]' : bname, ':.')
cal add(bufs[ebname], fname)
endfo
retu bufs[0] + bufs[1]
en
endf
" * MatchedItems() {{{1
fu! s:MatchIt(items, pat, limit, exc)
@ -927,9 +938,20 @@ fu! s:SetWD(args)
endf
" * AcceptSelection() {{{1
fu! ctrlp#acceptfile(mode, line, ...)
let [md, filpath] = [a:mode, fnamemodify(a:line, ':p')]
let [md, useb] = [a:mode, 0]
if !type(a:line)
let [filpath, bufnr, useb] = [a:line, a:line, 1]
el
let filpath = fnamemodify(a:line, ':p')
if s:nonamecond(a:line, filpath)
let bufnr = str2nr(matchstr(a:line, '[\/]\?\[\zs\d\+\ze\*No Name\]$'))
let [filpath, useb] = [bufnr, 1]
el
let bufnr = bufnr('^'.filpath.'$')
en
en
cal s:PrtExit()
let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()]
let tail = s:tail()
let j2l = a:0 ? a:1 : matchstr(tail, '^ +\zs\d\+$')
if ( s:jmptobuf =~ md || ( s:jmptobuf && md =~ '[et]' ) ) && bufnr > 0
\ && !( md == 'e' && bufnr == bufnr('%') )
@ -949,7 +971,7 @@ fu! ctrlp#acceptfile(mode, line, ...)
if j2l | cal ctrlp#j2l(j2l) | en
el
" Determine the command to use
let useb = bufnr > 0 && buflisted(bufnr) && empty(tail)
let useb = bufnr > 0 && buflisted(bufnr) && ( empty(tail) || useb )
let cmd =
\ md == 't' || s:splitwin == 1 ? ( useb ? 'tab sb' : 'tabe' ) :
\ md == 'h' || s:splitwin == 2 ? ( useb ? 'sb' : 'new' ) :
@ -1247,6 +1269,12 @@ fu! s:shortest(lens)
endf
fu! s:mixedsort(...)
if s:itemtype == 1
let pat = '[\/]\?\[\d\+\*No Name\]$'
if a:1 =~# pat && a:2 =~# pat | retu 0
elsei a:1 =~# pat | retu 1
elsei a:2 =~# pat | retu -1 | en
en
let [cln, cml] = [ctrlp#complen(a:1, a:2), s:compmatlen(a:1, a:2)]
if s:ispath
let ms = []
@ -1330,11 +1358,14 @@ endf
fu! s:formatline(str)
let str = a:str
if s:itemtype == 1
let bfnr = bufnr('^'.fnamemodify(str, ':p').'$')
let idc = ( bfnr == bufnr('#') ? '#' : '' )
\ . ( getbufvar(bfnr, '&ma') ? '' : '-' )
\ . ( getbufvar(bfnr, '&ro') ? '=' : '' )
\ . ( getbufvar(bfnr, '&mod') ? '+' : '' )
let filpath = fnamemodify(str, ':p')
let bufnr = s:nonamecond(str, filpath)
\ ? str2nr(matchstr(str, '[\/]\?\[\zs\d\+\ze\*No Name\]$'))
\ : bufnr('^'.filpath.'$')
let idc = ( bufnr == bufnr('#') ? '#' : '' )
\ . ( getbufvar(bufnr, '&ma') ? '' : '-' )
\ . ( getbufvar(bufnr, '&ro') ? '=' : '' )
\ . ( getbufvar(bufnr, '&mod') ? '+' : '' )
let str .= idc != '' ? ' '.idc : ''
en
let cond = s:ispath && ( s:winw - 4 ) < s:strwidth(str)
@ -1613,6 +1644,11 @@ fu! s:bufwins(bufnr)
retu winns
endf
fu! s:nonamecond(str, filpath)
retu a:str =~ '[\/]\?\[\d\+\*No Name\]$' && !filereadable(a:filpath)
\ && bufnr('^'.a:filpath.'$') < 1
endf
fu! ctrlp#normcmd(cmd, ...)
if a:0 < 2 && s:nosplit() | retu a:cmd | en
let norwins = filter(range(1, winnr('$')),
@ -1878,11 +1914,13 @@ endf
" Entering & Exiting {{{2
fu! s:getenv()
let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
let [s:crword, s:crnbword] = [expand('<cword>', 1), expand('<cWORD>', 1)]
let [s:crgfile, s:crline] = [expand('<cfile>', 1), getline('.')]
let [s:winh, s:crcursor] = [min([s:mxheight, &lines]), getpos('.')]
let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()]
let s:crfile = bufname('%') == ''
\ ? '['.s:crbufnr.'*No Name]' : expand('%:p', 1)
let s:crfpath = expand('%:p:h', 1)
let s:mrbs = ctrlp#mrufiles#bufs()
endf

View File

@ -238,7 +238,7 @@ fu! ctrlp#buffertag#accept(mode, str)
\ '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|\s(.+)$')
let bufnr = str2nr(get(vals, 1))
if bufnr
cal ctrlp#acceptfile(a:mode, bufname(bufnr))
cal ctrlp#acceptfile(a:mode, bufnr)
exe 'norm!' str2nr(get(vals, 2, line('.'))).'G'
cal s:chknearby('\V\C'.get(vals, 3, ''))
sil! norm! zvzz

View File

@ -59,7 +59,8 @@ fu! ctrlp#changes#init(original_bufnr, bufnr)
let [swb, &swb] = [&swb, '']
let lines = []
for each in bufs
let fnamet = fnamemodify(bufname(each), ':t')
let bname = bufname(each)
let fnamet = fnamemodify(bname == '' ? '[No Name]' : bname, ':t')
cal extend(lines, s:process(s:changelist(each), each, fnamet))
endfo
sil! exe 'noa hid b' a:original_bufnr
@ -73,7 +74,7 @@ fu! ctrlp#changes#accept(mode, str)
let info = matchlist(a:str, '\t|\(\d\+\):[^|]\+|\(\d\+\):\(\d\+\)|$')
let bufnr = str2nr(get(info, 1))
if bufnr
cal ctrlp#acceptfile(a:mode, bufname(bufnr))
cal ctrlp#acceptfile(a:mode, bufnr)
cal cursor(get(info, 2), get(info, 3))
sil! norm! zvzz
en

View File

@ -33,9 +33,12 @@ fu! ctrlp#line#init()
let [bufs, lines] = [ctrlp#buffers('id'), []]
for bufnr in bufs
let [lfb, bufn] = [getbufline(bufnr, 1, '$'), bufname(bufnr)]
let lfb = lfb == [] ? ctrlp#utils#readfile(fnamemodify(bufn, ':p')) : lfb
if lfb == [] && bufn != ''
let lfb = ctrlp#utils#readfile(fnamemodify(bufn, ':p'))
en
cal map(lfb, 'tr(v:val, '' '', '' '')')
let [linenr, len_lfb, buft] = [1, len(lfb), fnamemodify(bufn, ':t')]
let [linenr, len_lfb] = [1, len(lfb)]
let buft = bufn == '' ? '[No Name]' : fnamemodify(bufn, ':t')
wh linenr <= len_lfb
let lfb[linenr - 1] .= ' |'.buft.'|'.bufnr.':'.linenr.'|'
let linenr += 1
@ -50,7 +53,7 @@ fu! ctrlp#line#accept(mode, str)
let info = matchlist(a:str, '\t|[^|]\+|\(\d\+\):\(\d\+\)|$')
let bufnr = str2nr(get(info, 1))
if bufnr
cal ctrlp#acceptfile(a:mode, bufname(bufnr), get(info, 2))
cal ctrlp#acceptfile(a:mode, bufnr, get(info, 2))
en
endf

View File

@ -41,7 +41,11 @@ fu! s:getnewmix(cwd, clim)
if exists('+ssl') && &ssl
cal map(mrufs, 'tr(v:val, "\\", "/")')
en
let bufs = map(ctrlp#buffers('id'), 'fnamemodify(bufname(v:val), ":p")')
let allbufs = map(ctrlp#buffers(), 'fnamemodify(v:val, ":p")')
let [bufs, ubufs] = [[], []]
for each in allbufs
cal add(filereadable(each) ? bufs : ubufs, each)
endfo
let mrufs = bufs + filter(mrufs, 'index(bufs, v:val) < 0')
if len(mrufs) > len(g:ctrlp_lines)
cal filter(mrufs, 'stridx(v:val, a:cwd)')
@ -53,6 +57,7 @@ fu! s:getnewmix(cwd, clim)
if id >= 0 | cal remove(g:ctrlp_lines, id) | en
endfo
en
let mrufs += ubufs
cal map(mrufs, 'fnamemodify(v:val, ":.")')
let g:ctrlp_lines = len(mrufs) > len(g:ctrlp_lines)
\ ? g:ctrlp_lines + mrufs : mrufs + g:ctrlp_lines