Skip to content

Commit

Permalink
Version 1.6.6
Browse files Browse the repository at this point in the history
* Allow running commands like `:diffthis` when opening multiple files.
* Add experimental extensions:
  + undo.vim (requires v7.3.005+)
  + rtscript.vim (find vimscripts in runtimepath)
* Include the workaround for <bs> and <c-h> for MS-Win. Resolve kien#62.
* Mention custom_ignore in readme and on the homepage. Resolve kien#63.
* Check the present of cwd in returned paths. Fix kien#64.
* Trigger Vim to remove cwd from display-names. Fix kien#65.
* Some internal changes and additions.
  • Loading branch information
kien committed Jan 6, 2012
1 parent 93637ea commit 9690757
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 135 deletions.
167 changes: 100 additions & 67 deletions autoload/ctrlp.vim

Large diffs are not rendered by default.

50 changes: 37 additions & 13 deletions autoload/ctrlp/buffertag.vim
Expand Up @@ -2,6 +2,9 @@
" File: autoload/ctrlp/buffertag.vim " File: autoload/ctrlp/buffertag.vim
" Description: Buffer Tag extension " Description: Buffer Tag extension
" Maintainer: Kien Nguyen <github.com/kien> " Maintainer: Kien Nguyen <github.com/kien>
" Credits: Much of the code was taken from tagbar.vim by Jan Larres, plus
" a few lines from taglist.vim by Yegappan Lakshmanan and from
" buffertag.vim by Takeshi Nishida.
" ============================================================================= " =============================================================================


" Init {{{1 " Init {{{1
Expand All @@ -10,8 +13,8 @@ if exists('g:loaded_ctrlp_buftag') && g:loaded_ctrlp_buftag
en en
let g:loaded_ctrlp_buftag = 1 let g:loaded_ctrlp_buftag = 1


let s:buftag_var = ['ctrlp#buffertag#init(s:crfile, s:crbufnr)', let s:buftag_var = ['ctrlp#buffertag#init(s:crfile)', 'ctrlp#buffertag#accept',
\ 'ctrlp#buffertag#accept', 'buffer tags', 'bft'] \ 'buffer tags', 'bft', 'ctrlp#buffertag#exit()']


let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:buftag_var) : [s:buftag_var] \ ? add(g:ctrlp_ext_vars, s:buftag_var) : [s:buftag_var]
Expand Down Expand Up @@ -167,47 +170,68 @@ fu! s:process(fname, ftype)
let ftime = getftime(a:fname) let ftime = getftime(a:fname)
if has_key(g:ctrlp_buftags, a:fname) if has_key(g:ctrlp_buftags, a:fname)
\ && g:ctrlp_buftags[a:fname]['time'] >= ftime \ && g:ctrlp_buftags[a:fname]['time'] >= ftime
let data = g:ctrlp_buftags[a:fname]['data'] let lines = g:ctrlp_buftags[a:fname]['lines']
el el
let data = s:exectagsonfile(a:fname, a:ftype) let data = s:exectagsonfile(a:fname, a:ftype)
let cache = { a:fname : { 'time': ftime, 'data': data } } let [raw, lines] = [split(data, '\n\+'), []]
for line in raw | if len(split(line, ';"')) == 2
cal add(lines, s:parseline(line))
en | endfo
let cache = { a:fname : { 'time': ftime, 'lines': lines } }
cal extend(g:ctrlp_buftags, cache) cal extend(g:ctrlp_buftags, cache)
en en
let [raw, lines] = [split(data, '\n\+'), []]
for line in raw | if len(split(line, ';"')) == 2
cal add(lines, s:parseline(line))
en | endfo
retu lines retu lines
endf endf


fu! s:parseline(line) fu! s:parseline(line)
let eval = '\v^([^\t]+)\t(.+)\t\/\^(.+)\$\/\;\"\t(.+)\tline(no)?\:(\d+)' let eval = '\v^([^\t]+)\t(.+)\t\/\^(.+)\$\/\;\"\t(.+)\tline(no)?\:(\d+)'
let vals = matchlist(a:line, eval) let vals = matchlist(a:line, eval)
if empty(vals) | retu '' | en if empty(vals) | retu '' | en
retu vals[1].' '.vals[4].'|'.vals[6].'| '.vals[3] let [bufnr, bufname] = [bufnr(vals[2]), fnamemodify(vals[2], ':p:t')]
retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3]
endf endf
" Public {{{1 " Public {{{1
fu! ctrlp#buffertag#init(fname, bufnr) fu! ctrlp#buffertag#init(fname)
let fname = exists('s:bufname') ? s:bufname : a:fname
let bufs = exists('s:btmode') && s:btmode ? ctrlp#allbufs() : [fname]
let lines = []
for each in bufs
let tftype = get(split(getbufvar(each, '&ft'), '\.'), 0, '')
cal extend(lines, s:process(each, tftype))
endfo
sy match CtrlPTabExtra '\zs\t.*\ze$' sy match CtrlPTabExtra '\zs\t.*\ze$'
hi link CtrlPTabExtra Comment hi link CtrlPTabExtra Comment
retu s:process(a:fname, get(split(getbufvar(a:bufnr, '&ft'), '\.'), 0, '')) retu lines
endf endf


fu! ctrlp#buffertag#accept(mode, str) fu! ctrlp#buffertag#accept(mode, str)
cal ctrlp#exit() cal ctrlp#exit()
let vals = matchlist(a:str, '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|')
let [bufnr, linenr] = [vals[1], vals[2]]
if a:mode == 't' if a:mode == 't'
tab sp tab sp
elsei a:mode == 'h' elsei a:mode == 'h'
sp sp
elsei a:mode == 'v' elsei a:mode == 'v'
vs vs
en en
cal ctrlp#j2l(matchstr(a:str, '^[^\t]\+\t\+[^\t|]\+|\zs\d\+\ze|')) if exists('s:btmode') && s:btmode
exe 'hid b' bufnr
en
cal ctrlp#j2l(linenr)
endf endf


fu! ctrlp#buffertag#id() fu! ctrlp#buffertag#cmd(mode, ...)
let s:btmode = a:mode
if a:0 && !empty(a:1)
let s:bufname = fnamemodify(a:1, ':p')
en
retu s:id retu s:id
endf endf

fu! ctrlp#buffertag#exit()
unl! s:btmode s:bufname
endf
"}}} "}}}


" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
4 changes: 0 additions & 4 deletions autoload/ctrlp/dir.vim
Expand Up @@ -15,7 +15,6 @@ let s:ars = [
\ 's:maxfiles', \ 's:maxfiles',
\ 's:compare_lim', \ 's:compare_lim',
\ 's:glob', \ 's:glob',
\ 's:usrign',
\ ] \ ]


