Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add ability to specify a custom ignore function, instead of just patterns #594

Closed
wants to merge 2 commits into from

2 participants

@ludovicchabant

This makes it possible to customize the ignore patterns on a per-project basis... I do that by loading patterns for a given project from a ".ctrlpignore" file at the root of the project. Generally you don't need this, but for some codebases where the directory structure is not so clean, you kinda have to.

@d11wtq

Yes! I totally want this :)

@ludovicchabant

You may want to see how I use it with my auto-ignore script (you just need to activate it with a ctrlpext#autoignore#init() in your vimrc) and an example of a .ctrlpignore file. Cheers :)

(after I play around with it more, I may release that auto-ignore script as a standalone Vim plugin)

@ludovicchabant

Also, it's not very optimal right now (1 map lookup + 1 regex match per directory). I'll need to modify some more CtrlP code to fix that (probably some "before/after scan" hooks, so I can do only 1 map lookup for the whole project).

@d11wtq

Moved to ctrlpvim#16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 3 deletions.
  1. +18 −3 autoload/ctrlp.vim
  2. +9 −0 doc/ctrlp.txt
View
21 autoload/ctrlp.vim
@@ -343,6 +343,7 @@ fu! ctrlp#files()
" Get the list of files
if empty(lscmd)
if !ctrlp#igncwd(s:dyncwd)
+ cal s:InitCustomFuncs()
cal s:GlobPath(s:fnesc(s:dyncwd, 'g', ','), 0)
en
el
@@ -369,6 +370,12 @@ fu! ctrlp#files()
retu g:ctrlp_allfiles
endf
+fu! s:InitCustomFuncs()
+ if has_key(s:usrign, 'func-init') && s:usrign['func-init'] != ''
+ exe call(s:usrign['func-init'], [])
+ en
+endf
+
fu! s:GlobPath(dirs, depth)
let entries = split(globpath(a:dirs, s:glob), "\n")
let [dnf, depth] = [ctrlp#dirnfile(entries), a:depth + 1]
@@ -1532,9 +1539,17 @@ fu! ctrlp#dirnfile(entries)
endf
fu! s:usrign(item, type)
- retu s:igntype == 1 ? a:item =~ s:usrign
- \ : s:igntype == 4 && has_key(s:usrign, a:type) && s:usrign[a:type] != ''
- \ ? a:item =~ s:usrign[a:type] : 0
+ if s:igntype == 1 | retu a:item =~ s:usrign | end
+ if s:igntype == 4
+ if has_key(s:usrign, a:type) && s:usrign[a:type] != ''
+ \ && a:item =~ s:usrign[a:type]
+ retu 1
+ elsei has_key(s:usrign, 'func') && s:usrign['func'] != ''
+ \ && call(s:usrign['func'], [a:item, a:type])
+ retur 1
+ end
+ end
+ retu 0
endf
fu! s:samerootsyml(each, isfile, cwd)
View
9 doc/ctrlp.txt
@@ -261,6 +261,9 @@ Examples: >
let g:ctrlp_custom_ignore = {
\ 'file': '\v(\.cpp|\.h|\.hh|\.cxx)@<!$'
\ }
+ let g:ctrlp_custom_ignore = {
+ \ 'func': 'some#custom#match_function'
+ \ }
<
Note #1: by default, |wildignore| and |g:ctrlp_custom_ignore| only apply when
|globpath()| is used to scan for files, thus these options do not apply when a
@@ -269,6 +272,12 @@ command defined with |g:ctrlp_user_command| is being used.
Note #2: when changing the option's variable type, remember to |:unlet| it
first or restart Vim to avoid the "E706: Variable type mismatch" error.
+Note #3: when using the "func" ignore type, you must provide the full name of
+a function that can be called from CtrlP. An |autoload| function name is
+recommended here. The function must take 2 parameters, the item to match and
+its type. The type will be "dir", "file", or "link". The function must return
+1 if the item should be ignored, 0 otherwise.
+
*'g:ctrlp_max_files'*
The maximum number of files to scan, set to 0 for no limit: >
let g:ctrlp_max_files = 10000
Something went wrong with that request. Please try again.