Skip to content

Commit 474d81d

Browse files
committed
Merge pull request #16 from ludovicchabant/custom_ignore_func
Add ability to specify a custom ignore function, instead of just patterns
2 parents b94d8b4 + 2f3055e commit 474d81d

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

autoload/ctrlp.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,9 +1526,17 @@ fu! ctrlp#dirnfile(entries)
15261526
endf
15271527

15281528
fu! s:usrign(item, type)
1529-
retu s:igntype == 1 ? a:item =~ s:usrign
1530-
\ : s:igntype == 4 && has_key(s:usrign, a:type) && s:usrign[a:type] != ''
1531-
\ ? a:item =~ s:usrign[a:type] : 0
1529+
if s:igntype == 1 | retu a:item =~ s:usrign | end
1530+
if s:igntype == 4
1531+
if has_key(s:usrign, a:type) && s:usrign[a:type] != ''
1532+
\ && a:item =~ s:usrign[a:type]
1533+
retu 1
1534+
elsei has_key(s:usrign, 'func') && s:usrign['func'] != ''
1535+
\ && call(s:usrign['func'], [a:item, a:type])
1536+
retur 1
1537+
end
1538+
end
1539+
retu 0
15321540
endf
15331541

15341542
fu! s:samerootsyml(each, isfile, cwd)

doc/ctrlp.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ Examples: >
260260
let g:ctrlp_custom_ignore = {
261261
\ 'file': '\v(\.cpp|\.h|\.hh|\.cxx)@<!$'
262262
\ }
263+
let g:ctrlp_custom_ignore = {
264+
\ 'func': 'some#custom#match_function'
265+
\ }
263266
<
264267
Note #1: by default, |wildignore| and |g:ctrlp_custom_ignore| only apply when
265268
|globpath()| is used to scan for files, thus these options do not apply when a
@@ -268,6 +271,12 @@ command defined with |g:ctrlp_user_command| is being used.
268271
Note #2: when changing the option's variable type, remember to |:unlet| it
269272
first or restart Vim to avoid the "E706: Variable type mismatch" error.
270273

274+
Note #3: when using the "func" ignore type, you must provide the full name of
275+
a function that can be called from CtrlP. An |autoload| function name is
276+
recommended here. The function must take 2 parameters, the item to match and
277+
its type. The type will be "dir", "file", or "link". The function must return
278+
1 if the item should be ignored, 0 otherwise.
279+
271280
*'g:ctrlp_max_files'*
272281
The maximum number of files to scan, set to 0 for no limit: >
273282
let g:ctrlp_max_files = 10000

0 commit comments

Comments
 (0)