let s:dir_var = ['ctrlp#dir#init('.join(s:ars, ', ').')', 'ctrlp#dir#accept', let s:dir_var = ['ctrlp#dir#init('.join(s:ars, ', ').')', 'ctrlp#dir#accept',
Expand All @@ -28,9 +27,6 @@ let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1 " Utilities {{{1
fu! s:globdirs(dirs, depth) fu! s:globdirs(dirs, depth)
let entries = split(globpath(a:dirs, s:glob), "\n") let entries = split(globpath(a:dirs, s:glob), "\n")
if s:usrign != ''
cal filter(entries, 'v:val !~ s:usrign')
en
let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1] let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1]
cal extend(g:ctrlp_alldirs, dirs) cal extend(g:ctrlp_alldirs, dirs)
if !empty(dirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles) if !empty(dirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles)
Expand Down
20 changes: 9 additions & 11 deletions autoload/ctrlp/line.vim
@@ -1,9 +1,16 @@
" ============================================================================= " =============================================================================
" File: autoload/ctrlp/line.vim " File: autoload/ctrlp/line.vim
" Description: Line extension - find a line in any buffer. " Description: Line extension - Find a line in any buffer
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" ============================================================================= " =============================================================================


" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['line']
" Create A Command:
" com! CtrlPLine cal ctrlp#init(ctrlp#line#id())
"}}}

