Fix :CtrlPLine and :CtrlPBufTagAll

This commit is contained in:
Kien N 2012-02-12 18:50:15 +07:00
parent 0110b7b129
commit 93cb20dbfb
5 changed files with 55 additions and 47 deletions

View File

@ -183,7 +183,7 @@ fu! s:Close()
exe s:winres[0] exe s:winres[0]
en en
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 \ s:winh g:ctrlp_nolimit
cal ctrlp#recordhist() cal ctrlp#recordhist()
cal s:onexit() cal s:onexit()
if exists('g:ctrlp_log') && g:ctrlp_log if exists('g:ctrlp_log') && g:ctrlp_log
@ -193,12 +193,10 @@ fu! s:Close()
endf endf
" * Clear caches {{{1 " * Clear caches {{{1
fu! ctrlp#clr(...) fu! ctrlp#clr(...)
exe 'let g:ctrlp_new'.( exists('a:1') ? a:1 : 'cache' ).' = 1' exe 'let g:ctrlp_new'.( a:0 ? a:1 : 'cache' ).' = 1'
endf endf
fu! ctrlp#clra(...) fu! ctrlp#clra()
if !exists('a:1') && ( has('dialog_gui') || has('dialog_con') ) &&
\ confirm("Delete all cache files?", "&OK\n&Cancel") != 1 | retu | en
let cache_dir = ctrlp#utils#cachedir() let cache_dir = ctrlp#utils#cachedir()
if isdirectory(cache_dir) if isdirectory(cache_dir)
let cache_files = split(s:glbpath(cache_dir, '**', 1), "\n") let cache_files = split(s:glbpath(cache_dir, '**', 1), "\n")
@ -208,9 +206,7 @@ fu! ctrlp#clra(...)
cal ctrlp#clr() cal ctrlp#clr()
endf endf
fu! ctrlp#reset(...) fu! ctrlp#reset()
if !exists('a:1') && ( has('dialog_gui') || has('dialog_con') ) &&
\ confirm("Reset and apply new options?", "&OK\n&Cancel") != 1 | retu | en
cal s:opts() cal s:opts()
cal ctrlp#utils#opts() cal ctrlp#utils#opts()
cal ctrlp#mrufiles#opts() cal ctrlp#mrufiles#opts()
@ -365,7 +361,7 @@ endf
fu! s:Render(lines, pat) fu! s:Render(lines, pat)
let lines = a:lines let lines = a:lines
" Setup the match window " Setup the match window
let s:height = min([len(lines), s:mxheight]) let s:height = min([len(lines), s:winh])
sil! exe '%d _ | res' s:height sil! exe '%d _ | res' s:height
" Print the new items " Print the new items
if empty(lines) if empty(lines)
@ -410,7 +406,7 @@ fu! s:Update(str)
en en
let pat = s:SplitPattern(str) let pat = s:SplitPattern(str)
let lines = exists('g:ctrlp_nolimit') && empty(str) ? copy(g:ctrlp_lines) let lines = exists('g:ctrlp_nolimit') && empty(str) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, pat, s:mxheight) \ : s:MatchedItems(g:ctrlp_lines, pat, s:winh)
cal s:Render(lines, pat) cal s:Render(lines, pat)
endf endf
@ -432,7 +428,7 @@ fu! s:BuildPrompt(upd, ...)
en en
sil! cal ctrlp#statusline() sil! cal ctrlp#statusline()
" Toggling " Toggling
let [hiactive, hicursor, base] = exists('a:1') && !a:1 let [hiactive, hicursor, base] = a:0 && !a:1
\ ? ['CtrlPPrtBase', 'CtrlPPrtBase', tr(base, '>', '-')] \ ? ['CtrlPPrtBase', 'CtrlPPrtBase', tr(base, '>', '-')]
\ : ['CtrlPPrtText', 'CtrlPPrtCursor', base] \ : ['CtrlPPrtText', 'CtrlPPrtCursor', base]
let hibase = 'CtrlPPrtBase' let hibase = 'CtrlPPrtBase'
@ -443,7 +439,7 @@ fu! s:BuildPrompt(upd, ...)
\ | echoh' hicursor '| echon "'.prt[1].'" \ | echoh' hicursor '| echon "'.prt[1].'"
\ | echoh' hiactive '| echon "'.prt[2].'" | echoh None' \ | echoh' hiactive '| echon "'.prt[2].'" | echoh None'
" Append the cursor at the end " Append the cursor at the end
if empty(prt[1]) && ( !exists('a:1') || ( exists('a:1') && a:1 ) ) if empty(prt[1]) && !( a:0 && !a:1 )
exe 'echoh' hibase '| echon "_" | echoh None' exe 'echoh' hibase '| echon "_" | echoh None'
en en
endf endf
@ -549,7 +545,7 @@ endf
fu! s:PrtSelectJump(char, ...) fu! s:PrtSelectJump(char, ...)
let lines = copy(s:matched) let lines = copy(s:matched)
if exists('a:1') if a:0
cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]') cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]')
en en
" Cycle through matches, use s:jmpchr to store last jump " Cycle through matches, use s:jmpchr to store last jump
@ -619,15 +615,16 @@ endf
" * MapKeys() {{{1 " * MapKeys() {{{1
fu! s:MapKeys(...) fu! s:MapKeys(...)
" Normal keys " Normal keys
let pfunc = exists('a:1') && !a:1 ? 'PrtSelectJump' : 'PrtAdd' let pfunc = a:0 && !a:1 ? 'PrtSelectJump' : 'PrtAdd'
let dojmp = s:byfname && pfunc == 'PrtSelectJump' ? ', 1' : '' let dojmp = s:byfname && pfunc == 'PrtSelectJump' ? ', 1' : ''
for each in range(32, 126) for each in range(32, 126)
let cmd = "nn \<buffer> \<silent> \<char-%d> :\<c-u>cal \<SID>%s(\"%s\"%s)\<cr>" let cmd = "nn \<buffer> \<silent> \<char-%d> :\<c-u>cal \<SID>%s(\"%s\"%s)\<cr>"
exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp) exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp)
endfo endfo
if exists('a:2') | retu | en
" Special keys " Special keys
cal call('s:MapSpecs', exists('a:1') && !a:1 ? [1] : []) if a:0 < 2
cal call('s:MapSpecs', a:0 && !a:1 ? [1] : [])
en
endf endf
fu! s:MapSpecs(...) fu! s:MapSpecs(...)
@ -638,7 +635,7 @@ fu! s:MapSpecs(...)
exe s:lcmap.' <esc>['.each exe s:lcmap.' <esc>['.each
endfo endfo
en en
if exists('a:1') if a:0
for ke in s:prtunmaps | for kp in s:prtmaps[ke] for ke in s:prtunmaps | for kp in s:prtmaps[ke]
exe s:lcmap kp '<Nop>' exe s:lcmap kp '<Nop>'
endfo | endfo endfo | endfo
@ -691,12 +688,12 @@ fu! s:PrtSwitcher()
endf endf
fu! s:SetWD(...) "{{{1 fu! s:SetWD(...) "{{{1
let pathmode = s:pathmode let pathmode = s:pathmode
if exists('a:1') && strlen(a:1) | if type(a:1) if a:0 && strlen(a:1) | if type(a:1)
cal ctrlp#setdir(a:1) | retu cal ctrlp#setdir(a:1) | retu
el el
let pathmode = a:1 let pathmode = a:1
en | en en | en
if !exists('a:2') if a:0 < 2
if match(s:crfile, '^\<.\+\>://.*') >= 0 || !pathmode | retu | en if match(s:crfile, '^\<.\+\>://.*') >= 0 || !pathmode | retu | en
if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
cal ctrlp#setdir(s:crfpath) cal ctrlp#setdir(s:crfpath)
@ -717,10 +714,10 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
let [md, filpath] = [a:mode, fnamemodify(a:matchstr, ':p')] let [md, filpath] = [a:mode, fnamemodify(a:matchstr, ':p')]
cal s:PrtExit() cal s:PrtExit()
let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()] let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()]
let j2l = a:0 ? a:1 : str2nr(matchstr(tail, '^ +\D*\zs\d\+\ze\D*'))
if s:jmptobuf && bufnr > 0 && md =~ 'e\|t' if s:jmptobuf && bufnr > 0 && md =~ 'e\|t'
let [jmpb, bufwinnr] = [1, bufwinnr(bufnr)] let [jmpb, bufwinnr] = [1, bufwinnr(bufnr)]
let buftab = s:jmptobuf > 1 ? s:buftab(bufnr, md) : [0, 0] let buftab = s:jmptobuf > 1 ? s:buftab(bufnr, md) : [0, 0]
let j2l = a:0 ? a:1 : str2nr(matchstr(tail, '^ +\D*\zs\d\+\ze\D*'))
en en
" Switch to existing buffer or open new one " Switch to existing buffer or open new one
if exists('jmpb') && bufwinnr > 0 && md != 't' if exists('jmpb') && bufwinnr > 0 && md != 't'
@ -739,12 +736,16 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
\ md == 'v' || s:splitwin == 3 ? ( useb ? 'vert sb' : 'vne' ) : \ md == 'v' || s:splitwin == 3 ? ( useb ? 'vert sb' : 'vne' ) :
\ call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e']) \ call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e'])
" Reset &switchbuf option " Reset &switchbuf option
if useb
let [swb, &swb] = [&swb, ''] let [swb, &swb] = [&swb, '']
en
" Open new window/buffer " Open new window/buffer
let fid = useb ? bufnr : filpath let args = [cmd, useb ? bufnr : filpath, a:0 ? ' +'.a:1 : tail, useb, j2l]
cal call('s:openfile', a:0 ? [cmd, fid, ' +'.a:1] : [cmd, fid]) cal call('s:openfile', args)
if useb
let &swb = swb let &swb = swb
en en
en
endf endf
fu! s:SpecInputs(str) fu! s:SpecInputs(str)
@ -805,7 +806,7 @@ fu! s:CreateNewFile(...) "{{{1
let optyp = str | en | el | let optyp = fname let optyp = str | en | el | let optyp = fname
en en
if !exists('optyp') | retu | en if !exists('optyp') | retu | en
let filpath = fnamemodify(optyp, ':p') let [filpath, tail] = [fnamemodify(optyp, ':p'), s:tail()]
cal s:insertcache(str) cal s:insertcache(str)
cal s:PrtExit() cal s:PrtExit()
let cmd = md == 'r' ? ctrlp#normcmd('e') : let cmd = md == 'r' ? ctrlp#normcmd('e') :
@ -813,7 +814,7 @@ fu! s:CreateNewFile(...) "{{{1
\ s:newfop =~ '2\|h' || ( a:0 && a:1 == 'h' ) || md == 'h' ? 'new' : \ s:newfop =~ '2\|h' || ( a:0 && a:1 == 'h' ) || md == 'h' ? 'new' :
\ s:newfop =~ '3\|v' || ( a:0 && a:1 == 'v' ) || md == 'v' ? 'vne' : \ s:newfop =~ '3\|v' || ( a:0 && a:1 == 'v' ) || md == 'v' ? 'vne' :
\ ctrlp#normcmd('e') \ ctrlp#normcmd('e')
cal s:openfile(cmd, filpath) cal s:openfile(cmd, filpath, tail)
endf endf
" * OpenMulti() {{{1 " * OpenMulti() {{{1
fu! s:MarkToOpen() fu! s:MarkToOpen()
@ -860,7 +861,8 @@ fu! s:OpenMulti()
cal s:sanstail(join(s:prompt, '')) cal s:sanstail(join(s:prompt, ''))
cal s:PrtExit() cal s:PrtExit()
" Move the cursor to a reusable window " Move the cursor to a reusable window
let emptytail = empty(s:tail()) let tail = s:tail()
let emptytail = empty(tail)
let useb = bufnr('^'.mkd[0].'$') > 0 && emptytail let useb = bufnr('^'.mkd[0].'$') > 0 && emptytail
let fst = call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e']) let fst = call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e'])
" Check if it's a replaceable buffer " Check if it's a replaceable buffer
@ -876,7 +878,7 @@ fu! s:OpenMulti()
let snd = md != '' && has_key(cmds, md) let snd = md != '' && has_key(cmds, md)
\ ? ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' ) \ ? ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' )
let fid = useb ? bufnr : va let fid = useb ? bufnr : va
cal s:openfile(ic == 1 && ( ucr == 'r' || repabl ) ? fst : snd, fid) cal s:openfile(ic == 1 && ( ucr == 'r' || repabl ) ? fst : snd, fid, tail)
if ( nr != '' && nr > 1 && nr < ic ) || ( nr == '' && ic > 1 ) if ( nr != '' && nr > 1 && nr < ic ) || ( nr == '' && ic > 1 )
sil! hid clo! | el | let ic += 1 sil! hid clo! | el | let ic += 1
en en
@ -919,9 +921,9 @@ endf
fu! s:matchlens(str, pat, ...) fu! s:matchlens(str, pat, ...)
if empty(a:pat) || index(['^', '$'], a:pat) >= 0 | retu {} | en if empty(a:pat) || index(['^', '$'], a:pat) >= 0 | retu {} | en
let st = exists('a:1') ? a:1 : 0 let st = a:0 ? a:1 : 0
let lens = exists('a:2') ? a:2 : {} let lens = a:0 >= 2 ? a:2 : {}
let nr = exists('a:3') ? a:3 : 0 let nr = a:0 >= 3 ? a:3 : 0
if nr > 20 | retu {} | en if nr > 20 | retu {} | en
if match(a:str, a:pat, st) >= 0 if match(a:str, a:pat, st) >= 0
let [mst, mnd] = [matchstr(a:str, a:pat, st), matchend(a:str, a:pat, st)] let [mst, mnd] = [matchstr(a:str, a:pat, st), matchend(a:str, a:pat, st)]
@ -1120,8 +1122,8 @@ fu! ctrlp#fnesc(path)
endf endf
fu! ctrlp#setdir(path, ...) fu! ctrlp#setdir(path, ...)
let cmd = exists('a:1') ? a:1 : 'lc!' let cmd = a:0 ? a:1 : 'lc!'
sil! exe cmd.' '.ctrlp#fnesc(a:path) sil! exe cmd ctrlp#fnesc(a:path)
endf endf
" Highlighting {{{2 " Highlighting {{{2
fu! s:syntax() fu! s:syntax()
@ -1274,7 +1276,7 @@ endf
fu! s:leavepre() fu! s:leavepre()
if s:clrex && ( !has('clientserver') || if s:clrex && ( !has('clientserver') ||
\ ( has('clientserver') && len(split(serverlist(), "\n")) == 1 ) ) \ ( has('clientserver') && len(split(serverlist(), "\n")) == 1 ) )
cal ctrlp#clra(1) cal ctrlp#clra()
en en
endf endf
@ -1319,6 +1321,7 @@ fu! s:argmaps(md, ...)
endf endf
" Misc {{{2 " Misc {{{2
fu! s:getenv() fu! s:getenv()
let s:winh = min([s:mxheight, &lines])
let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]] let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)] let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
let [s:crword, s:crline] = [expand('<cword>'), getline('.')] let [s:crword, s:crline] = [expand('<cword>'), getline('.')]
@ -1359,12 +1362,15 @@ fu! s:migemo(str)
retu str retu str
endf endf
fu! s:openfile(cmd, filpath, ...) fu! s:openfile(cmd, fid, tail, ...)
let cmd = a:cmd =~ '^[eb]$' && &modified ? 'hid '.a:cmd : a:cmd let cmd = a:cmd =~ '^[eb]$' && &modified ? 'hid '.a:cmd : a:cmd
let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : cmd let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : cmd
let tail = a:0 ? a:1 : s:tail() let j2l = a:0 && a:1 ? a:2 : 0
exe cmd.tail.' '.ctrlp#fnesc(a:filpath) exe cmd.( a:0 && a:1 ? '' : a:tail ) ctrlp#fnesc(a:fid)
if !empty(tail) if j2l
exe j2l
en
if !empty(a:tail) || j2l
sil! norm! zvzz sil! norm! zvzz
en en
if exists('*haslocaldir') if exists('*haslocaldir')

View File

@ -45,8 +45,9 @@ fu! ctrlp#quickfix#accept(mode, str)
let cmd = md == 't' ? 'tabe' : md == 'h' ? 'new' : md == 'v' ? 'vne' let cmd = md == 't' ? 'tabe' : md == 'h' ? 'new' : md == 'v' ? 'vne'
\ : ctrlp#normcmd('e') \ : ctrlp#normcmd('e')
let cmd = cmd == 'e' && &modified ? 'hid e' : cmd let cmd = cmd == 'e' && &modified ? 'hid e' : cmd
exe cmd.' '.ctrlp#fnesc(filpath) exe cmd ctrlp#fnesc(filpath)
cal cursor(items[2], items[3]) | sil! norm! zvzz cal cursor(items[2], items[3])
sil! norm! zvzz
endf endf
fu! ctrlp#quickfix#id() fu! ctrlp#quickfix#id()

View File

@ -95,11 +95,11 @@ fu! ctrlp#tag#accept(mode, str)
let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : cmd let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : cmd
if fnd[0] == 1 if fnd[0] == 1
if cmd != '' if cmd != ''
sil! exe cmd exe cmd
en en
exe fnd[1].'ta' tg exe fnd[1].'ta' tg
el el
exe cmd.' '.tg exe cmd tg
en en
endf endf

View File

@ -33,9 +33,9 @@ fu! ctrlp#utils#cachedir()
endf endf
fu! ctrlp#utils#cachefile(...) fu! ctrlp#utils#cachefile(...)
let tail = exists('a:1') ? '.'.a:1 : '' let tail = a:0 ? '.'.a:1 : ''
let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt' let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt'
retu exists('a:1') ? cache_file : s:cache_dir.s:lash(s:cache_dir).cache_file retu a:0 ? cache_file : s:cache_dir.s:lash(s:cache_dir).cache_file
endf endf
fu! ctrlp#utils#readfile(file) fu! ctrlp#utils#readfile(file)
@ -58,9 +58,9 @@ fu! ctrlp#utils#mkdir(dir)
endf endf
fu! ctrlp#utils#writecache(lines, ...) fu! ctrlp#utils#writecache(lines, ...)
if isdirectory(ctrlp#utils#mkdir(exists('a:1') ? a:1 : s:cache_dir)) if isdirectory(ctrlp#utils#mkdir(a:0 ? a:1 : s:cache_dir))
sil! cal writefile(a:lines, exists('a:2') ? a:2 : ctrlp#utils#cachefile()) sil! cal writefile(a:lines, a:0 >= 2 ? a:2 : ctrlp#utils#cachefile())
if !exists('a:1') if !a:0
let g:ctrlp_newcache = 0 let g:ctrlp_newcache = 0
en en
en en

View File

@ -755,6 +755,7 @@ Special thanks:~
* Zak Johnson <github.com/zakj> * Zak Johnson <github.com/zakj>
* Diego Viola <github.com/diegoviola> * Diego Viola <github.com/diegoviola>
* Thibault Duplessis <github.com/ornicar> * Thibault Duplessis <github.com/ornicar>
* Tacahiroy <github.com/tacahiroy>
Bugfixes/Corrections. Bugfixes/Corrections.
=============================================================================== ===============================================================================