comparison vim/autoload/ctrlpext/autoignore.vim @ 199:4e276e0cdd98

Better auto-ignore for CtrlP.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 18 Aug 2014 17:12:08 -0700
parents ae53d68033d9
children
comparison
equal deleted inserted replaced
198:5a898e1ffbe3 199:4e276e0cdd98
29 function! ctrlpext#autoignore#init() abort 29 function! ctrlpext#autoignore#init() abort
30 if !exists('g:ctrlp_custom_ignore') 30 if !exists('g:ctrlp_custom_ignore')
31 let g:ctrlp_custom_ignore = {} 31 let g:ctrlp_custom_ignore = {}
32 endif 32 endif
33 let g:ctrlp_custom_ignore['func'] = 'ctrlpext#autoignore#ignore' 33 let g:ctrlp_custom_ignore['func'] = 'ctrlpext#autoignore#ignore'
34 let g:ctrlp_custom_ignore['func-init'] = 'ctrlpext#autoignore#ignore_init'
34 endfunction 35 endfunction
35 36
36 " List patterns for a given project's root. 37 " List patterns for a given project's root.
37 function! ctrlpext#autoignore#get_patterns(root_dir) abort 38 function! ctrlpext#autoignore#get_patterns(root_dir) abort
38 let l:patterns = s:get_project_patterns(a:root_dir) 39 let l:patterns = s:get_project_patterns(a:root_dir)
51 echom "ctrlp_autoignore: " . a:message 52 echom "ctrlp_autoignore: " . a:message
52 endif 53 endif
53 endfunction 54 endfunction
54 55
55 let s:proj_cache = {} 56 let s:proj_cache = {}
57 let s:active_patterns = []
56 58
57 function! s:load_project_patterns(root_dir) abort 59 function! s:load_project_patterns(root_dir) abort
58 let l:ign_path = a:root_dir . '/.ctrlpignore' 60 let l:ign_path = a:root_dir . '/.ctrlpignore'
59 if !filereadable(l:ign_path) 61 if !filereadable(l:ign_path)
60 call s:trace("No pattern file at: " . l:ign_path) 62 call s:trace("No pattern file at: " . l:ign_path)
88 endfunction 90 endfunction
89 91
90 " The custom ignore function that CtrlP will be using in addition to 92 " The custom ignore function that CtrlP will be using in addition to
91 " normal pattern-based matching. 93 " normal pattern-based matching.
92 function! ctrlpext#autoignore#ignore(item, type) abort 94 function! ctrlpext#autoignore#ignore(item, type) abort
93 let l:root = getcwd() 95 for pat in s:active_patterns
94 let l:patterns = s:get_project_patterns(l:root)
95 for pat in l:patterns
96 if pat['type'] == '' || pat['type'] == a:type 96 if pat['type'] == '' || pat['type'] == a:type
97 if match(a:item, pat['pat']) >= 0 97 if match(a:item, pat['pat']) >= 0
98 return 1 98 return 1
99 endif 99 endif
100 endif 100 endif
101 endfor 101 endfor
102 return 0 102 return 0
103 endfunction 103 endfunction
104 104
105 function! ctrlpext#autoignore#ignore_init() abort
106 let l:root = getcwd()
107 let s:active_patterns = s:get_project_patterns(l:root)
108 endfunction
109
105 " }}} 110 " }}}
106 111