Skip to content

Commit

Permalink
allow for lists of regex patterns for black and whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
kaHaleMaKai committed Jun 6, 2016
1 parent 9436437 commit f2da5cc
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions plugin/localvimrc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,25 @@ endif
" define default "localvimrc_whitelist" {{{2
" copy to script local variable to prevent .lvimrc modifying the whitelist.
if (!exists("g:localvimrc_whitelist"))
let s:localvimrc_whitelist = "^$" " This never matches a file
let s:localvimrc_whitelist = ["^$"] " This never matches a file
else
let s:localvimrc_whitelist = g:localvimrc_whitelist
if type(g:localvimrc_whitelist) == type("")
let s:localvimrc_whitelist = [g:localvimrc_whitelist]
else
let s:localvimrc_whitelist = g:localvimrc_whitelist
endif
endif

" define default "localvimrc_blacklist" {{{2
" copy to script local variable to prevent .lvimrc modifying the blacklist.
if (!exists("g:localvimrc_blacklist"))
let s:localvimrc_blacklist = "^$" " This never matches a file
let s:localvimrc_blacklist = ["^$"] " This never matches a file
else
let s:localvimrc_blacklist = g:localvimrc_blacklist
if type(g:localvimrc_blacklist) == type("")
let s:localvimrc_blacklist = [g:localvimrc_blacklist]
else
let s:localvimrc_blacklist = g:localvimrc_blacklist
endif
endif

" define default "localvimrc_persistent" {{{2
Expand Down Expand Up @@ -152,6 +160,15 @@ if has("autocmd")
augroup END
endif

function! s:MatchAny(str, patterns)
for pattern in a:patterns
if match(a:str, pattern) > -1
return 1
endif
endfor
return 0
endfunc

" Section: Functions {{{1

" Function: s:LocalVimRC() {{{2
Expand Down Expand Up @@ -246,15 +263,15 @@ function! s:LocalVimRC()

" check if whitelisted
if (l:rcfile_load == "unknown")
if (match(l:rcfile, s:localvimrc_whitelist) != -1)
if s:MatchAny(l:rcfile, s:localvimrc_whitelist)
call s:LocalVimRCDebug(2, l:rcfile . " is whitelisted")
let l:rcfile_load = "yes"
endif
endif

" check if blacklisted
if (l:rcfile_load == "unknown")
if (match(l:rcfile, s:localvimrc_blacklist) != -1)
if s:MatchAny(l:rcfile, s:localvimrc_blacklist)
call s:LocalVimRCDebug(2, l:rcfile . " is blacklisted")
let l:rcfile_load = "no"
endif
Expand Down

0 comments on commit f2da5cc

Please sign in to comment.