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_reversed': ['s:mwreverse', 1],
\ '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_history': ['s:maxhst', hst],
\ 'g:ctrlp_open_multi': ['s:opmul', '1v'],
@ -66,7 +66,7 @@ fu! s:opts()
\ 'PrtSelectMove("d")': ['<PageDown>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ '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("t")': ['<c-t>', '<MiddleMouse>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
@ -75,7 +75,7 @@ fu! s:opts()
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>', '<c-i>'],
\ 'PrtExpandDir()': ['<tab>'],
\ 'PrtInsert("w")': ['<F2>', '<insert>'],
\ 'PrtInsert("s")': ['<F3>'],
\ 'PrtInsert("v")': ['<F4>'],
@ -126,7 +126,7 @@ cal s:opts()
let s:lash = ctrlp#utils#lash()
" Limiters
let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000]
let [s:compare_lim, s:nocache_lim] = [3000, 4000]
" Regexp
let s:fpats = {
@ -298,20 +298,15 @@ endf
fu! s:MatchIt(items, pat, limit, mfunc)
let newitems = []
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
endfo
retu newitems
endf
fu! s:MatchedItems(items, pats, limit)
let [items, pats, limit] = [a:items, a:pats, 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
fu! s:MatchedItems(items, pat, limit)
let [items, pat, limit] = [a:items, a:pat, a:limit]
let [type, ipt, mfunc] = [s:type(1), s:ispathitem(), 'match']
if s:byfname && ipt
let mfunc = 's:matchfname'
@ -319,52 +314,37 @@ fu! s:MatchedItems(items, pats, limit)
let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' }
if has_key(types, type) | let mfunc = types[type] | en
en
" Loop through the patterns
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 newitems = s:MatchIt(items, pat, limit, mfunc)
let s:matches = len(newitems)
retu newitems
endf
fu! s:SplitPattern(str, ...) "{{{1
fu! s:SplitPattern(str) "{{{1
let str = s:sanstail(a:str)
if s:migemo && s:regexp && len(str) > 0 && executable('cmigemo')
let str = s:migemo(str)
en
let s:savestr = str
if s:regexp || match(str, '\\\(<\|>\)\|[*|]') >= 0
let array = [s:regexfilter(str)]
let pat = s:regexfilter(str)
el
let array = split(str, '\zs')
let lst = split(str, '\zs')
if exists('+ssl') && !&ssl
cal map(array, 'substitute(v:val, "\\", "\\\\\\", "g")')
cal map(lst, 'escape(v:val, ''\'')')
en
" Literal ^ and $
for each in ['^', '$']
cal map(array, 'substitute(v:val, "\\\'.each.'", "\\\\\\'.each.'", "g")')
for each in ['^', '$', '.']
cal map(lst, 'escape(v:val, each)')
endfo
en
" Build the new pattern
let nitem = !empty(array) ? array[0] : ''
let newpats = [nitem]
if len(array) > 1
for item in range(1, len(array) - 1)
" Separator
let sep = a:0 ? a:1 : '[^'.array[item-1].']\{-}'
let nitem .= sep.array[item]
cal add(newpats, nitem)
endfo
if exists('lst')
let pat = ''
if !empty(lst)
let pat = lst[0]
for item in range(1, len(lst) - 1)
let pat .= '[^'.lst[item - 1].']\{-}'.lst[item]
endfo
en
en
retu newpats
retu escape(pat, '~')
endf
" * BuildPrompt() {{{1
fu! s:Render(lines, pat)
@ -392,8 +372,7 @@ fu! s:Render(lines, pat)
let s:matched = copy(lines)
cal map(lines, '"> ".v:val')
cal setline(1, lines)
exe 'keepj norm!' s:mwreverse ? 'G' : 'gg'
keepj norm! 1|
exe 'keepj norm!' ( s:mwreverse ? 'G' : 'gg' ).'1|'
cal s:unmarksigns()
cal s:remarksigns()
if exists('s:cline') && !exists('g:ctrlp_nolimit')
@ -408,7 +387,6 @@ endf
fu! s:Update(str)
" Get the previous string if existed
let oldstr = exists('s:savestr') ? s:savestr : ''
let pats = s:SplitPattern(a:str)
" Get the new string sans tail
let notail = substitute(a:str, '\\\\', '\', 'g')
let notail = substitute(notail, '\\\@<!:\([^:]\|\\:\)*$', '', '')
@ -417,15 +395,16 @@ fu! s:Update(str)
if notail == oldstr && !empty(notail) && !exists('s:force')
retu
en
let pat = s:SplitPattern(a:str)
let lines = exists('g:ctrlp_nolimit') && empty(notail) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, copy(pats), s:mxheight)
cal s:Render(lines, pats[-1])
\ : s:MatchedItems(g:ctrlp_lines, pat, s:mxheight)
cal s:Render(lines, pat)
endf
fu! s:ForceUpdate()
let [estr, prt] = ['"\', copy(s:prompt)]
cal map(prt, 'escape(v:val, estr)')
cal s:Update(join(prt, ''))
sil! cal s:Update(join(prt, ''))
endf
fu! s:BuildPrompt(upd, ...)
@ -435,7 +414,7 @@ fu! s:BuildPrompt(upd, ...)
let str = join(prt, '')
let lazy = empty(str) || exists('s:force') || !has('autocmd') ? 0 : s:lazy
if a:upd && !lazy && ( s:matches || s:regexp
\ || match(str, '[*|]') >= 0 || match(str, '\\\:\([^:]\|\\:\)*$') >= 0 )
\ || match(str, '\(\\\(<\|>\)\|[*|]\)\|\(\\\:\([^:]\|\\:\)*$\)') >= 0 )
sil! cal s:Update(str)
en
sil! cal ctrlp#statusline()
@ -701,7 +680,7 @@ fu! s:PrtSwitcher()
endf
fu! s:SetWD(...) "{{{1
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
el
let pathmode = a:1
@ -928,13 +907,14 @@ fu! s:comparent(s1, s2)
endf
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 lens = exists('a:2') ? a:2 : {}
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 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)
en
retu lens
@ -1149,10 +1129,7 @@ endf
fu! s:highlight(pat, grp)
cal clearmatches()
if !empty(a:pat) && s:ispathitem()
let pat = substitute(a:pat, '\~', '\\~', 'g')
let pat = s:regexp
\ ? substitute(pat, '\\\@<!\^', '^> \\zs', 'g')
\ : escape(pat, '.')
let pat = s:regexp ? substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g') : a:pat
" Match only filename
if s:byfname
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']
for token in tokens
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
en
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>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ '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("t")': ['<c-t>', '<MiddleMouse>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
@ -146,7 +146,7 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>', '<c-i>'],
\ 'PrtExpandDir()': ['<tab>'],
\ 'PrtInsert("w")': ['<F2>', '<insert>'],
\ 'PrtInsert("s")': ['<F3>'],
\ 'PrtInsert("v")': ['<F4>'],
@ -251,7 +251,7 @@ the highlight group thatll be used: >
*'g:ctrlp_max_files'*
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'*
@ -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*
Developed by Kien Nguyen <github.com/kien>, initially based on the Command-T
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.
Developed by Kien Nguyen <github.com/kien>.
This was originally written as a module for a would-be larger plugin called
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
Projects homepage: http://kien.github.com/ctrlp.vim
Git repository: https://github.com/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
gibhub, bitbucket, and through email.