" Init {{{1 " Init {{{1
if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line
fini fini
Expand All @@ -18,16 +25,7 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Public {{{1 " Public {{{1
fu! ctrlp#line#init() fu! ctrlp#line#init()
let [bufs, lines] = [[], []] let [bufs, lines] = [ctrlp#allbufs(), []]
for each in range(1, bufnr('$'))
if getbufvar(each, '&bl')
let bufname = bufname(each)
if strlen(bufname) && bufname != 'ControlP'
cal add(bufs, fnamemodify(bufname, ':p'))
en
en
endfo
cal filter(bufs, 'filereadable(v:val)')
for each in bufs for each in bufs
let from_file = readfile(each) let from_file = readfile(each)
cal map(from_file, 'tr(v:val, '' '', '' '')') cal map(from_file, 'tr(v:val, '' '', '' '')')
Expand Down
2 changes: 1 addition & 1 deletion autoload/ctrlp/quickfix.vim
Expand Up @@ -11,7 +11,7 @@ en
let g:loaded_ctrlp_quickfix = 1 let g:loaded_ctrlp_quickfix = 1


let s:var_qf = ['ctrlp#quickfix#init()', 'ctrlp#quickfix#accept', 'quickfix', let s:var_qf = ['ctrlp#quickfix#init()', 'ctrlp#quickfix#accept', 'quickfix',
\ 'qfx', [1]] \ 'qfx']


let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:var_qf) : [s:var_qf] \ ? add(g:ctrlp_ext_vars, s:var_qf) : [s:var_qf]
Expand Down
45 changes: 45 additions & 0 deletions autoload/ctrlp/rtscript.vim
@@ -0,0 +1,45 @@
" =============================================================================
" File: autoload/ctrlp/rtscript.vim
" Description: Runtime scripts extension - Find vimscripts in runtimepath
" Author: Kien Nguyen <github.com/kien>
" =============================================================================

" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['rtscript']
" Create A Command:
" com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id())
"}}}

" Init {{{1
if exists('g:loaded_ctrlp_rtscript') && g:loaded_ctrlp_rtscript
fini
en
let [g:loaded_ctrlp_rtscript, g:ctrlp_newrts] = [1, 0]

let s:rtscript_var = ['ctrlp#rtscript#init()', 'ctrlp#rtscript#accept',
\ 'runtime scripts', 'rts']

let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:rtscript_var) : [s:rtscript_var]

let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Public {{{1
fu! ctrlp#rtscript#init()
if g:ctrlp_newrts || !exists('g:ctrlp_rtscache')
let entries = split(globpath(&rtp, '**/*.\(vim\|txt\)'), "\n")
let [g:ctrlp_rtscache, g:ctrlp_newrts] = [ctrlp#dirnfile(entries)[1], 0]
en
retu g:ctrlp_rtscache
endf

fu! ctrlp#rtscript#accept(mode, str)
cal ctrlp#acceptfile(a:mode, a:str)
endf

fu! ctrlp#rtscript#id()
retu s:id
endf
"}}}

" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
116 changes: 116 additions & 0 deletions autoload/ctrlp/undo.vim
@@ -0,0 +1,116 @@
" =============================================================================
" File: autoload/ctrlp/undo.vim
" Description: Undo extension - Browse undo history (requires Vim 7.3.005+)
" Author: Kien Nguyen <github.com/kien>
" =============================================================================

" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['undo']
" Create A Command:
" com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
"}}}

" Init {{{1
if ( exists('g:loaded_ctrlp_undo') && g:loaded_ctrlp_undo )
\ || !( v:version > 702 && has('patch005') )
fini
en
let g:loaded_ctrlp_undo = 1

let s:undo_var = ['ctrlp#undo#init(s:undotree)', 'ctrlp#undo#accept',
\ 'undo', 'udo']

let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:undo_var) : [s:undo_var]

let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1
fu! s:flatten(tree)
let flatdict = {}
for each in a:tree
cal extend(flatdict, { each['seq'] : each['time'] })
if has_key(each, 'alt')
cal extend(flatdict, s:flatten(each['alt']))
en
endfo
retu flatdict
endf

fu! s:humantime(nr)
let elapsed = localtime() - a:nr
let mins = elapsed / 60
let hrs = elapsed / 3600
let days = elapsed / 86400
let wks = elapsed / 604800
let mons = elapsed / 2592000
let yrs = elapsed / 31536000
let text = [
\ ' second ago',
\ ' seconds ago',
\ ' minutes ago',
\ ' hours ago',
\ ' days ago',
\ ' weeks ago',
\ ' months ago',
\ ' years ago',
\ ]
if yrs > 1
retu yrs.text[7]
elsei mons > 1
retu mons.text[6]
elsei wks > 1
retu wks.text[5]
elsei days > 1
retu days.text[4]
elsei hrs > 1
retu hrs.text[3]
elsei mins > 1
retu mins.text[2]
elsei elapsed == 1
retu elapsed.text[0]
elsei elapsed < 120
retu elapsed.text[1]
en
endf

fu! s:syntax()
sy match CtrlPUndoT '\d\+ \zs[^ ]\+\ze'
sy match CtrlPUndoBr '\[\|\]'
sy match CtrlPUndoNr '\[\d\+\]$' contains=CtrlPUndoBr
hi link CtrlPUndoT Directory
hi link CtrlPUndoBr Comment
hi link CtrlPUndoNr String
endf

fu! s:dict2list(dict)
let dict = map(a:dict, 's:humantime(v:val)')
retu map(keys(dict), 'eval(''[v:val, dict[v:val]]'')')
endf

fu! s:compval(...)
retu a:2[0] - a:1[0]
endf
" Public {{{1
fu! ctrlp#undo#init(undo)
let entries = a:undo['entries']
if empty(entries) | retu [] | en
cal s:syntax()
let g:ctrlp_nolimit = 1
let entries = sort(s:dict2list(s:flatten(entries)), 's:compval')
retu map(entries, 'v:val[1]." [".v:val[0]."]"')
endf

fu! ctrlp#undo#accept(mode, str)
let undon = matchstr(a:str, '\[\zs\d\+\ze\]')
if empty(undon) | retu | en
cal ctrlp#exit()
exe 'u' undon
endf

fu! ctrlp#undo#id()
retu s:id
endf
"}}}

" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2

0 comments on commit 9690757

Please sign in to comment.