From 27e2375bc051e4b97ad0c49edea32878205f63aa Mon Sep 17 00:00:00 2001 From: Kien N Date: Thu, 18 Apr 2013 16:00:56 +0700 Subject: [PATCH] Allow :CtrlPLine to take a bufname argument Closes #396 --- autoload/ctrlp/buffertag.vim | 4 +++- autoload/ctrlp/changes.vim | 4 +++- autoload/ctrlp/line.vim | 15 +++++++++++---- doc/ctrlp.txt | 4 ++-- plugin/ctrlp.vim | 4 +++- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/autoload/ctrlp/buffertag.vim b/autoload/ctrlp/buffertag.vim index aa67afa..bc3662a 100644 --- a/autoload/ctrlp/buffertag.vim +++ b/autoload/ctrlp/buffertag.vim @@ -248,7 +248,9 @@ endf fu! ctrlp#buffertag#cmd(mode, ...) let s:btmode = a:mode 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 retu s:id endf diff --git a/autoload/ctrlp/changes.vim b/autoload/ctrlp/changes.vim index 67a299c..313d8c2 100644 --- a/autoload/ctrlp/changes.vim +++ b/autoload/ctrlp/changes.vim @@ -83,7 +83,9 @@ endf fu! ctrlp#changes#cmd(mode, ...) let s:clmode = a:mode 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 retu s:id endf diff --git a/autoload/ctrlp/line.vim b/autoload/ctrlp/line.vim index e82bf1b..5bec47e 100644 --- a/autoload/ctrlp/line.vim +++ b/autoload/ctrlp/line.vim @@ -11,7 +11,7 @@ en let g:loaded_ctrlp_line = 1 cal add(g:ctrlp_ext_vars, { - \ 'init': 'ctrlp#line#init()', + \ 'init': 'ctrlp#line#init(s:crbufnr)', \ 'accept': 'ctrlp#line#accept', \ 'lname': 'lines', \ 'sname': 'lns', @@ -29,8 +29,9 @@ fu! s:syntax() en endf " Public {{{1 -fu! ctrlp#line#init() - let [bufs, lines] = [ctrlp#buffers('id'), []] +fu! ctrlp#line#init(bufnr) + 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 let [lfb, bufn] = [getbufline(bufnr, 1, '$'), bufname(bufnr)] if lfb == [] && bufn != '' @@ -57,7 +58,13 @@ fu! ctrlp#line#accept(mode, str) en 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 endf "}}} diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 684e51c..808be60 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -1106,8 +1106,8 @@ Available extensions:~ *:CtrlPLine* * Line mode:~ - Name: 'line' - - Command: ":CtrlPLine" - - Search for a line in all listed buffers. + - Command: ":CtrlPLine [buffer]" + - Search for a line in all listed buffers or in the specified [buffer]. *:CtrlPChange* *:CtrlPChangeAll* diff --git a/plugin/ctrlp.vim b/plugin/ctrlp.vim index b6f9a27..c7b8fa3 100644 --- a/plugin/ctrlp.vim +++ b/plugin/ctrlp.vim @@ -51,7 +51,9 @@ com! -n=? -com=buffer CtrlPBufTag com! -bar CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1)) com! -bar CtrlPRTS cal ctrlp#init(ctrlp#rtscript#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, )) com! -n=? -com=buffer CtrlPChange \ cal ctrlp#init(ctrlp#changes#cmd(0, ))