Merge branch 'develop'

This commit is contained in:
Kien N 2011-09-09 04:41:57 +07:00
commit e4181dc3d9
3 changed files with 100 additions and 47 deletions

View File

@ -123,31 +123,42 @@ func! ctrlp#clearallcaches()
endfunc
"}}}
func! s:ListAllFiles(path) "{{{
" s:ListAllFiles(path) {{{
func! s:List(path)
" note: wildignore is ignored when using **, so find all the directories
" first then glob with * for the files
let alldirs = split(globpath(a:path, '**'), '\n')
cal filter(alldirs, 'isdirectory(v:val)')
let dirs = join(alldirs, ',')
let allfiles = split(globpath(a:path, '*'), '\n')
let allfiles = extend(allfiles, split(globpath(dirs, '*'), '\n'))
cal filter(allfiles, '!isdirectory(v:val)')
" remove base directory
let path = &ssl || !exists('+ssl') ? getcwd().'/' : substitute(getcwd(), '\', '\\\\', 'g').'\\'
cal map(allfiles, 'substitute(v:val, path, "", "g")')
retu allfiles
endfunc
func! s:ListAllFiles(path)
let cache_file = ctrlp#utils#cachefile()
if g:ctrlp_newcache || !filereadable(cache_file) || s:caching == 0
let allfiles = split(globpath(a:path, '**'), '\n')
cal filter(allfiles, '!isdirectory(v:val)')
" filter all entries matched wildignore's patterns (in addition to globpath's)
if exists('+wig') && !empty(&wig)
let ignores = map(split(&wig, ','), 'substitute(v:val, "\\W\\+", ".*", "g")')
cal filter(allfiles, 's:matchlists(v:val, string(ignores))')
endif
" remove base directory
let path = &ssl || !exists('+ssl') ? getcwd().'/' : substitute(getcwd(), '\', '\\\\', 'g').'\\'
cal map(allfiles, 'substitute(v:val, path, "", "g")')
if g:ctrlp_newcache || !filereadable(cache_file) || !s:caching
let allfiles = s:List(a:path)
let read_cache = 0
else
let allfiles = ctrlp#utils#readfile(cache_file)
let read_cache = 1
endif
if len(allfiles) <= 3000 | cal sort(allfiles, 's:compare') | endif
" write cache
if ( g:ctrlp_newcache || !filereadable(cache_file) ) && s:caching
\ || len(allfiles) > 4000
if !read_cache &&
\ ( ( g:ctrlp_newcache || !filereadable(cache_file) )
\ && s:caching || len(allfiles) > 4000 )
if len(allfiles) > 4000 | let s:caching = 1 | endif
cal ctrlp#utils#writecache(allfiles)
endif
retu allfiles
endfunc "}}}
endfunc
"}}}
func! s:ListAllBuffers() "{{{
let allbufs = []
@ -190,7 +201,7 @@ func! s:SplitPattern(str,...) "{{{
if len(array) > 1
for i in range(1, len(array) - 1)
" Separator
let sp = exists('a:1') ? a:1 : '.*'
let sp = exists('a:1') ? a:1 : '.\{-}'
let nitem .= sp.array[i]
cal add(newpats, nitem)
endfor
@ -305,7 +316,7 @@ func! s:BufOpen(...) "{{{
let s:CtrlP_ea = &ea
let s:CtrlP_ut = &ut
let s:CtrlP_gcr = &gcr
if !exists('g:CtrlP_prompt') || s:pinput == 0
if !exists('g:CtrlP_prompt') || !s:pinput
let g:CtrlP_prompt = ['', '', '']
endif
se magic
@ -365,7 +376,6 @@ func! s:UpdateMatches(pat) "{{{
let newpat = s:SplitPattern(a:pat)
let lines = s:GetMatchedItems(s:lines, newpat, s:mxheight)
cal s:Renderer(lines)
"cal s:Highlight(newpat)
endfunc "}}}
func! s:BuildPrompt(...) "{{{
@ -381,7 +391,7 @@ func! s:BuildPrompt(...) "{{{
" Toggling
if !exists('a:1') || ( exists('a:1') && a:1 )
let hiactive = 'Normal'
elseif exists('a:1') || ( exists('a:1') && a:1 == 0 )
elseif exists('a:1') || ( exists('a:1') && !a:1 )
let hiactive = 'Comment'
let base = substitute(base, '>', '-', 'g')
endif
@ -481,9 +491,16 @@ func! s:PrtSelectJump(char,...)
let g:CtrlP_cline = line('.')
endif
endfunc
func! s:PrtClearCache()
cal ctrlp#clearallcaches()
sil! cal s:SetLines(s:itemtype)
sil! cal s:Renderer(s:lines)
cal s:BuildPrompt()
endfunc
"}}}
" s:MapKeys() && s:MapSpecs() {{{
" s:MapKeys() {{{
func! s:MapKeys(...)
" Normal keystrokes
let func = !exists('a:1') || ( exists('a:1') && a:1 ) ? 'PrtAdd' : 'PrtSelectJump'
@ -493,7 +510,7 @@ func! s:MapKeys(...)
endfor
if exists('a:2') | retu | endif
" Special keystrokes
if exists('a:1') && a:1 == 0
if exists('a:1') && !a:1
cal s:MapSpecs('unmap')
else
cal s:MapSpecs()
@ -524,6 +541,7 @@ func! s:MapSpecs(...)
\ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'BufOpen("ControlP", "del")': ['<esc>', '<c-c>'],
\ }
if type(s:urprtmaps) == 4
@ -536,7 +554,7 @@ func! s:MapSpecs(...)
for each in keys(prttempdis)
if g:ctrlp_mru_files && !has_key(prtmaps, each)
cal extend(prtmaps, {each:prttempdis[each]})
elseif g:ctrlp_mru_files == 0
elseif !g:ctrlp_mru_files
cal remove(prtmaps, each)
endif
endfor
@ -562,7 +580,7 @@ func! s:MapSpecs(...)
endfunc
"}}}
" s:ToggleFocus() && s:Focus() {{{
" s:ToggleFocus() {{{
func! s:Focus()
retu !exists('b:focus') ? 1 : b:focus
endfunc
@ -602,23 +620,12 @@ func! s:Type(type) "{{{
cal s:BuildPrompt(s:Focus())
endfunc "}}}
"Mightdo: Highlight matched characters/strings. /low
func! s:Highlight(...) "{{{
hi clear CtrlPKeywords
hi link CtrlPKeywords Normal
if exists('a:1') && !empty(a:1)
let pat = substitute(a:1[-1], ':\d*$', '', 'g')
exe 'syn match CtrlPKeywords /\c'.pat.'/'
hi link CtrlPKeywords Constant
endif
endfunc "}}}
" ctrlp#SetWorkingPath(...) {{{
func! s:FindRoot(curr, mark)
if !empty(globpath(a:curr, a:mark))
exe 'chdir' a:curr
else
let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]*$', '', '')
let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '')
if parent != a:curr
cal s:FindRoot(parent, a:mark)
endif
@ -631,7 +638,7 @@ func! ctrlp#SetWorkingPath(...)
let l:pathmode = a:1
endif
if match(expand('%:p'), '^\<.\+\>://.*') >= 0
\ || s:pathmode == 0 || l:pathmode == 0
\ || !s:pathmode || !l:pathmode
retu
endif
if exists('+acd')
@ -659,14 +666,21 @@ func! ctrlp#SetWorkingPath(...)
endfunc
"}}}
func! s:AcceptSelection(mode) "{{{
func! s:AcceptSelection(mode,...) "{{{
let md = a:mode
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]
" If only need the full path
if exists('a:1') && a:1 | retu filepath | endif
" Remove the prompt and match window
cal s:BufOpen('ControlP', 'del')
" Do an action on the selected entry
" Split the mode string if it's longer than 1 char
if len(md) > 1
let mds = split(md, '\zs')
let md = mds[0]
endif
" Do something with the selected entry
if md == 't' || s:splitwin == 1 " in new tab
tabnew
let cmd = 'e'
@ -674,7 +688,7 @@ func! s:AcceptSelection(mode) "{{{
let cmd = 'new'
elseif md == 'v' || s:splitwin == 3 " in new ver split
let cmd = 'vne'
elseif md == 'e' || s:splitwin == 0 " in current window
elseif md == 'e' || !s:splitwin " in current window
let cmd = 'e'
endif
let bufnum = bufnr(filename)
@ -690,7 +704,6 @@ func! s:AcceptSelection(mode) "{{{
ec
endfunc "}}}
"Mightdo: Further customizing s:compare(). Sort by file type. /low
" Helper functions {{{
func! s:compare(s1, s2)
" by length
@ -705,7 +718,7 @@ func! s:walker(max, pos, dir, ...)
elseif a:dir == -1
let pos = a:pos > 0 ? a:pos - 1 : a:max
endif
if g:ctrlp_mru_files == 0 && pos == 2
if !g:ctrlp_mru_files && pos == 2
\ && !exists('a:1')
let jmp = pos == a:max ? 0 : 3
let pos = a:pos == 1 ? jmp : 1
@ -719,7 +732,7 @@ func! s:statusline(...)
\ 1: ['buffers', 'buf'],
\ 2: ['recent\ files', 'mru'],
\ }
if g:ctrlp_mru_files == 0
if !g:ctrlp_mru_files
cal remove(itemtypes, 2)
endif
let max = len(itemtypes) - 1
@ -737,7 +750,7 @@ func! s:matchsubstr(item, pat)
endfunc
func! s:matchlists(item, lst)
for each in eval(a:lst)
for each in a:lst
if match(a:item, each) >= 0 | retu 0 | endif
endfor
retu 1
@ -750,11 +763,18 @@ func! s:syntax()
hi link CtrlPNoEntries Error
hi CtrlPLineMarker guifg=bg
endfunc
func! s:uniquefilter(val, pats)
for each in a:pats
if match(each, a:val) >= 0 && len(a:val) < len(each) | retu 0 | endif
endfor
retu 1
endfunc
"}}}
func! s:SetLines(type) "{{{
let s:itemtype = a:type
if s:itemtype == 0
if !s:itemtype
let s:lines = s:ListAllFiles(getcwd())
elseif s:itemtype == 1
let s:lines = s:ListAllBuffers()
@ -770,8 +790,12 @@ func! s:hooks(type) "{{{
retu eval(types[a:type])
endfunc "}}}
func! ctrlp#init(type) "{{{
sil! cal ctrlp#SetWorkingPath()
func! ctrlp#init(type, ...) "{{{
if exists('a:1')
sil! cal ctrlp#SetWorkingPath(a:1)
else
sil! cal ctrlp#SetWorkingPath()
endif
sil! cal s:SetLines(a:type)
sil! cal s:BufOpen('ControlP')
sil! cal s:SetupBlank()

