From 7cda4083dea19ff43f11cdf6b67601e135f4d916 Mon Sep 17 00:00:00 2001 From: Kien N Date: Wed, 4 Apr 2012 06:17:11 +0700 Subject: [PATCH] Add mixed files + mrufiles mode Close #101 --- autoload/ctrlp/mixed.vim | 82 +++++++++++++++++++++++++++++++++++++ autoload/ctrlp/mrufiles.vim | 8 ++-- doc/ctrlp.txt | 10 ++++- plugin/ctrlp.vim | 26 +++++------- 4 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 autoload/ctrlp/mixed.vim diff --git a/autoload/ctrlp/mixed.vim b/autoload/ctrlp/mixed.vim new file mode 100644 index 0000000..20e82b7 --- /dev/null +++ b/autoload/ctrlp/mixed.vim @@ -0,0 +1,82 @@ +" ============================================================================= +" File: autoload/ctrlp/mixed.vim +" Description: Files + MRU +" Author: Kien Nguyen +" ============================================================================= + +" Init {{{1 +if exists('g:loaded_ctrlp_mixed') && g:loaded_ctrlp_mixed + fini +en +let [g:loaded_ctrlp_mixed, g:ctrlp_newmix] = [1, 0] + +let s:mixed_var = { + \ 'init': 'ctrlp#mixed#init(s:compare_lim)', + \ 'accept': 'ctrlp#acceptfile', + \ 'lname': 'fil + mru', + \ 'sname': 'mix', + \ 'type': 'path', + \ 'opmul': 1, + \ 'specinput': 1, + \ } + +let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) + \ ? add(g:ctrlp_ext_vars, s:mixed_var) : [s:mixed_var] + +let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) +" Utilities {{{1 +fu! s:newcache(cwd) + if !has_key(g:ctrlp_allmixes, 'data') | retu 1 | en + retu g:ctrlp_allmixes['cwd'] != a:cwd + \ || g:ctrlp_allmixes['time'] < getftime(ctrlp#utils#cachefile()) + \ || g:ctrlp_allmixes['bufs'] < len(ctrlp#mrufiles#mrufs()) +endf + +fu! s:getnewmix(cwd, clim) + if g:ctrlp_newmix + cal ctrlp#mrufiles#refresh('raw') + let g:ctrlp_newcache = 1 + en + cal ctrlp#files() + cal ctrlp#progress('Mixing...') + let mrufs = ctrlp#mrufiles#list('raw') + if exists('+ssl') && &ssl + cal map(mrufs, 'tr(v:val, "\\", "/")') + en + if len(mrufs) > len(g:ctrlp_allfiles) || v:version < 702 + cal filter(mrufs, 'stridx(v:val, a:cwd)') + el + let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)') + let cwd_mrufs = ctrlp#rmbasedir(cwd_mrufs) + for each in cwd_mrufs + let id = index(g:ctrlp_allfiles, each) + if id >= 0 | cal remove(g:ctrlp_allfiles, id) | en + endfo + en + cal map(mrufs, 'fnamemodify(v:val, ":.")') + let g:ctrlp_lines = len(mrufs) > len(g:ctrlp_allfiles) + \ ? g:ctrlp_allfiles + mrufs : mrufs + g:ctrlp_allfiles + if len(g:ctrlp_lines) <= a:clim + cal sort(g:ctrlp_lines, 'ctrlp#complen') + en + let g:ctrlp_allmixes = { 'time': getftime(ctrlp#utils#cachefile()), + \ 'cwd': a:cwd, 'bufs': len(ctrlp#mrufiles#mrufs()), 'data': g:ctrlp_lines } +endf +" Public {{{1 +fu! ctrlp#mixed#init(clim) + let cwd = getcwd() + if g:ctrlp_newmix || s:newcache(cwd) + cal s:getnewmix(cwd, a:clim) + el + let g:ctrlp_lines = g:ctrlp_allmixes['data'] + en + let g:ctrlp_newmix = 0 + retu g:ctrlp_lines +endf + +fu! ctrlp#mixed#id() + retu s:id +endf +"}}} + +" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 diff --git a/autoload/ctrlp/mrufiles.vim b/autoload/ctrlp/mrufiles.vim index f8c3048..4fb1e7e 100644 --- a/autoload/ctrlp/mrufiles.vim +++ b/autoload/ctrlp/mrufiles.vim @@ -64,7 +64,7 @@ fu! s:record(bufnr, ...) cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile) endf " Public {{{1 -fu! ctrlp#mrufiles#refresh() +fu! ctrlp#mrufiles#refresh(...) let mrufs = s:readcache() cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)') if exists('+ssl') @@ -72,7 +72,7 @@ fu! ctrlp#mrufiles#refresh() cal filter(mrufs, 'count(mrufs, v:val) == 1') en cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile) - retu s:reformat(mrufs) + retu a:0 && a:1 == 'raw' ? [] : s:reformat(mrufs) endf fu! ctrlp#mrufiles#remove(files) @@ -86,8 +86,8 @@ fu! ctrlp#mrufiles#remove(files) endf fu! ctrlp#mrufiles#list(...) - if a:0 | cal s:record(a:1) | retu | en - retu s:reformat(s:readcache()) + if a:0 && a:1 != 'raw' | cal s:record(a:1) | retu | en + retu a:0 && a:1 == 'raw' ? s:readcache() : s:reformat(s:readcache()) endf fu! ctrlp#mrufiles#bufs() diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index ed807de..b828f8a 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -696,7 +696,7 @@ EXTENSIONS *g:ctrlp-extensions* Extensions are optional. To enable an extension, add its name to the variable g:ctrlp_extensions: > let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript', - \ 'undo', 'line', 'changes'] + \ 'undo', 'line', 'changes', 'mixed'] < The order of the items will be the order they appear on the statusline and when using , . @@ -766,6 +766,12 @@ Available extensions:~ - Search for and jump to a recent change in the current buffer or in all listed buffers. + *:CtrlPMixed* + * Mixed mode:~ + - Name: 'mixed' + - Command: ':CtrlPMixed' + - Search in both files and MRU files. + ------------------------------------------------------------------------------- Buffer Tag mode options:~ @@ -898,6 +904,8 @@ Special thanks:~ =============================================================================== CHANGELOG *ctrlp-changelog* + + New command: |:CtrlPMixed|, search in both files and MRU files. + Before 2012/03/31~ + New option: |g:ctrlp_default_input|, default input when entering CtrlP. diff --git a/plugin/ctrlp.vim b/plugin/ctrlp.vim index 75c4f5a..ed159a9 100644 --- a/plugin/ctrlp.vim +++ b/plugin/ctrlp.vim @@ -10,8 +10,9 @@ if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp ) || v:version < 700 || &cp en let g:loaded_ctrlp = 1 -let [g:ctrlp_lines, g:ctrlp_allfiles, g:ctrlp_alltags, g:ctrlp_alldirs, - \ g:ctrlp_buftags, g:ctrlp_builtins] = [[], [], [], [], {}, 2] +let [g:ctrlp_lines, g:ctrlp_allfiles, g:ctrlp_alltags, + \ g:ctrlp_alldirs, g:ctrlp_allmixes, g:ctrlp_buftags, + \ g:ctrlp_builtins] = [[], [], [], [], {}, {}, 2] if !exists('g:ctrlp_map') | let g:ctrlp_map = '' | en if !exists('g:ctrlp_cmd') | let g:ctrlp_cmd = 'CtrlP' | en @@ -39,22 +40,17 @@ en cal ctrlp#mrufiles#init() -com! CtrlPTag cal ctrlp#init(ctrlp#tag#id()) - -com! CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id()) - -com! -n=? -com=dir CtrlPDir cal ctrlp#init(ctrlp#dir#id(), ) - +com! CtrlPTag cal ctrlp#init(ctrlp#tag#id()) +com! CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id()) +com! -n=? -com=dir CtrlPDir + \ cal ctrlp#init(ctrlp#dir#id(), ) com! -n=? -com=buffer CtrlPBufTag \ cal ctrlp#init(ctrlp#buffertag#cmd(0, )) com! CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1)) - -com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id()) - -com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id()) - -com! CtrlPLine cal ctrlp#init(ctrlp#line#id()) - +com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id()) +com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id()) +com! CtrlPLine cal ctrlp#init(ctrlp#line#id()) com! -n=? -com=buffer CtrlPChange \ cal ctrlp#init(ctrlp#changes#cmd(0, )) com! CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1)) +com! CtrlPMixed cal ctrlp#init(ctrlp#mixed#id())