Skip to content

Commit 2f3055e

Browse files
Add ability to specify a custom ignore function, instead of just patterns.
1 parent b5d3fe6 commit 2f3055e

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
@@ -1532,9 +1532,17 @@ fu! ctrlp#dirnfile(entries)
15321532
endf
15331533

15341534
fu! s:usrign(item, type)
1535-
retu s:igntype == 1 ? a:item =~ s:usrign
1536-
\ : s:igntype == 4 && has_key(s:usrign, a:type) && s:usrign[a:type] != ''
1537-
\ ? a:item =~ s:usrign[a:type] : 0
1535+
if s:igntype == 1 | retu a:item =~ s:usrign | end
1536+
if s:igntype == 4
1537+
if has_key(s:usrign, a:type) && s:usrign[a:type] != ''
1538+
\ && a:item =~ s:usrign[a:type]
1539+
retu 1
1540+
elsei has_key(s:usrign, 'func') && s:usrign['func'] != ''
1541+
\ && call(s:usrign['func'], [a:item, a:type])
1542+
retur 1
1543+
end
1544+
end
1545+
retu 0
15381546
endf
15391547

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

doc/ctrlp.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ Examples: >
261261
let g:ctrlp_custom_ignore = {
262262
\ 'file': '\v(\.cpp|\.h|\.hh|\.cxx)@<!$'
263263
\ }
264+
let g:ctrlp_custom_ignore = {
265+
\ 'func': 'some#custom#match_function'
266+
\ }
264267
<
265268
Note #1: by default, |wildignore| and |g:ctrlp_custom_ignore| only apply when
266269
|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.
269272
Note #2: when changing the option's variable type, remember to |:unlet| it
270273
first or restart Vim to avoid the "E706: Variable type mismatch" error.
271274

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

0 commit comments

Comments
 (0)