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

View File

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

View File

@ -33,9 +33,9 @@ fu! ctrlp#utils#cachedir()
endf
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'
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
fu! ctrlp#utils#readfile(file)
@ -58,9 +58,9 @@ fu! ctrlp#utils#mkdir(dir)
endf
fu! ctrlp#utils#writecache(lines, ...)
if isdirectory(ctrlp#utils#mkdir(exists('a:1') ? a:1 : s:cache_dir))
sil! cal writefile(a:lines, exists('a:2') ? a:2 : ctrlp#utils#cachefile())
if !exists('a:1')
if isdirectory(ctrlp#utils#mkdir(a:0 ? a:1 : s:cache_dir))
sil! cal writefile(a:lines, a:0 >= 2 ? a:2 : ctrlp#utils#cachefile())
if !a:0
let g:ctrlp_newcache = 0
en
en

View File

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