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

View File

@ -12,7 +12,7 @@ let [g:loaded_ctrlp_rtscript, g:ctrlp_newrts] = [1, 0]
let s:rtscript_var = {
\ 'init': 'ctrlp#rtscript#init()',
\ 'accept': 'ctrlp#rtscript#accept',
\ 'accept': 'ctrlp#acceptfile',
\ 'lname': 'runtime scripts',
\ 'sname': 'rts',
\ '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)
" Public {{{1
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...')
let entries = split(globpath(&rtp, '**/*.*'), "\n")
cal filter(entries, 'index(entries, v:val, v:key + 1) < 0')
cal map(entries, 'fnamemodify(v:val, '':.'')')
let [g:ctrlp_rtscache, g:ctrlp_newrts] = [ctrlp#dirnfile(entries)[1], 0]
let [entries, echoed] = [ctrlp#dirnfile(entries)[1], 1]
el
let [entries, results] = g:ctrlp_rtscache[2:3]
en
retu g:ctrlp_rtscache
endf
fu! ctrlp#rtscript#accept(mode, str)
cal ctrlp#acceptfile(a:mode, a:str)
let cwd = getcwd()
if g:ctrlp_newrts
\ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, cwd] )
if !exists('echoed') | sil! cal ctrlp#progress('Processing...') | en
let results = map(copy(entries), 'fnamemodify(v:val, '':.'')')
en
let [g:ctrlp_rtscache, g:ctrlp_newrts] = [[&rtp, cwd, entries, results], 0]
retu results
endf
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
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*
@ -77,8 +77,8 @@ Set the maximum height of the match window: >
<
*'g:ctrlp_jump_to_buffer'*
When opening a file, if it's already opened somewhere |CtrlP| will try to jump
to it instead of opening a new window or new tab: >
When opening a file with <cr> or <c-t>, if the file's already opened somewhere
|CtrlP| will try to jump to it instead of opening a new instance: >
let g:ctrlp_jump_to_buffer = 2
<
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.
*'g:ctrlp_working_path_mode'*
When starting up the prompt, temporarily set the working directory (i.e. the
|current-directory|) to:
When starting up, |CtrlP| sets its local working directory according to this
variable: >
let g:ctrlp_working_path_mode = 2
<
1 - the parent directory of the current file.
2 - the nearest ancestor that contains one of these directories/files:
.git/
@ -96,9 +98,6 @@ When starting up the prompt, temporarily set the working directory (i.e. the
_darcs/
root.dir
0 - dont manage working directory.
>
let g:ctrlp_working_path_mode = 2
<
*'g:ctrlp_root_markers'*
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 = ['']
<
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'*
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|.
*'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: >
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
<bs>. So if pressing <bs> moves the cursor to the left instead of deleting a
char for you, add this to your |vimrc| to change the default <c-h> mapping: >
<bs> (|key-codes|). So if pressing <bs> moves the cursor to the left instead of
deleting a char for you, add this to your |vimrc| to change the default <c-h>
mapping: >
let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<bs>', '<c-]>', '<c-h>'],
\ '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
<
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\* " 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
|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|.
*'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.
*'g:ctrlp_user_command'*
Specify an external tool to use for listing files instead of Vims globpath().
Use %s in place of the target directory: >
Specify an external tool to use for listing files instead of using Vims
|globpath()|. Use %s in place of the target directory: >
let g:ctrlp_user_command = ''
<
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)
v - open in vertical split(s)
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
|g:ctrlp_open_multi|.
@ -401,10 +402,11 @@ See https://gist.github.com/1610859 for a working example.
:ClearCtrlPCache
Flush the cache for the current working directory. The same as pressing <F5>
inside |CtrlP|.
You can also enable/disable caching with the option |g:ctrlp_use_caching|.
*: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
@ -438,7 +440,7 @@ Once inside the prompt:~
See also |input-formats| (guide) and |g:ctrlp_regexp_search| (option).
<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 '>>>')
<c-f>, 'forward'
@ -529,14 +531,18 @@ Once inside the prompt:~
<F7>
Clear MRU list.
<insert>
Insert the word under the cursor (in the active buffer) into the prompt.
<esc>,
<c-c>,
<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|.
When inside the match window (press <tab> to switch):~
When inside the match window (press <s-tab> to switch):~
a-z
0-9
@ -643,7 +649,7 @@ Available extensions:~
* Runtime script mode:~
- Name: 'rtscript'
- Command: ':CtrlPRTS'
- Search for files (vimscripts, docs...) in runtimepath.
- Search for files (vimscripts, docs, snippets...) in runtimepath.
-------------------------------------------------------------------------------
Buffer Tag mode options:~