Some internal changes

This commit is contained in:
Kien N 2012-01-30 23:03:30 +07:00
parent 6a9f1e3a46
commit 5e04bfaeed
2 changed files with 43 additions and 100 deletions

View File

@ -24,7 +24,7 @@ fu! s:opts()
\ 'g:ctrlp_match_window_bottom': ['s:mwbottom', 1], \ 'g:ctrlp_match_window_bottom': ['s:mwbottom', 1],
\ 'g:ctrlp_match_window_reversed': ['s:mwreverse', 1], \ 'g:ctrlp_match_window_reversed': ['s:mwreverse', 1],
\ 'g:ctrlp_max_depth': ['s:maxdepth', 40], \ 'g:ctrlp_max_depth': ['s:maxdepth', 40],
\ 'g:ctrlp_max_files': ['s:maxfiles', 20000], \ 'g:ctrlp_max_files': ['s:maxfiles', 10000],
\ 'g:ctrlp_max_height': ['s:mxheight', 10], \ 'g:ctrlp_max_height': ['s:mxheight', 10],
\ 'g:ctrlp_max_history': ['s:maxhst', hst], \ 'g:ctrlp_max_history': ['s:maxhst', hst],
\ 'g:ctrlp_open_multi': ['s:opmul', '1v'], \ 'g:ctrlp_open_multi': ['s:opmul', '1v'],
@ -66,7 +66,7 @@ fu! s:opts()
\ 'PrtSelectMove("d")': ['<PageDown>'], \ 'PrtSelectMove("d")': ['<PageDown>'],
\ 'PrtHistory(-1)': ['<c-n>'], \ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'], \ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<c-m>', '<2-LeftMouse>'], \ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'], \ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>', '<MiddleMouse>'], \ 'AcceptSelection("t")': ['<c-t>', '<MiddleMouse>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'], \ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
@ -75,7 +75,7 @@ fu! s:opts()
\ 'ToggleByFname()': ['<c-d>'], \ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'], \ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'], \ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>', '<c-i>'], \ 'PrtExpandDir()': ['<tab>'],
\ 'PrtInsert("w")': ['<F2>', '<insert>'], \ 'PrtInsert("w")': ['<F2>', '<insert>'],
\ 'PrtInsert("s")': ['<F3>'], \ 'PrtInsert("s")': ['<F3>'],
\ 'PrtInsert("v")': ['<F4>'], \ 'PrtInsert("v")': ['<F4>'],
@ -126,7 +126,7 @@ cal s:opts()
let s:lash = ctrlp#utils#lash() let s:lash = ctrlp#utils#lash()
" Limiters " Limiters
let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000] let [s:compare_lim, s:nocache_lim] = [3000, 4000]
" Regexp " Regexp
let s:fpats = { let s:fpats = {
@ -298,20 +298,15 @@ endf
fu! s:MatchIt(items, pat, limit, mfunc) fu! s:MatchIt(items, pat, limit, mfunc)
let newitems = [] let newitems = []
for item in a:items for item in a:items
if call(a:mfunc, [item, a:pat]) >= 0 | cal add(newitems, item) | en try | if call(a:mfunc, [item, a:pat]) >= 0 | cal add(newitems, item) | en
cat | brea | endt
if a:limit > 0 && len(newitems) >= a:limit | brea | en if a:limit > 0 && len(newitems) >= a:limit | brea | en
endfo endfo
retu newitems retu newitems
endf endf
fu! s:MatchedItems(items, pats, limit) fu! s:MatchedItems(items, pat, limit)
let [items, pats, limit] = [a:items, a:pats, a:limit] let [items, pat, limit] = [a:items, a:pat, a:limit]
" If items is longer than s:mltipats_lim, use only the last pattern
if len(items) >= s:mltipats_lim || ( exists('s:height') && s:height > 20 )
let pats = [pats[-1]]
en
cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")')
if !s:regexp | cal map(pats, 'escape(v:val, ".")') | en
let [type, ipt, mfunc] = [s:type(1), s:ispathitem(), 'match'] let [type, ipt, mfunc] = [s:type(1), s:ispathitem(), 'match']
if s:byfname && ipt if s:byfname && ipt
let mfunc = 's:matchfname' let mfunc = 's:matchfname'
@ -319,52 +314,37 @@ fu! s:MatchedItems(items, pats, limit)
let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' } let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' }
if has_key(types, type) | let mfunc = types[type] | en if has_key(types, type) | let mfunc = types[type] | en
en en
" Loop through the patterns let newitems = s:MatchIt(items, pat, limit, mfunc)
for pat in pats
" If newitems is small, set it as items to search in
if exists('newitems') && len(newitems) < limit
let items = copy(newitems)
en
if empty(items) " End here
retu exists('newitems') ? newitems : []
el " Start here, go back up if have 2 or more in pats
" Loop through the items
let newitems = s:MatchIt(items, pat, limit, mfunc)
en
endfo
let s:matches = len(newitems) let s:matches = len(newitems)
retu newitems retu newitems
endf endf
fu! s:SplitPattern(str, ...) "{{{1 fu! s:SplitPattern(str) "{{{1
let str = s:sanstail(a:str) let str = s:sanstail(a:str)
if s:migemo && s:regexp && len(str) > 0 && executable('cmigemo') if s:migemo && s:regexp && len(str) > 0 && executable('cmigemo')
let str = s:migemo(str) let str = s:migemo(str)
en en
let s:savestr = str let s:savestr = str
if s:regexp || match(str, '\\\(<\|>\)\|[*|]') >= 0 if s:regexp || match(str, '\\\(<\|>\)\|[*|]') >= 0
let array = [s:regexfilter(str)] let pat = s:regexfilter(str)
el el
let array = split(str, '\zs') let lst = split(str, '\zs')
if exists('+ssl') && !&ssl if exists('+ssl') && !&ssl
cal map(array, 'substitute(v:val, "\\", "\\\\\\", "g")') cal map(lst, 'escape(v:val, ''\'')')
en en
" Literal ^ and $ for each in ['^', '$', '.']
for each in ['^', '$'] cal map(lst, 'escape(v:val, each)')
cal map(array, 'substitute(v:val, "\\\'.each.'", "\\\\\\'.each.'", "g")')
endfo endfo
en en
" Build the new pattern if exists('lst')
let nitem = !empty(array) ? array[0] : '' let pat = ''
let newpats = [nitem] if !empty(lst)
if len(array) > 1 let pat = lst[0]
for item in range(1, len(array) - 1) for item in range(1, len(lst) - 1)
" Separator let pat .= '[^'.lst[item - 1].']\{-}'.lst[item]
let sep = a:0 ? a:1 : '[^'.array[item-1].']\{-}' endfo
let nitem .= sep.array[item] en
cal add(newpats, nitem)
endfo
en en
retu newpats retu escape(pat, '~')
endf endf
" * BuildPrompt() {{{1 " * BuildPrompt() {{{1
fu! s:Render(lines, pat) fu! s:Render(lines, pat)
@ -392,8 +372,7 @@ fu! s:Render(lines, pat)
let s:matched = copy(lines) let s:matched = copy(lines)
cal map(lines, '"> ".v:val') cal map(lines, '"> ".v:val')
cal setline(1, lines) cal setline(1, lines)
exe 'keepj norm!' s:mwreverse ? 'G' : 'gg' exe 'keepj norm!' ( s:mwreverse ? 'G' : 'gg' ).'1|'
keepj norm! 1|
cal s:unmarksigns() cal s:unmarksigns()
cal s:remarksigns() cal s:remarksigns()
if exists('s:cline') && !exists('g:ctrlp_nolimit') if exists('s:cline') && !exists('g:ctrlp_nolimit')
@ -408,7 +387,6 @@ endf
fu! s:Update(str) fu! s:Update(str)
" Get the previous string if existed " Get the previous string if existed
let oldstr = exists('s:savestr') ? s:savestr : '' let oldstr = exists('s:savestr') ? s:savestr : ''
let pats = s:SplitPattern(a:str)
" Get the new string sans tail " Get the new string sans tail
let notail = substitute(a:str, '\\\\', '\', 'g') let notail = substitute(a:str, '\\\\', '\', 'g')
let notail = substitute(notail, '\\\@<!:\([^:]\|\\:\)*$', '', '') let notail = substitute(notail, '\\\@<!:\([^:]\|\\:\)*$', '', '')
@ -417,15 +395,16 @@ fu! s:Update(str)
if notail == oldstr && !empty(notail) && !exists('s:force') if notail == oldstr && !empty(notail) && !exists('s:force')
retu retu
en en
let pat = s:SplitPattern(a:str)
let lines = exists('g:ctrlp_nolimit') && empty(notail) ? copy(g:ctrlp_lines) let lines = exists('g:ctrlp_nolimit') && empty(notail) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, copy(pats), s:mxheight) \ : s:MatchedItems(g:ctrlp_lines, pat, s:mxheight)
cal s:Render(lines, pats[-1]) cal s:Render(lines, pat)
endf endf
fu! s:ForceUpdate() fu! s:ForceUpdate()
let [estr, prt] = ['"\', copy(s:prompt)] let [estr, prt] = ['"\', copy(s:prompt)]
cal map(prt, 'escape(v:val, estr)') cal map(prt, 'escape(v:val, estr)')
cal s:Update(join(prt, '')) sil! cal s:Update(join(prt, ''))
endf endf
fu! s:BuildPrompt(upd, ...) fu! s:BuildPrompt(upd, ...)
@ -435,7 +414,7 @@ fu! s:BuildPrompt(upd, ...)
let str = join(prt, '') let str = join(prt, '')
let lazy = empty(str) || exists('s:force') || !has('autocmd') ? 0 : s:lazy let lazy = empty(str) || exists('s:force') || !has('autocmd') ? 0 : s:lazy
if a:upd && !lazy && ( s:matches || s:regexp if a:upd && !lazy && ( s:matches || s:regexp
\ || match(str, '[*|]') >= 0 || match(str, '\\\:\([^:]\|\\:\)*$') >= 0 ) \ || match(str, '\(\\\(<\|>\)\|[*|]\)\|\(\\\:\([^:]\|\\:\)*$\)') >= 0 )
sil! cal s:Update(str) sil! cal s:Update(str)
en en
sil! cal ctrlp#statusline() sil! cal ctrlp#statusline()
@ -701,7 +680,7 @@ fu! s:PrtSwitcher()
endf endf
fu! s:SetWD(...) "{{{1 fu! s:SetWD(...) "{{{1
let pathmode = s:pathmode let pathmode = s:pathmode
if exists('a:1') && len(a:1) | if type(a:1) if exists('a:1') && strlen(a:1) | if type(a:1)
cal ctrlp#setdir(a:1) | retu cal ctrlp#setdir(a:1) | retu
el el
let pathmode = a:1 let pathmode = a:1
@ -928,13 +907,14 @@ fu! s:comparent(s1, s2)
endf endf
fu! s:matchlens(str, pat, ...) fu! s:matchlens(str, pat, ...)
if empty(a:pat) || index(['^','$'], a:pat) >= 0 | retu {} | en if empty(a:pat) || index(['^', '$'], a:pat) >= 0 | retu {} | en
let st = exists('a:1') ? a:1 : 0 let st = exists('a:1') ? a:1 : 0
let lens = exists('a:2') ? a:2 : {} let lens = exists('a:2') ? a:2 : {}
let nr = exists('a:3') ? a:3 : 0 let nr = exists('a:3') ? a:3 : 0
if match(a:str, a:pat, st) != -1 if nr > 20 | retu {} | en
if match(a:str, a:pat, st) >= 0
let [mst, mnd] = [matchstr(a:str, a:pat, st), matchend(a:str, a:pat, st)] let [mst, mnd] = [matchstr(a:str, a:pat, st), matchend(a:str, a:pat, st)]
let lens = extend(lens, { nr : [len(mst), mst] }) let lens = extend(lens, { nr : [strlen(mst), mst] })
let lens = s:matchlens(a:str, a:pat, mnd, lens, nr + 1) let lens = s:matchlens(a:str, a:pat, mnd, lens, nr + 1)
en en
retu lens retu lens
@ -1149,10 +1129,7 @@ endf
fu! s:highlight(pat, grp) fu! s:highlight(pat, grp)
cal clearmatches() cal clearmatches()
if !empty(a:pat) && s:ispathitem() if !empty(a:pat) && s:ispathitem()
let pat = substitute(a:pat, '\~', '\\~', 'g') let pat = s:regexp ? substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g') : a:pat
let pat = s:regexp
\ ? substitute(pat, '\\\@<!\^', '^> \\zs', 'g')
\ : escape(pat, '.')
" Match only filename " Match only filename
if s:byfname if s:byfname
let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g') let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g')
@ -1362,7 +1339,7 @@ fu! s:migemo(str)
let [tokens, str, cmd] = [split(str, '\s'), '', 'cmigemo -v -w %s -d %s'] let [tokens, str, cmd] = [split(str, '\s'), '', 'cmigemo -v -w %s -d %s']
for token in tokens for token in tokens
let rtn = system(printf(cmd, shellescape(token), shellescape(dict))) let rtn = system(printf(cmd, shellescape(token), shellescape(dict)))
let str .= !v:shell_error && len(rtn) > 0 ? '.*'.rtn : token let str .= !v:shell_error && strlen(rtn) > 0 ? '.*'.rtn : token
endfo endfo
en en
retu str retu str

View File

@ -137,7 +137,7 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'], \ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtHistory(-1)': ['<c-n>'], \ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'], \ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<c-m>', '<2-LeftMouse>'], \ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'], \ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>', '<MiddleMouse>'], \ 'AcceptSelection("t")': ['<c-t>', '<MiddleMouse>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'], \ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
@ -146,7 +146,7 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'ToggleByFname()': ['<c-d>'], \ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'], \ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'], \ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>', '<c-i>'], \ 'PrtExpandDir()': ['<tab>'],
\ 'PrtInsert("w")': ['<F2>', '<insert>'], \ 'PrtInsert("w")': ['<F2>', '<insert>'],
\ 'PrtInsert("s")': ['<F3>'], \ 'PrtInsert("s")': ['<F3>'],
\ 'PrtInsert("v")': ['<F4>'], \ 'PrtInsert("v")': ['<F4>'],
@ -251,7 +251,7 @@ the highlight group thatll be used: >
*'g:ctrlp_max_files'* *'g:ctrlp_max_files'*
The maximum number of files to scan, set to 0 for no limit: > The maximum number of files to scan, set to 0 for no limit: >
let g:ctrlp_max_files = 20000 let g:ctrlp_max_files = 10000
< <
*'g:ctrlp_max_depth'* *'g:ctrlp_max_depth'*
@ -693,50 +693,16 @@ Examples: >
\ } \ }
< <
===============================================================================
EXTENDING *ctrlp-extending*
Extending |CtrlP| is very simple. Simply create a vim file following a short
guidelines, place it in autoload/ctrlp/ and add its name to your .vimrc.
To see how it works, get the sample.vim from the extensions branch on the main
git repository (https://github.com/kien/ctrlp.vim/tree/extensions), and place
it along with the parent directories somewhere in your runtimepath. Then put
this into your .vimrc: >
let g:ctrlp_extensions = ['sample']
<
A new search type will show up the next time you open |CtrlP|.
For more details, check out the comments inside sample.vim.~
===============================================================================
USER-CONFIGURATION *ctrlp-user-config*
Some miscellaneous configurations:~
+) |g:ctrlp_user_command| config that makes use of your |wildignore| setting:
https://github.com/kien/ctrlp.vim/issues/70 by Rich Alesi
=============================================================================== ===============================================================================
CREDITS *ctrlp-credits* CREDITS *ctrlp-credits*
Developed by Kien Nguyen <github.com/kien>, initially based on the Command-T Developed by Kien Nguyen <github.com/kien>.
and the LustyExplorer plugins. No code was taken from these plugins, but I did
clone the majority of their (awesome) interfaces and the way they work.
This was originally written as a module for a would-be larger plugin called Projects homepage: http://kien.github.com/ctrlp.vim
AutoDoc.vim which Ive stopped developing because of lost of interest. I really
liked the way Command-T and LustyExplorer deal with users input, so I wrote a
pure Vimscript version of their prompt window, intended to use it for the
aforementioned plugin.
Homepage: http://kien.github.com/ctrlp.vim
Git repository: https://github.com/kien/ctrlp.vim Git repository: https://github.com/kien/ctrlp.vim
Mercurial repository: https://bitbucket.org/kien/ctrlp.vim Mercurial repository: https://bitbucket.org/kien/ctrlp.vim
=============================================================================== -------------------------------------------------------------------------------
THANKS *ctrlp-thanks*
Thanks to everyone that has submitted ideas, bug reports or helped debugging on Thanks to everyone that has submitted ideas, bug reports or helped debugging on
gibhub, bitbucket, and through email. gibhub, bitbucket, and through email.