Permalink
Browse files

Use ts-prompt automatically when possible

Closes #451
  • Loading branch information...
1 parent 6e4fb3b commit 83397bd05b6c982f85be936808acb776af8fd9a1 @kien committed Jul 28, 2013
Showing with 32 additions and 22 deletions.
  1. +32 −22 autoload/ctrlp/tag.vim
@@ -22,32 +22,36 @@ cal add(g:ctrlp_ext_vars, {
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1
fu! s:findcount(str)
- let [tg, fname] = split(a:str, '\t\+\ze[^\t]\+$')
+ let [tg, ofname] = split(a:str, '\t\+\ze[^\t]\+$')
let tgs = taglist('^'.tg.'$')
if len(tgs) < 2
- retu [1, 1]
+ retu [0, 0, 0, 0]
en
let bname = fnamemodify(bufname('%'), ':p')
- let fname = expand(fnamemodify(simplify(fname), ':s?^[.\/]\+??:p:.'), 1)
- let [fnd, ct, pos, idx] = [0, 0, 0, 0]
- wh idx < len(tgs)
- if bname == fnamemodify(tgs[idx]["filename"], ':p')
- cal insert(tgs, remove(tgs, idx))
- brea
- en
- let idx += 1
- endw
- for each in tgs
- let ct += 1
- let fulname = fnamemodify(each["filename"], ':p')
+ let fname = expand(fnamemodify(simplify(ofname), ':s?^[.\/]\+??:p:.'), 1)
+ let [fnd, cnt, pos, ctgs, otgs] = [0, 0, 0, [], []]
+ for tgi in tgs
+ let lst = bname == fnamemodify(tgi["filename"], ':p') ? 'ctgs' : 'otgs'
+ cal call('add', [{lst}, tgi])
+ endfo
+ let ntgs = ctgs + otgs
+ for tgi in ntgs
+ let cnt += 1
+ let fulname = fnamemodify(tgi["filename"], ':p')
if stridx(fulname, fname) >= 0
\ && strlen(fname) + stridx(fulname, fname) == strlen(fulname)
let fnd += 1
- let pos = ct
+ let pos = cnt
en
- if fnd > 1 | brea | en
endfo
- retu [fnd, pos]
+ let cnt = 0
+ for tgi in ntgs
+ let cnt += 1
+ if tgi["filename"] == ofname
+ let [fnd, pos] = [0, cnt]
+ en
+ endfo
+ retu [1, fnd, pos, len(ctgs)]
endf
fu! s:filter(tags)
@@ -89,27 +93,33 @@ endf
fu! ctrlp#tag#accept(mode, str)
cal ctrlp#exit()
let str = matchstr(a:str, '^[^\t]\+\t\+[^\t]\+\ze\t')
- let [tg, fnd] = [split(str, '^[^\t]\+\zs\t')[0], s:findcount(str)]
+ let [tg, fdcnt] = [split(str, '^[^\t]\+\zs\t')[0], s:findcount(str)]
let cmds = {
\ 't': ['tab sp', 'tab stj'],
\ 'h': ['sp', 'stj'],
\ 'v': ['vs', 'vert stj'],
\ 'e': ['', 'tj'],
\ }
- let cmd = fnd[0] == 1 ? cmds[a:mode][0] : cmds[a:mode][1]
+ let utg = fdcnt[3] < 2 && fdcnt[0] == 1 && fdcnt[1] == 1
+ let cmd = !fdcnt[0] || utg ? cmds[a:mode][0] : cmds[a:mode][1]
let cmd = a:mode == 'e' && ctrlp#modfilecond(!&aw)
\ ? ( cmd == 'tj' ? 'stj' : 'sp' ) : cmd
let cmd = a:mode == 't' ? ctrlp#tabcount().cmd : cmd
- if fnd[0] == 1
+ if !fdcnt[0] || utg
if cmd != ''
exe cmd
en
let save_cst = &cst
set cst&
- cal feedkeys(":".fnd[1]."ta ".tg."\r", 'nt')
+ cal feedkeys(":".( utg ? fdcnt[2] : "" )."ta ".tg."\r", 'nt')
let &cst = save_cst
el
- cal feedkeys(":".cmd." ".tg."\r", 'nt')
+ let ext = ""
+ if fdcnt[1] < 2 && fdcnt[2]
+ let [sav_more, &more] = [&more, 0]
+ let ext = fdcnt[2]."\r".":let &more = ".sav_more."\r"
+ en
+ cal feedkeys(":".cmd." ".tg."\r".ext, 'nt')
en
cal ctrlp#setlcdir()
endf

0 comments on commit 83397bd

Please sign in to comment.