From 253ccf9d8274ceaba64e6b18548e1e60606d7d33 Mon Sep 17 00:00:00 2001 From: Kien N Date: Fri, 9 Sep 2011 11:09:01 +0700 Subject: [PATCH 1/7] remove unneeded Renderer() --- autoload/ctrlp.vim | 2 -- 1 file changed, 2 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 080c699..3e2f490 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -502,7 +502,6 @@ endfunc func! s:PrtClearCache() cal ctrlp#clearallcaches() sil! cal s:SetLines(s:itemtype) - sil! cal s:Renderer(s:lines) cal s:BuildPrompt() endfunc "}}} @@ -808,7 +807,6 @@ func! ctrlp#init(type, ...) "{{{ sil! cal s:SetupBlank() sil! cal s:MapKeys() sil! cal s:SetLines(a:type) - sil! cal s:Renderer(s:lines) cal s:statusline() cal s:BuildPrompt() sil! cal s:syntax() From 945f3928d5ed22dd93617eb5731796267e845147 Mon Sep 17 00:00:00 2001 From: Kien N Date: Fri, 9 Sep 2011 13:19:47 +0700 Subject: [PATCH 2/7] redraw statusline after refreshing --- autoload/ctrlp.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 3e2f490..382d097 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -502,6 +502,7 @@ endfunc func! s:PrtClearCache() cal ctrlp#clearallcaches() sil! cal s:SetLines(s:itemtype) + cal s:statusline() cal s:BuildPrompt() endfunc "}}} From 1fecf8bc3f1d1941348c9f45a31a9459c3c131f2 Mon Sep 17 00:00:00 2001 From: Kien N Date: Fri, 9 Sep 2011 19:55:24 +0700 Subject: [PATCH 3/7] `..` input format and some refactorings --- autoload/ctrlp.vim | 107 +++++++++++++++++++++++++++++++-------------- doc/ctrlp.txt | 11 +++-- 2 files changed, 81 insertions(+), 37 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 382d097..0334daf 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -99,6 +99,11 @@ else let s:urprtmaps = g:ctrlp_prompt_mappings unl g:ctrlp_prompt_mappings endif + +" Limiters +let s:compare_lim = 3000 +let s:nocache_lim = 4000 +let s:mltipats_lim = 3000 "}}} " Clear caches {{{ @@ -155,12 +160,12 @@ func! s:ListAllFiles(path) let allfiles = ctrlp#utils#readfile(cache_file) let read_cache = 1 endif - if len(allfiles) <= 3000 | cal sort(allfiles, 's:compare') | endif + if len(allfiles) <= s:compare_lim | cal sort(allfiles, 's:compare') | endif " write cache if !read_cache && \ ( ( g:ctrlp_newcache || !filereadable(cache_file) ) - \ && s:caching || len(allfiles) > 4000 ) - if len(allfiles) > 4000 | let s:caching = 1 | endif + \ && s:caching || len(allfiles) > s:nocache_lim ) + if len(allfiles) > s:nocache_lim | let s:caching = 1 | endif cal ctrlp#utils#writecache(allfiles) endif retu allfiles @@ -226,8 +231,8 @@ func! s:GetMatchedItems(items, pats, limit) "{{{ let s:jmpln = substitute(pats[-1], '.*\ze:\d*$', '', 'g') cal remove(pats, -1) endif - " if items is longer than 2000, use only the last pattern - if len(items) >= 2000 + " if items is longer than s:mltipats_lim, use only the last pattern + if len(items) >= s:mltipats_lim let pats = [pats[-1]] endif " loop through the patterns @@ -251,6 +256,7 @@ func! s:GetMatchedItems(items, pats, limit) "{{{ endfor endif endfor + let s:nomatches = len(newitems) retu newitems endfunc "}}} @@ -394,7 +400,10 @@ func! s:BuildPrompt(...) "{{{ let start = escape(g:CtrlP_prompt[0], estr) let mid = escape(g:CtrlP_prompt[1], estr) let end = escape(g:CtrlP_prompt[2], estr) - cal s:UpdateMatches(start.mid.end) + let str = l:start.l:mid.l:end + if strpart(str, 0, 2) != '..' && s:nomatches + cal s:UpdateMatches(str) + endif " Toggling if !exists('a:1') || ( exists('a:1') && a:1 ) let hiactive = 'Normal' @@ -419,59 +428,76 @@ endfunc "}}} "Mightdo: PrtSelectJump() cycles through matches. /medium " Prt Actions {{{ func! s:PrtClear() + let s:nomatches = 1 let g:CtrlP_prompt = ['','',''] cal s:BuildPrompt() endfunc func! s:PrtAdd(char) - let g:CtrlP_prompt[0] = g:CtrlP_prompt[0] . a:char + let prt = g:CtrlP_prompt + let prt[0] = prt[0] . a:char cal s:BuildPrompt() endfunc func! s:PrtBS() - let str = g:CtrlP_prompt[0] - let g:CtrlP_prompt[0] = strpart(str, -1, strlen(str)) + let s:nomatches = 1 + let prt = g:CtrlP_prompt + let prt[0] = strpart(prt[0], -1, strlen(prt[0])) + let g:CtrlP_prompt = prt cal s:BuildPrompt() endfunc func! s:PrtDelete() - let g:CtrlP_prompt[1] = strpart(g:CtrlP_prompt[2], 0, 1) - let g:CtrlP_prompt[2] = strpart(g:CtrlP_prompt[2], 1) + let s:nomatches = 1 + let prt = g:CtrlP_prompt + let prt[1] = strpart(prt[2], 0, 1) + let prt[2] = strpart(prt[2], 1) + let g:CtrlP_prompt = prt cal s:BuildPrompt() endfunc func! s:PrtCurLeft() if !empty(g:CtrlP_prompt[0]) - let g:CtrlP_prompt[2] = g:CtrlP_prompt[1] . g:CtrlP_prompt[2] - let g:CtrlP_prompt[1] = strpart(g:CtrlP_prompt[0], strlen(g:CtrlP_prompt[0]) - 1) - let g:CtrlP_prompt[0] = strpart(g:CtrlP_prompt[0], -1, strlen(g:CtrlP_prompt[0])) + let prt = g:CtrlP_prompt + let prt[2] = prt[1] . prt[2] + let prt[1] = strpart(prt[0], strlen(prt[0]) - 1) + let prt[0] = strpart(prt[0], -1, strlen(prt[0])) + let g:CtrlP_prompt = prt endif cal s:BuildPrompt() endfunc func! s:PrtCurRight() - let g:CtrlP_prompt[0] = g:CtrlP_prompt[0] . g:CtrlP_prompt[1] + let prt = g:CtrlP_prompt + let prt[0] = prt[0] . prt[1] + let g:CtrlP_prompt = prt cal s:PrtDelete() endfunc func! s:PrtCurStart() - let str = g:CtrlP_prompt[0] . g:CtrlP_prompt[1] . g:CtrlP_prompt[2] - let g:CtrlP_prompt[2] = strpart(str, 1) - let g:CtrlP_prompt[1] = strpart(str, 0, 1) - let g:CtrlP_prompt[0] = '' + let prt = g:CtrlP_prompt + let str = prt[0] . prt[1] . prt[2] + let prt[2] = strpart(str, 1) + let prt[1] = strpart(str, 0, 1) + let prt[0] = '' + let g:CtrlP_prompt = prt cal s:BuildPrompt() endfunc func! s:PrtCurEnd() - let str = g:CtrlP_prompt[0] . g:CtrlP_prompt[1] . g:CtrlP_prompt[2] - let g:CtrlP_prompt[2] = '' - let g:CtrlP_prompt[1] = '' - let g:CtrlP_prompt[0] = str + let prt = g:CtrlP_prompt + let str = prt[0] . prt[1] . prt[2] + let prt[2] = '' + let prt[1] = '' + let prt[0] = str + let g:CtrlP_prompt = prt cal s:BuildPrompt() endfunc func! s:PrtDeleteWord() - let str = g:CtrlP_prompt[0] + let s:nomatches = 1 + let prt = g:CtrlP_prompt + let str = prt[0] if match(str, ' [^ ]\+$') >= 0 let str = matchstr(str, '^.\+ \ze[^ ]\+$') elseif match(str, '[ ]\+$') >= 0 @@ -675,6 +701,16 @@ endfunc func! s:AcceptSelection(mode,...) "{{{ let md = a:mode + " use .. to go back in the dir tree + if md == 'e' + let prt = g:CtrlP_prompt + let str = prt[0] . prt[1] . prt[2] + if str == '..' + cal s:parentdir(getcwd()) + cal s:PrtClear() + retu + endif + endif let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$') let filepath = s:itemtype ? matchstr : getcwd().ctrlp#utils#lash().matchstr let filename = split(filepath, ctrlp#utils#lash())[-1] @@ -746,31 +782,33 @@ func! s:statusline(...) let next = itemtypes[s:walker(max, s:itemtype, 1, 1)][1] let prev = itemtypes[s:walker(max, s:itemtype, -1, 1)][1] let item = itemtypes[s:itemtype][0] - let focus = s:Focus() ? 'prt' : 'win' - let byfname = s:byfname ? 'file' : 'path' + let focus = s:Focus() ? 'prt' : 'win' + let byfname = s:byfname ? 'file' : 'path' let regex = s:regexp ? '%#Conditional#\ regex\ %*' : '' let focus = '%#MatchParen#\ '.focus.'\ %*' let byfname = '%#Character#\ '.byfname.'\ %*' let item = '%#Constant#\ '.item.'\ %*' - exe 'setl stl='.focus.byfname.regex.'\ +-<'.prev.'>-{'.item.'}-<'.next.'>-+' + let slider = '\ +-<'.prev.'>-{'.item.'}-<'.next.'>-+' + exe 'setl stl='.focus.byfname.regex.slider endfunc func! s:matchsubstr(item, pat) retu match(split(a:item, '[\/]\ze[^\/]\+$')[-1], a:pat) endfunc -func! s:matchlists(item, lst) - for each in a:lst - if match(a:item, each) >= 0 | retu 0 | endif - endfor - retu 1 -endfunc - func! s:progress(entries) exe 'setl stl=%#WarningMsg#\ '.len(a:entries).'\ %*\ ' redr endfunc +func! s:parentdir(curr) + let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '') + if parent != a:curr + exe 'chdir' parent + endif + cal s:SetLines(s:itemtype) +endfunc + func! s:syntax() syn match CtrlPNoEntries '^ == NO MATCHES ==$' syn match CtrlPNoEntries '^ == DISABLED ==$' @@ -799,6 +837,7 @@ func! s:hooks(type) "{{{ endfunc "}}} func! ctrlp#init(type, ...) "{{{ + let s:nomatches = 1 if exists('a:1') sil! cal ctrlp#SetWorkingPath(a:1) else diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 43092a7..4dce7de 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -322,6 +322,10 @@ c) Strings end with a colon ':' followed by an arbitrary number will be read as a line number to jump to after opening the file. e.g. 'abc:45' will open the selected file and jump to line 45. +d) Type exactly two dots (..) at the start of the line and press enter to go + backward in the directory tree by 1 level. If the parent directory is + large, this might be slow. + =============================================================================== 6. Credits *ctrlp-credits* @@ -343,10 +347,11 @@ CHANGELOG *ctrlp-update-2* Update #2~ + + New input format: '..' (section 5.d) + New mapping: . - + New commands: |:CtrlPRoot|, - |:CtrlPCurWD| - |:CtrlPCurFile| + + New commands: |:CtrlPCurWD|, + |:CtrlPCurFile|, + |:CtrlPRoot| *ctrlp-update-1* Update #1~ From df2622f2943fead4336b12624890161d6d7e3a91 Mon Sep 17 00:00:00 2001 From: Kien N Date: Fri, 9 Sep 2011 20:49:50 +0700 Subject: [PATCH 4/7] update readme with new `..` input --- autoload/ctrlp.vim | 3 +++ readme.md | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 0334daf..9e2e258 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -629,6 +629,7 @@ endfunc func! s:ToggleRegex() "{{{ let s:regexp = s:regexp ? 0 : 1 cal s:statusline() + let s:nomatches = 1 cal s:BuildPrompt(s:Focus()) endfunc "}}} @@ -636,6 +637,7 @@ func! s:ToggleByFname() "{{{ let s:byfname = s:byfname ? 0 : 1 cal s:MapKeys(s:Focus(), 1) cal s:statusline() + let s:nomatches = 1 cal s:BuildPrompt(s:Focus()) endfunc "}}} @@ -650,6 +652,7 @@ func! s:Type(type) "{{{ cal s:syntax() cal s:SetLines(s:itemtype) cal s:statusline() + let s:nomatches = 1 cal s:BuildPrompt(s:Focus()) endfunc "}}} diff --git a/readme.md b/readme.md index 2e6cf1d..2a0b22c 100644 --- a/readme.md +++ b/readme.md @@ -15,6 +15,7 @@ Full path fuzzy file, buffer and MRU file finder for Vim. * Or press `` while CtrlP is open to switch to full regexp search mode. * End the input string with a colon `:` followed with a number to jump to that line in the selected file. e.g. `abc:45` to open the file matched the pattern and jump to line 45. +* Submit two dots `..` as the input string to go backward the directory tree by 1 level. _Screenshot: filename only mode with the match window focused._ ![ctrlp filename mode, match window focused][2] @@ -59,6 +60,6 @@ The parameter is the same (0, 1 or 2): _Check [the docs][3] for more mappings, commands and options._ -[1]: http://i.imgur.com/lQScr.png +[1]: http://i.imgur.com/Gfntl.png [2]: http://i.imgur.com/MyRIv.png [3]: https://github.com/kien/ctrlp.vim/blob/master/doc/ctrlp.txt From 23b27224449c52872a849e1836b5694117dbfa14 Mon Sep 17 00:00:00 2001 From: Kien N Date: Fri, 9 Sep 2011 21:39:13 +0700 Subject: [PATCH 5/7] some clean up --- autoload/ctrlp.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 9e2e258..48a9aaf 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -103,7 +103,7 @@ endif " Limiters let s:compare_lim = 3000 let s:nocache_lim = 4000 -let s:mltipats_lim = 3000 +let s:mltipats_lim = 2000 "}}} " Clear caches {{{ @@ -138,6 +138,7 @@ func! s:List(dirs, allfiles) cal extend(allfiles, a:allfiles, 0) if empty(alldirs) let s:allfiles = allfiles + cal s:statusline() else let dirs = join(alldirs, ',') cal s:progress(allfiles) @@ -814,7 +815,6 @@ endfunc func! s:syntax() syn match CtrlPNoEntries '^ == NO MATCHES ==$' - syn match CtrlPNoEntries '^ == DISABLED ==$' syn match CtrlPLineMarker '^>' hi link CtrlPNoEntries Error hi CtrlPLineMarker guifg=bg @@ -850,7 +850,6 @@ func! ctrlp#init(type, ...) "{{{ sil! cal s:SetupBlank() sil! cal s:MapKeys() sil! cal s:SetLines(a:type) - cal s:statusline() cal s:BuildPrompt() sil! cal s:syntax() endfunc "}}} From ea9b3421257f4339babb4ba2c399f96af4769d2c Mon Sep 17 00:00:00 2001 From: Kien N Date: Fri, 9 Sep 2011 22:02:39 +0700 Subject: [PATCH 6/7] small cosmetics changes --- autoload/ctrlp.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 48a9aaf..41122e9 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -788,11 +788,11 @@ func! s:statusline(...) let item = itemtypes[s:itemtype][0] let focus = s:Focus() ? 'prt' : 'win' let byfname = s:byfname ? 'file' : 'path' - let regex = s:regexp ? '%#Conditional#\ regex\ %*' : '' - let focus = '%#MatchParen#\ '.focus.'\ %*' + let regex = s:regexp ? '%#LineNr#\ regex\ %*' : '' + let focus = '%#LineNr#\ '.focus.'\ %*' let byfname = '%#Character#\ '.byfname.'\ %*' - let item = '%#Constant#\ '.item.'\ %*' - let slider = '\ +-<'.prev.'>-{'.item.'}-<'.next.'>-+' + let item = '%#Character#\ '.item.'\ %*' + let slider = '\ <'.prev.'>={'.item.'}=<'.next.'>' exe 'setl stl='.focus.byfname.regex.slider endfunc @@ -801,7 +801,7 @@ func! s:matchsubstr(item, pat) endfunc func! s:progress(entries) - exe 'setl stl=%#WarningMsg#\ '.len(a:entries).'\ %*\ ' + exe 'setl stl=%#Function#\ '.len(a:entries).'\ %*\ ' redr endfunc From 8569c1257a75ebd944a993a53605e6c41fb67c0a Mon Sep 17 00:00:00 2001 From: Kien N Date: Fri, 9 Sep 2011 22:28:40 +0700 Subject: [PATCH 7/7] don't sort MRU files --- autoload/ctrlp.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 41122e9..7c8bd10 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -361,7 +361,9 @@ func! s:Renderer(lines) "{{{ " Output to buffer if len(nls) >= 1 setl cul - cal sort(nls, 's:compare') + if s:itemtype != 2 + cal sort(nls, 's:compare') + endif if s:mwreverse cal reverse(nls) endif