Custom ignore and default command options

* Extend jump-to-open-buffer to use <c-t> when jump_to_buffer = 2.
  Only works for buffers opened in another tab.  Suggested by @hail2u.
* Add g:ctrlp_default_cmd, option to reuse the default mapping for a
  different command.  Close #57.
* Add g:ctrlp_custom_ignore.  Close #58.
This commit is contained in:
Kien N 2011-12-18 09:58:44 +07:00
parent 0bd17c4462
commit 64dca5ec79
4 changed files with 146 additions and 109 deletions

View File

@ -11,13 +11,14 @@ fu! s:opts()
let opts = { let opts = {
\ 'g:ctrlp_by_filename': ['s:byfname', 0], \ 'g:ctrlp_by_filename': ['s:byfname', 0],
\ 'g:ctrlp_clear_cache_on_exit': ['s:clrex', 1], \ 'g:ctrlp_clear_cache_on_exit': ['s:clrex', 1],
\ 'g:ctrlp_custom_ignore': ['s:usrign', ''],
\ 'g:ctrlp_dont_split': ['s:nosplit', ''], \ 'g:ctrlp_dont_split': ['s:nosplit', ''],
\ 'g:ctrlp_dotfiles': ['s:dotfiles', 1], \ 'g:ctrlp_dotfiles': ['s:dotfiles', 1],
\ 'g:ctrlp_extensions': ['s:extensions', []], \ 'g:ctrlp_extensions': ['s:extensions', []],
\ 'g:ctrlp_follow_symlinks': ['s:folsym', 0], \ 'g:ctrlp_follow_symlinks': ['s:folsym', 0],
\ 'g:ctrlp_highlight_match': ['s:mathi', [1, 'Identifier']], \ 'g:ctrlp_highlight_match': ['s:mathi', [1, 'Identifier']],
\ 'g:ctrlp_lazy_update': ['s:lazy', 0], \ 'g:ctrlp_lazy_update': ['s:lazy', 0],
\ 'g:ctrlp_jump_to_buffer': ['s:jmptobuf', 1], \ 'g:ctrlp_jump_to_buffer': ['s:jmptobuf', 2],
\ '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],
@ -126,23 +127,67 @@ fu! ctrlp#reset()
unl! s:cline unl! s:cline
endf endf
" * Files() {{{1 " * Files() {{{1
fu! s:Files()
let [cwd, cache_file] = [getcwd(), ctrlp#utils#cachefile()]
if g:ctrlp_newcache || !filereadable(cache_file) || !s:caching
let lscmd = s:lsCmd()
" Get the list of files
if empty(lscmd)
cal s:GlobPath(cwd, [], 0)
el
sil! cal ctrlp#progress('Indexing...')
try | cal s:UserCmd(cwd, lscmd) | cat | retu [] | endt
en
" Remove base directory
cal ctrlp#rmbasedir(g:ctrlp_allfiles)
let read_cache = 0
el
let g:ctrlp_allfiles = ctrlp#utils#readfile(cache_file)
let read_cache = 1
en
if len(g:ctrlp_allfiles) <= s:compare_lim
cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
en
cal s:writecache(read_cache, cache_file)
retu g:ctrlp_allfiles
endf
fu! s:GlobPath(dirs, allfiles, depth) fu! s:GlobPath(dirs, allfiles, depth)
let entries = split(globpath(a:dirs, s:glob), "\n") let entries = split(globpath(a:dirs, s:glob), "\n")
if !s:folsym if s:usrign != ''
let entries = filter(entries, 'getftype(v:val) != "link"') cal filter(entries, 'v:val !~ s:usrign')
en en
let g:ctrlp_allfiles = filter(copy(entries), '!isdirectory(v:val)') let [dirs, g:ctrlp_allfiles] = s:DirAndFile(copy(entries))
let ftrfunc = s:dotfiles ? 'ctrlp#dirfilter(v:val)' : 'isdirectory(v:val)'
let alldirs = filter(entries, ftrfunc)
cal extend(g:ctrlp_allfiles, a:allfiles, 0) cal extend(g:ctrlp_allfiles, a:allfiles, 0)
let depth = a:depth + 1 let depth = a:depth + 1
if !empty(alldirs) && !s:maxfiles(len(g:ctrlp_allfiles)) && depth <= s:maxdepth if !empty(dirs) && !s:maxf(len(g:ctrlp_allfiles)) && depth <= s:maxdepth
sil! cal ctrlp#progress(len(g:ctrlp_allfiles)) sil! cal ctrlp#progress(len(g:ctrlp_allfiles))
cal s:GlobPath(join(alldirs, ','), g:ctrlp_allfiles, depth) cal s:GlobPath(join(dirs, ','), g:ctrlp_allfiles, depth)
en en
endf endf
fu! s:UserCommand(path, lscmd) fu! s:DirAndFile(entries)
let items = [[], []]
for each in a:entries
let etype = getftype(each)
if etype == 'dir'
if s:dotfiles | if match(each, '[\/]\.\{,2}$') < 0
cal add(items[0], each)
en | el
cal add(items[0], each)
en
el
if s:folsym
cal add(items[1], each)
el | if etype != 'link'
cal add(items[1], each)
en | en
en
endfo
retu items
endf
fu! s:UserCmd(path, lscmd)
let path = a:path let path = a:path
if exists('+ssl') && &ssl if exists('+ssl') && &ssl
let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')] let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')]
@ -158,29 +203,21 @@ fu! s:UserCommand(path, lscmd)
en en
endf endf
fu! s:Files() fu! s:lsCmd()
let [cwd, cache_file] = [getcwd(), ctrlp#utils#cachefile()] let cmd = s:usrcmd
if g:ctrlp_newcache || !filereadable(cache_file) || !s:caching if type(cmd) == 1
let lscmd = s:lscommand() retu cmd
" Get the list of files elsei type(cmd) == 3 && len(cmd) >= 2 && !empty(cmd[0]) && !empty(cmd[1])
if empty(lscmd) let rmarker = cmd[0]
cal s:GlobPath(cwd, [], 0) " Find a repo root
el cal s:findroot(getcwd(), rmarker, 0, 1)
sil! cal ctrlp#progress('Waiting...') if !exists('s:vcsroot') || ( exists('s:vcsroot') && empty(s:vcsroot) )
try | cal s:UserCommand(cwd, lscmd) | cat | retu [] | endt " Try the secondary_command
retu len(cmd) == 3 ? cmd[2] : ''
en en
" Remove base directory let s:vcscmd = s:lash == '\' ? 1 : 0
cal ctrlp#rmbasedir(g:ctrlp_allfiles) retu cmd[1]
let read_cache = 0
el
let g:ctrlp_allfiles = ctrlp#utils#readfile(cache_file)
let read_cache = 1
en en
if len(g:ctrlp_allfiles) <= s:compare_lim
cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
en
cal s:writecache(read_cache, cache_file)
retu g:ctrlp_allfiles
endf endf
fu! s:Buffers() "{{{1 fu! s:Buffers() "{{{1
let allbufs = [] let allbufs = []
@ -669,19 +706,19 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
let filpath = s:itemtype ? matchstr : getcwd().s:lash.matchstr let filpath = s:itemtype ? matchstr : getcwd().s:lash.matchstr
cal s:PrtExit() cal s:PrtExit()
let bufnum = bufnr(filpath) let bufnum = bufnr(filpath)
if s:jmptobuf && bufnum > 0 && (md == 'e' || md == 't') if s:jmptobuf && bufnum > 0 && md =~ 'e\|t'
let [jmpb, bufwinnr] = [1, bufwinnr(bufnum)] let [jmpb, bufwinnr] = [1, bufwinnr(bufnum)]
let buftab = s:jmptobuf > 1 ? s:buftab(bufnum) : [0, 0] let buftab = s:jmptobuf > 1 ? s:buftab(bufnum, md) : [0, 0]
let j2l = a:0 ? a:1 : str2nr(matchstr(s:tail(), '^ +\zs\d\+$')) let j2l = a:0 ? a:1 : str2nr(matchstr(s:tail(), '^ +\zs\d\+$'))
en en
" Switch to existing buffer or open new one " Switch to existing buffer or open new one
if exists('jmpb') && buftab[0] if exists('jmpb') && bufwinnr > 0 && md != 't'
exe 'tabn' buftab[1]
exe buftab[0].'winc w'
if j2l | cal s:j2l(j2l) | en
elsei exists('jmpb') && bufwinnr > 0
exe bufwinnr.'winc w' exe bufwinnr.'winc w'
if j2l | cal s:j2l(j2l) | en if j2l | cal s:j2l(j2l) | en
elsei exists('jmpb') && buftab[0]
exe 'tabn' buftab[0]
exe buftab[1].'winc w'
if j2l | cal s:j2l(j2l) | en
el el
" Determine the command to use " Determine the command to use
let cmd = md == 't' || s:splitwin == 1 ? 'tabe' let cmd = md == 't' || s:splitwin == 1 ? 'tabe'
@ -692,8 +729,31 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
en en
endf endf
fu! s:SpecInputs()
let str = join(s:prompt, '')
let type = s:itemtype > 2 ?
\ g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )][3] : s:itemtype
if str == '..' && type =~ '0\|dir'
cal s:parentdir(getcwd())
cal s:SetLines(s:itemtype)
cal s:PrtClear()
retu 1
elsei ( str == '/' || str == '\' ) && type =~ '0\|dir'
cal s:SetWD(2, 0)
cal s:SetLines(s:itemtype)
cal s:PrtClear()
retu 1
elsei str == '?'
cal s:PrtExit()
let hlpwin = &columns > 159 ? '| vert res 80' : ''
sil! exe 'bo vert h ctrlp-mappings' hlpwin '| norm! 0'
retu 1
en
retu 0
endf
fu! s:AcceptSelection(mode) fu! s:AcceptSelection(mode)
if a:mode == 'e' | if s:specinputs() | retu | en | en if a:mode == 'e' | if s:SpecInputs() | retu | en | en
" Get the selected line " Get the selected line
let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$') let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$')
if empty(matchstr) | retu | en if empty(matchstr) | retu | en
@ -885,10 +945,6 @@ fu! ctrlp#progress(len)
redr redr
endf endf
" Paths {{{2 " Paths {{{2
fu! ctrlp#dirfilter(val)
retu isdirectory(a:val) && match(a:val, '[\/]\.\{,2}$') < 0 ? 1 : 0
endf
fu! s:ispathitem() fu! s:ispathitem()
let ext = s:itemtype - ( g:ctrlp_builtins + 1 ) let ext = s:itemtype - ( g:ctrlp_builtins + 1 )
if s:itemtype < 3 || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext][3] == 'dir' ) if s:itemtype < 3 || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext][3] == 'dir' )
@ -1051,14 +1107,14 @@ fu! s:vacantdict(dict)
retu filter(range(1, max(keys(a:dict))), '!has_key(a:dict, v:val)') retu filter(range(1, max(keys(a:dict))), '!has_key(a:dict, v:val)')
endf endf
" Buffers {{{2 " Buffers {{{2
fu! s:buftab(bufnum) fu! s:buftab(bufnum, md)
for nr in range(1, tabpagenr('$')) for tabnr in range(1, tabpagenr('$'))
let buflist = tabpagebuflist(nr) if tabpagenr() == tabnr && a:md == 't' | con | en
if match(buflist, a:bufnum) >= 0 let buflist = tabpagebuflist(tabnr)
let [buftabnr, tabwinnrs] = [nr, tabpagewinnr(nr, '$')] if index(buflist, a:bufnum) >= 0
for ewin in range(1, tabwinnrs) for winnr in range(1, tabpagewinnr(tabnr, '$'))
if buflist[ewin - 1] == a:bufnum if buflist[winnr - 1] == a:bufnum
retu [ewin, buftabnr] retu [tabnr, winnr]
en en
endfo endfo
en en
@ -1136,29 +1192,6 @@ fu! s:sanstail(str)
retu str retu str
endf endf
" Misc {{{2 " Misc {{{2
fu! s:specinputs()
let str = join(s:prompt, '')
let type = s:itemtype > 2 ?
\ g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )][3] : s:itemtype
if str == '..' && type =~ '0\|dir'
cal s:parentdir(getcwd())
cal s:SetLines(s:itemtype)
cal s:PrtClear()
retu 1
elsei ( str == '/' || str == '\' ) && type =~ '0\|dir'
cal s:SetWD(2, 0)
cal s:SetLines(s:itemtype)
cal s:PrtClear()
retu 1
elsei str == '?'
cal s:PrtExit()
let hlpwin = &columns > 159 ? '| vert res 80' : ''
sil! exe 'bo vert h ctrlp-mappings' hlpwin '| norm! 0'
retu 1
en
retu 0
endf
fu! s:lastvisual() fu! s:lastvisual()
let cview = winsaveview() let cview = winsaveview()
let [ovreg, ovtype] = [getreg('v'), getregtype('v')] let [ovreg, ovtype] = [getreg('v'), getregtype('v')]
@ -1228,7 +1261,7 @@ fu! s:matchtab(item, pat)
retu match(split(a:item, '\t\+[^\t]\+$')[0], a:pat) retu match(split(a:item, '\t\+[^\t]\+$')[0], a:pat)
endf endf
fu! s:maxfiles(len) fu! s:maxf(len)
retu s:maxfiles && a:len > s:maxfiles ? 1 : 0 retu s:maxfiles && a:len > s:maxfiles ? 1 : 0
endf endf
@ -1248,23 +1281,6 @@ fu! s:insertcache(str)
cal insert(data, str, pos) cal insert(data, str, pos)
cal s:writecache(0, ctrlp#utils#cachefile()) cal s:writecache(0, ctrlp#utils#cachefile())
endf endf
fu! s:lscommand()
let cmd = s:usrcmd
if type(cmd) == 1
retu cmd
elsei type(cmd) == 3 && len(cmd) >= 2 && !empty(cmd[0]) && !empty(cmd[1])
let rmarker = cmd[0]
" Find a repo root
cal s:findroot(getcwd(), rmarker, 0, 1)
if !exists('s:vcsroot') || ( exists('s:vcsroot') && empty(s:vcsroot) )
" Try the secondary_command
retu len(cmd) == 3 ? cmd[2] : ''
en
let s:vcscmd = s:lash == '\' ? 1 : 0
retu cmd[1]
en
endf
" Extensions {{{2 " Extensions {{{2
fu! s:tagfiles() fu! s:tagfiles()
retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)') retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)')

View File

@ -17,6 +17,7 @@ let s:ars = [
\ 's:maxfiles', \ 's:maxfiles',
\ 's:compare_lim', \ 's:compare_lim',
\ 's:glob', \ 's:glob',
\ 's:usrign',
\ ] \ ]
let s:dir_var = ['ctrlp#dir#init('.join(s:ars, ', ').')', 'ctrlp#dir#accept', let s:dir_var = ['ctrlp#dir#init('.join(s:ars, ', ').')', 'ctrlp#dir#accept',
@ -30,9 +31,12 @@ let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
fu! s:globdirs(dirs, depth) fu! s:globdirs(dirs, depth)
let entries = split(globpath(a:dirs, s:glob), "\n") let entries = split(globpath(a:dirs, s:glob), "\n")
if !s:folsym if !s:folsym
let entries = filter(entries, 'getftype(v:val) != "link"') cal filter(entries, 'getftype(v:val) != "link"')
en en
let ftrfunc = s:dotfiles ? 'ctrlp#dirfilter(v:val)' : 'isdirectory(v:val)' if s:usrign != ''
cal filter(entries, 'v:val !~ s:usrign')
en
let ftrfunc = s:dotfiles ? 's:dirfilter(v:val)' : 'isdirectory(v:val)'
let alldirs = filter(entries, ftrfunc) let alldirs = filter(entries, ftrfunc)
cal extend(g:ctrlp_alldirs, alldirs) cal extend(g:ctrlp_alldirs, alldirs)
let depth = a:depth + 1 let depth = a:depth + 1
@ -43,6 +47,10 @@ fu! s:globdirs(dirs, depth)
en en
endf endf
fu! s:dirfilter(val)
retu isdirectory(a:val) && match(a:val, '[\/]\.\{,2}$') < 0 ? 1 : 0
endf
fu! s:max(len, max) fu! s:max(len, max)
retu a:max && a:len > a:max ? 1 : 0 retu a:max && a:len > a:max ? 1 : 0
endf endf

View File

@ -23,9 +23,9 @@ CONTENTS *ctrlp-contents*
=============================================================================== ===============================================================================
1. Intro *ctrlp-intro* 1. Intro *ctrlp-intro*
Full path fuzzy file, buffer and MRU file finder with an intuitive interface. Full path fuzzy file, buffer, mru and tag finder with an intuitive interface.
Written in pure Vimscript for MacVim and Vim version 7.0+. Has full support for Written in pure Vimscript for MacVim and Vim version 7.0+. Has full support for
Vims |regexp| as search pattern, built-in MRU 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, quickfix, dir...), see |ctrlp-extensions|.
@ -40,8 +40,13 @@ Use this option to change the mapping to invoke |CtrlP| in |Normal| mode: >
let g:ctrlp_map = '<c-p>' let g:ctrlp_map = '<c-p>'
< <
*'g:ctrlp_cmd'*
Set the default opening command to use when pressing the above mapping: >
let g:ctrlp_cmd = 'CtrlP'
<
*'g:loaded_ctrlp'* *'g:loaded_ctrlp'*
Use this option to disable the plugin completely: > Use this to disable the plugin completely: >
let g:loaded_ctrlp = 1 let g:loaded_ctrlp = 1
< <
@ -72,9 +77,10 @@ Set the maximum height of the match window: >
< <
*'g:ctrlp_jump_to_buffer'* *'g:ctrlp_jump_to_buffer'*
Set this to 0 to disable the jump-to-open-buffer feature. Set to 2 to also jump Set this to 0 to disable the jump-to-open-buffer feature.
tab if the selected buffers opened in another tab: > Set to 2 to also jump tab if the selected buffers opened in another tab.
let g:ctrlp_jump_to_buffer = 1 Set to 1 to only jump to it if its opened in the current tab: >
let g:ctrlp_jump_to_buffer = 2
< <
*'g:ctrlp_working_path_mode'* *'g:ctrlp_working_path_mode'*
@ -192,21 +198,24 @@ MRU entries: >
Set this to 0 if you dont want |CtrlP| to search for dotfiles and dotdirs: > 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 also use |'wildignore'| to exclude anything from the search. You can use |'wildignore'| to exclude anything from the search.
e.g. exclude version control directories from the results: > e.g. exclude 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
< <
Note: the `*/` in front of each dotfile glob is required for the dotfiles Note: the `*/` in front of each glob is required.
search feature to work correctly along side with |wildignore|. If youve
disabled dotfiles search (set |g:ctrlp_dotfiles| to 0), then you can ignore
this.
Other note: |wildignore| influences the result of |expand()|, |globpath()| and Other note: |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'*
In addition to |'wildignore'|, use this for files and directories you want only
|CtrlP| to not show. Use |regexp| to specify the pattern: >
let g:ctrlp_custom_ignore = ''
<
*'g:ctrlp_highlight_match'* *'g:ctrlp_highlight_match'*
Use this to enable/disable highlighting of the matched patterns and to specify Use this to enable/disable highlighting of the matched patterns and to specify
the highlight group thatll be used: > the highlight group thatll be used: >
@ -491,7 +500,7 @@ d) Type exactly two dots '..' at the start of the prompt and press enter to go
backward in the directory tree by 1 level. If the parent directory is backward in the directory tree by 1 level. If the parent directory is
large, this might be slow. large, this might be slow.
e) Similarly submit '/' or '\' to find and go to the projects root. If the e) Similarly, submit '/' or '\' to find and go to the projects root. If the
project is large, using a VCS listing command to look for files might help project is large, using a VCS listing command to look for files might help
speeding up the intial scan (see |g:ctrlp_user_command| for more details). speeding up the intial scan (see |g:ctrlp_user_command| for more details).
@ -590,6 +599,9 @@ Special thanks:~
=============================================================================== ===============================================================================
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*
+ New options: |g:ctrlp_cmd|,
|g:ctrlp_custom_ignore|
Before 2011/11/30~ Before 2011/11/30~
+ New features: Tag, Quickfix and Directory extensions. + New features: Tag, Quickfix and Directory extensions.

View File

@ -11,6 +11,7 @@ en
let [g:loaded_ctrlp, g:ctrlp_lines, g:ctrlp_allfiles] = [1, [], []] let [g:loaded_ctrlp, g:ctrlp_lines, g:ctrlp_allfiles] = [1, [], []]
if !exists('g:ctrlp_map') | let g:ctrlp_map = '<c-p>' | en if !exists('g:ctrlp_map') | let g:ctrlp_map = '<c-p>' | en
if !exists('g:ctrlp_cmd') | let g:ctrlp_cmd = 'CtrlP' | en
com! -na=? -comp=custom,ctrlp#cpl CtrlP cal ctrlp#init(0, <q-args>) com! -na=? -comp=custom,ctrlp#cpl CtrlP cal ctrlp#init(0, <q-args>)
@ -25,7 +26,7 @@ com! CtrlPCurWD cal ctrlp#init(0, 0)
com! CtrlPCurFile cal ctrlp#init(0, 1) com! CtrlPCurFile cal ctrlp#init(0, 1)
com! CtrlPRoot cal ctrlp#init(0, 2) com! CtrlPRoot cal ctrlp#init(0, 2)
exe 'nn <silent>' g:ctrlp_map ':<c-u>CtrlP<cr>' exe 'nn <silent>' g:ctrlp_map ':<c-u>'.g:ctrlp_cmd.'<cr>'
cal ctrlp#mrufiles#init() cal ctrlp#mrufiles#init()