View File

@ -147,6 +147,7 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'BufOpen("ControlP", "del")': ['<esc>', '<c-c>', '<c-g>'],
\ }
<
@ -202,6 +203,20 @@ Example: >
:ClearAllCtrlPCaches
Delete all the saved cache files in |ctrlp_cache_dir|.
*:CtrlPCurWD*
:CtrlPCurWD
Find files in the current working directory.
Ignores |g:ctrlp_working_path_mode|.
*:CtrlPCurFile*
:CtrlPCurFile
Find files in the same directory as the current file, recursively.
*:CtrlPRoot*
:CtrlPRoot
Same as |:CtrlPCurFile| but start from the projects root.
See also |g:ctrlp_working_path_mode|.
===============================================================================
4. Mappings *ctrlp-mappings*
@ -279,6 +294,9 @@ Once inside the prompt:
<c-s>
Open selected file in a 'horizontal' split
<F5>
Refresh the match window.
<esc>,
<c-c>,
<c-g>
@ -292,7 +310,7 @@ Chose your own mappings with |g:ctrlp_prompt_mappings|.
*ctrlp-prompt-input-formats*
Formats for inputting in the prompt:
a) Simple string. e.g. 'abc' is understood internally as 'a.*b.*c'
a) Simple string. e.g. 'abc' is understood internally as 'a.\{-}b.\{-}c'
b) Vim |regexp|. If the input string contains '*', '^', '$', '+' or '$', itll
be treated as a Vims |regexp| |pattern| without any modification.
@ -323,6 +341,13 @@ Mercurial repository: https://bitbucket.org/kien/ctrlp.vim
===============================================================================
CHANGELOG
*ctrlp-update-2*
Update #2~
+ New mapping: <F5>.
+ New commands: |:CtrlPRoot|,
|:CtrlPCurWD|
|:CtrlPCurFile|
*ctrlp-update-1*
Update #1~
+ New feature: search in most recently used (MRU) files

View File

@ -19,6 +19,10 @@ com! CtrlPMRUFiles cal ctrlp#init(2)
com! ClearCtrlPCache cal ctrlp#clearcache()
com! ClearAllCtrlPCaches cal ctrlp#clearallcaches()
com! CtrlPCurWD cal ctrlp#init(0, 0)
com! CtrlPCurFile cal ctrlp#init(0, 1)
com! CtrlPRoot cal ctrlp#init(0, 2)
exe 'nn <silent>' g:ctrlp_map ':<c-u>CtrlP<cr>'
if g:ctrlp_mru_files | cal ctrlp#mrufiles#init() | endif