Allow :CtrlPLine to take a bufname argument

Closes #396
This commit is contained in:
Kien N 2013-04-18 16:00:56 +07:00
parent e927848400
commit 27e2375bc0
5 changed files with 22 additions and 9 deletions

View File

@ -248,7 +248,9 @@ endf
fu! ctrlp#buffertag#cmd(mode, ...) fu! ctrlp#buffertag#cmd(mode, ...)
let s:btmode = a:mode let s:btmode = a:mode
if a:0 && !empty(a:1) if a:0 && !empty(a:1)
let s:bufname = fnamemodify(a:1, ':p') let s:btmode = 0
let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1
let s:bufname = fnamemodify(bname, ':p')
en en
retu s:id retu s:id
endf endf

View File

@ -83,7 +83,9 @@ endf
fu! ctrlp#changes#cmd(mode, ...) fu! ctrlp#changes#cmd(mode, ...)
let s:clmode = a:mode let s:clmode = a:mode
if a:0 && !empty(a:1) if a:0 && !empty(a:1)
let s:bufnr = bufnr('^'.fnamemodify(a:1, ':p').'$') let s:clmode = 0
let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1
let s:bufnr = bufnr('^'.fnamemodify(bname, ':p').'$')
en en
retu s:id retu s:id
endf endf

View File

@ -11,7 +11,7 @@ en
let g:loaded_ctrlp_line = 1 let g:loaded_ctrlp_line = 1
cal add(g:ctrlp_ext_vars, { cal add(g:ctrlp_ext_vars, {
\ 'init': 'ctrlp#line#init()', \ 'init': 'ctrlp#line#init(s:crbufnr)',
\ 'accept': 'ctrlp#line#accept', \ 'accept': 'ctrlp#line#accept',
\ 'lname': 'lines', \ 'lname': 'lines',
\ 'sname': 'lns', \ 'sname': 'lns',
@ -29,8 +29,9 @@ fu! s:syntax()
en en
endf endf
" Public {{{1 " Public {{{1
fu! ctrlp#line#init() fu! ctrlp#line#init(bufnr)
let [bufs, lines] = [ctrlp#buffers('id'), []] let [lines, bufnr] = [[], exists('s:bufnr') ? s:bufnr : a:bufnr]
let bufs = exists('s:lnmode') && s:lnmode ? ctrlp#buffers('id') : [bufnr]
for bufnr in bufs for bufnr in bufs
let [lfb, bufn] = [getbufline(bufnr, 1, '$'), bufname(bufnr)] let [lfb, bufn] = [getbufline(bufnr, 1, '$'), bufname(bufnr)]
if lfb == [] && bufn != '' if lfb == [] && bufn != ''
@ -57,7 +58,13 @@ fu! ctrlp#line#accept(mode, str)
en en
endf endf
fu! ctrlp#line#id() fu! ctrlp#line#cmd(mode, ...)
let s:lnmode = a:mode
if a:0 && !empty(a:1)
let s:lnmode = 0
let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1
let s:bufnr = bufnr('^'.fnamemodify(bname, ':p').'$')
en
retu s:id retu s:id
endf endf
"}}} "}}}

View File

@ -1106,8 +1106,8 @@ Available extensions:~
*:CtrlPLine* *:CtrlPLine*
* Line mode:~ * Line mode:~
- Name: 'line' - Name: 'line'
- Command: ":CtrlPLine" - Command: ":CtrlPLine [buffer]"
- Search for a line in all listed buffers. - Search for a line in all listed buffers or in the specified [buffer].
*:CtrlPChange* *:CtrlPChange*
*:CtrlPChangeAll* *:CtrlPChangeAll*

View File

@ -51,7 +51,9 @@ com! -n=? -com=buffer CtrlPBufTag
com! -bar CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1)) com! -bar CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1))
com! -bar CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id()) com! -bar CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id())
com! -bar CtrlPUndo cal ctrlp#init(ctrlp#undo#id()) com! -bar CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
com! -bar CtrlPLine cal ctrlp#init(ctrlp#line#id())
com! -n=? -com=buffer CtrlPLine
\ cal ctrlp#init(ctrlp#line#cmd(1, <q-args>))
com! -n=? -com=buffer CtrlPChange com! -n=? -com=buffer CtrlPChange
\ cal ctrlp#init(ctrlp#changes#cmd(0, <q-args>)) \ cal ctrlp#init(ctrlp#changes#cmd(0, <q-args>))