Some bugfixes

* Remove \zs, \ze as regexp-mode auto-triggers.
* Fix #116. Remove the full-path auto-switching feature. Refs #98.
* Proper caching for rtscript extension.
* Add <PageUp>, <PageDown> keymaps (used for quickfix and undo).
This commit is contained in:
Kien N 2012-01-29 00:29:09 +07:00
parent d0714ff6fd
commit 2d90da985d
3 changed files with 59 additions and 48 deletions

View File

@ -62,6 +62,8 @@ fu! s:opts()
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'], \ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtSelectMove("t")': ['<home>'], \ 'PrtSelectMove("t")': ['<home>'],
\ 'PrtSelectMove("b")': ['<end>'], \ 'PrtSelectMove("b")': ['<end>'],
\ 'PrtSelectMove("u")': ['<PageUp>'],
\ '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>', '<c-m>', '<2-LeftMouse>'],
@ -291,7 +293,7 @@ fu! s:MatchIt(items, pat, limit, mfunc)
retu newitems retu newitems
endf endf
fu! s:MatchedItems(items, pats, limit, bfn) fu! s:MatchedItems(items, pats, limit)
let [items, pats, limit] = [a:items, a:pats, a: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 items is longer than s:mltipats_lim, use only the last pattern
if len(items) >= s:mltipats_lim || ( exists('s:height') && s:height > 20 ) if len(items) >= s:mltipats_lim || ( exists('s:height') && s:height > 20 )
@ -300,7 +302,7 @@ fu! s:MatchedItems(items, pats, limit, bfn)
cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")') cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")')
if !s:regexp | cal map(pats, 'escape(v:val, ".")') | en 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 && a:bfn if s:byfname && ipt
let mfunc = 's:matchfname' let mfunc = 's:matchfname'
elsei s:itemtype > 2 elsei s:itemtype > 2
let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' } let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' }
@ -328,7 +330,7 @@ fu! s:SplitPattern(str, ...) "{{{1
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, '\\\(zs\|ze\|<\|>\)\|[*|]') >= 0 if s:regexp || match(str, '\\\(<\|>\)\|[*|]') >= 0
let array = [s:regexfilter(str)] let array = [s:regexfilter(str)]
el el
let array = split(str, '\zs') let array = split(str, '\zs')
@ -354,7 +356,7 @@ fu! s:SplitPattern(str, ...) "{{{1
retu newpats retu newpats
endf endf
" * BuildPrompt() {{{1 " * BuildPrompt() {{{1
fu! s:Render(lines, pat, bfn) fu! s:Render(lines, pat)
let lines = a:lines let lines = a:lines
" Setup the match window " Setup the match window
let s:height = min([len(lines), s:mxheight]) let s:height = min([len(lines), s:mxheight])
@ -388,7 +390,7 @@ fu! s:Render(lines, pat, bfn)
en en
" Highlighting " Highlighting
if s:dohighlight() if s:dohighlight()
cal s:highlight(a:pat, s:mathi[1] == '' ? 'Identifier' : s:mathi[1], a:bfn) cal s:highlight(a:pat, s:mathi[1] == '' ? 'Identifier' : s:mathi[1])
en en
endf endf
@ -404,13 +406,9 @@ 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 bfn = s:byfname && notail != '' && match(notail, '\v/|\\:@!') < 0
if s:byfname && s:regexp && match(notail, '\\:\@!') >= 0
let bfn = s:byfname
en
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, bfn) \ : s:MatchedItems(g:ctrlp_lines, copy(pats), s:mxheight)
cal s:Render(lines, pats[-1], bfn) cal s:Render(lines, pats[-1])
endf endf
fu! s:ForceUpdate() fu! s:ForceUpdate()
@ -541,8 +539,9 @@ fu! s:PrtCurEnd()
endf endf
fu! s:PrtSelectMove(dir) fu! s:PrtSelectMove(dir)
let torb = { 't': 'gg', 'b': 'G' } let wht = winheight(0)
exe 'keepj norm!' ( a:dir =~ '^[tb]$' ? torb[a:dir] : a:dir ) let dirs = {'t': 'gg','b': 'G','j': 'j','k': 'k','u': wht.'k','d': wht.'j'}
exe 'keepj norm!' dirs[a:dir]
if !exists('g:ctrlp_nolimit') | let s:cline = line('.') | en if !exists('g:ctrlp_nolimit') | let s:cline = line('.') | en
if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en
endf endf
@ -906,8 +905,9 @@ endf
fu! s:comparent(s1, s2) fu! s:comparent(s1, s2)
" By same parent dir " By same parent dir
if match(s:crfpath, escape(getcwd(), '.^$*\')) >= 0 let cwd = getcwd()
let [as1, as2] = [fnamemodify(a:s1, ':p'), fnamemodify(a:s2, ':p')] if match(s:crfpath, escape(cwd, '.^$*\')) >= 0
let [as1, as2] = [cwd.s:lash().a:s1, cwd.s:lash().a:s2]
let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)] let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)]
if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en
if loc2 == s:crfpath && loc1 != s:crfpath | retu 1 | en if loc2 == s:crfpath && loc1 != s:crfpath | retu 1 | en
@ -1131,7 +1131,7 @@ fu! s:syntax()
en en
endf endf
fu! s:highlight(pat, grp, bfn) 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 = substitute(a:pat, '\~', '\\~', 'g')
@ -1139,7 +1139,7 @@ fu! s:highlight(pat, grp, bfn)
\ ? substitute(pat, '\\\@<!\^', '^> \\zs', 'g') \ ? substitute(pat, '\\\@<!\^', '^> \\zs', 'g')
\ : escape(pat, '.') \ : escape(pat, '.')
" Match only filename " Match only filename
if s:byfname && a:bfn if s:byfname
let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g') let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g')
let pat = substitute(pat, '$', '\\ze[^\\/]*$', 'g') let pat = substitute(pat, '$', '\\ze[^\\/]*$', 'g')
en en

View File

@ -12,7 +12,7 @@ let [g:loaded_ctrlp_rtscript, g:ctrlp_newrts] = [1, 0]
let s:rtscript_var = { let s:rtscript_var = {
\ 'init': 'ctrlp#rtscript#init()', \ 'init': 'ctrlp#rtscript#init()',
\ 'accept': 'ctrlp#rtscript#accept', \ 'accept': 'ctrlp#acceptfile',
\ 'lname': 'runtime scripts', \ 'lname': 'runtime scripts',
\ 'sname': 'rts', \ 'sname': 'rts',
\ 'type': 'path', \ 'type': 'path',
@ -24,18 +24,23 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Public {{{1 " Public {{{1
fu! ctrlp#rtscript#init() fu! ctrlp#rtscript#init()
if g:ctrlp_newrts || !exists('g:ctrlp_rtscache') if g:ctrlp_newrts
\ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[0] == &rtp )
sil! cal ctrlp#progress('Indexing...') sil! cal ctrlp#progress('Indexing...')
let entries = split(globpath(&rtp, '**/*.*'), "\n") let entries = split(globpath(&rtp, '**/*.*'), "\n")
cal filter(entries, 'index(entries, v:val, v:key + 1) < 0') cal filter(entries, 'index(entries, v:val, v:key + 1) < 0')
cal map(entries, 'fnamemodify(v:val, '':.'')') let [entries, echoed] = [ctrlp#dirnfile(entries)[1], 1]
let [g:ctrlp_rtscache, g:ctrlp_newrts] = [ctrlp#dirnfile(entries)[1], 0] el
let [entries, results] = g:ctrlp_rtscache[2:3]
en en
retu g:ctrlp_rtscache let cwd = getcwd()
endf if g:ctrlp_newrts
\ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, cwd] )
fu! ctrlp#rtscript#accept(mode, str) if !exists('echoed') | sil! cal ctrlp#progress('Processing...') | en
cal ctrlp#acceptfile(a:mode, a:str) let results = map(copy(entries), 'fnamemodify(v:val, '':.'')')
en
let [g:ctrlp_rtscache, g:ctrlp_newrts] = [[&rtp, cwd, entries, results], 0]
retu results
endf endf
fu! ctrlp#rtscript#id() fu! ctrlp#rtscript#id()

View File

@ -28,7 +28,7 @@ Written in pure Vimscript for MacVim and Vim version 7.0+. Has full support for
Vims |regexp| as search pattern, built-in MRU files monitoring, projects root Vims |regexp| as search pattern, built-in MRU files monitoring, projects root
finder, and more. finder, and more.
To enable optional extensions (tag, quickfix, dir...), see |ctrlp-extensions|. To enable optional extensions (tag, dir, rtscript...), see |ctrlp-extensions|.
=============================================================================== ===============================================================================
2. Options *ctrlp-options* 2. Options *ctrlp-options*
@ -77,8 +77,8 @@ Set the maximum height of the match window: >
< <
*'g:ctrlp_jump_to_buffer'* *'g:ctrlp_jump_to_buffer'*
When opening a file, if it's already opened somewhere |CtrlP| will try to jump When opening a file with <cr> or <c-t>, if the file's already opened somewhere
to it instead of opening a new window or new tab: > |CtrlP| will try to jump to it instead of opening a new instance: >
let g:ctrlp_jump_to_buffer = 2 let g:ctrlp_jump_to_buffer = 2
< <
1 - only jump to the buffer if its opened in the current tab. 1 - only jump to the buffer if its opened in the current tab.
@ -86,8 +86,10 @@ to it instead of opening a new window or new tab: >
0 - disable this feature. 0 - disable this feature.
*'g:ctrlp_working_path_mode'* *'g:ctrlp_working_path_mode'*
When starting up the prompt, temporarily set the working directory (i.e. the When starting up, |CtrlP| sets its local working directory according to this
|current-directory|) to: variable: >
let g:ctrlp_working_path_mode = 2
<
1 - the parent directory of the current file. 1 - the parent directory of the current file.
2 - the nearest ancestor that contains one of these directories/files: 2 - the nearest ancestor that contains one of these directories/files:
.git/ .git/
@ -96,9 +98,6 @@ When starting up the prompt, temporarily set the working directory (i.e. the
_darcs/ _darcs/
root.dir root.dir
0 - dont manage working directory. 0 - dont manage working directory.
>
let g:ctrlp_working_path_mode = 2
<
*'g:ctrlp_root_markers'* *'g:ctrlp_root_markers'*
Use this to set your own root markers in addition to the default ones. Your Use this to set your own root markers in addition to the default ones. Your
@ -106,7 +105,7 @@ markers will take precedence: >
let g:ctrlp_root_markers = [''] let g:ctrlp_root_markers = ['']
< <
These markers (builtins and yours) will serve as identifiers for the '/' and These markers (builtins and yours) will serve as identifiers for the '/' and
'\' special inputs (section 5.e) '\' special inputs (section 5.e).
*'g:ctrlp_use_caching'* *'g:ctrlp_use_caching'*
Set this to 0 to disable per-session caching. When disabled, caching will still Set this to 0 to disable per-session caching. When disabled, caching will still
@ -116,7 +115,7 @@ be enabled for directories that have more than 4000 files: >
Note: you can quickly purge the cache by pressing <F5> while inside |CtrlP|. Note: you can quickly purge the cache by pressing <F5> while inside |CtrlP|.
*'g:ctrlp_clear_cache_on_exit'* *'g:ctrlp_clear_cache_on_exit'*
Set this to 0 to enable cross-sessions caching by not clearing the cache files Set this to 0 to enable cross-session caching by not deleting the cache files
upon exiting Vim: > upon exiting Vim: >
let g:ctrlp_clear_cache_on_exit = 1 let g:ctrlp_clear_cache_on_exit = 1
< <
@ -165,8 +164,9 @@ only need to keep the lines that youve changed the values (inside []): >
\ } \ }
< <
Note: In some terminals, its not possible to remap <c-h> without also changing Note: In some terminals, its not possible to remap <c-h> without also changing
<bs>. So if pressing <bs> moves the cursor to the left instead of deleting a <bs> (|key-codes|). So if pressing <bs> moves the cursor to the left instead of
char for you, add this to your |vimrc| to change the default <c-h> mapping: > deleting a char for you, add this to your |vimrc| to change the default <c-h>
mapping: >
let g:ctrlp_prompt_mappings = { let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<bs>', '<c-]>', '<c-h>'], \ 'PrtBS()': ['<bs>', '<c-]>', '<c-h>'],
\ 'PrtCurLeft()': ['<left>', '<c-^>'], \ 'PrtCurLeft()': ['<left>', '<c-^>'],
@ -217,7 +217,8 @@ Set this to 0 if you dont want |CtrlP| to search for dotfiles and dotdirs: >
let g:ctrlp_dotfiles = 1 let g:ctrlp_dotfiles = 1
< <
You can use |'wildignore'| to exclude anything from the search. You can use |'wildignore'| to exclude anything from the search.
e.g. exclude version control directories: > Examples: >
" Excluding version control directories
set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " Linux/MacOSX set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " Linux/MacOSX
set wildignore+=.git\*,.hg\*,.svn\* " Windows set wildignore+=.git\*,.hg\*,.svn\* " Windows
< <
@ -225,7 +226,7 @@ Note #1: the `*/` in front of each directory glob is required.
Note #2: |wildignore| influences the result of |expand()|, |globpath()| and Note #2: |wildignore| influences the result of |expand()|, |globpath()| and
|glob()| which many plugins use to find stuff on the system (e.g. fugitive.vim |glob()| which many plugins use to find stuff on the system (e.g. fugitive.vim
looks for .git/, some other plugins look for external exe tools on Windows). looks for .git/, some other plugins look for external .exe tools on Windows).
So be a little mindful of what you put in your |wildignore|. So be a little mindful of what you put in your |wildignore|.
*'g:ctrlp_custom_ignore'* *'g:ctrlp_custom_ignore'*
@ -260,8 +261,8 @@ The maximum depth of a directory tree to recurse into: >
Note: the larger these values, the more memory Vim uses. Note: the larger these values, the more memory Vim uses.
*'g:ctrlp_user_command'* *'g:ctrlp_user_command'*
Specify an external tool to use for listing files instead of Vims globpath(). Specify an external tool to use for listing files instead of using Vims
Use %s in place of the target directory: > |globpath()|. Use %s in place of the target directory: >
let g:ctrlp_user_command = '' let g:ctrlp_user_command = ''
< <
Examples: > Examples: >
@ -332,7 +333,7 @@ Pressing <c-o> or <c-y> will then prompt for a keypress. The key can be:
h - open in horizontal split(s) h - open in horizontal split(s)
v - open in vertical split(s) v - open in vertical split(s)
r - open in current window (for <c-y> only) r - open in current window (for <c-y> only)
<esc>, <c-c> - cancel and go back to |CtrlP| <esc>, <c-c> - cancel and go back to the prompt.
Any other key - use the behavior specified with |g:ctrlp_open_new_file| and Any other key - use the behavior specified with |g:ctrlp_open_new_file| and
|g:ctrlp_open_multi|. |g:ctrlp_open_multi|.
@ -401,10 +402,11 @@ See https://gist.github.com/1610859 for a working example.
:ClearCtrlPCache :ClearCtrlPCache
Flush the cache for the current working directory. The same as pressing <F5> Flush the cache for the current working directory. The same as pressing <F5>
inside |CtrlP|. inside |CtrlP|.
You can also enable/disable caching with the option |g:ctrlp_use_caching|.
*:ClearAllCtrlPCaches* *:ClearAllCtrlPCaches*
:ClearAllCtrlPCaches :ClearAllCtrlPCaches
Delete all the cache files saved in |ctrlp_cache_dir|. Delete all the cache files saved in |g:ctrlp_cache_dir|.
*:ResetCtrlP* *:ResetCtrlP*
:ResetCtrlP :ResetCtrlP
@ -438,7 +440,7 @@ Once inside the prompt:~
See also |input-formats| (guide) and |g:ctrlp_regexp_search| (option). See also |input-formats| (guide) and |g:ctrlp_regexp_search| (option).
<c-d> <c-d>
Toggle between full path search and filename only search. Toggle between full-path search and filename only search.
(note: in filename mode, the prompts base is '>d>' instead of '>>>') (note: in filename mode, the prompts base is '>d>' instead of '>>>')
<c-f>, 'forward' <c-f>, 'forward'
@ -529,14 +531,18 @@ Once inside the prompt:~
<F7> <F7>
Clear MRU list. Clear MRU list.
<insert>
Insert the word under the cursor (in the active buffer) into the prompt.
<esc>, <esc>,
<c-c>, <c-c>,
<c-g> <c-g>
Exit |CtrlP|. <c-c> can also be used to stop the scan. Exit |CtrlP|.
<c-c> can also be used to stop the scan if its taking too long.
Choose your own mappings with |g:ctrlp_prompt_mappings|. Choose your own mappings with |g:ctrlp_prompt_mappings|.
When inside the match window (press <tab> to switch):~ When inside the match window (press <s-tab> to switch):~
a-z a-z
0-9 0-9
@ -643,7 +649,7 @@ Available extensions:~
* Runtime script mode:~ * Runtime script mode:~
- Name: 'rtscript' - Name: 'rtscript'
- Command: ':CtrlPRTS' - Command: ':CtrlPRTS'
- Search for files (vimscripts, docs...) in runtimepath. - Search for files (vimscripts, docs, snippets...) in runtimepath.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Buffer Tag mode options:~ Buffer Tag mode options:~