Skip to content

Commit

Permalink
Merge branch 'kaHaleMaKai-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
embear committed Jun 6, 2016
2 parents 9436437 + e942707 commit 450ead1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ Example:
``` {.vim}
" whitelist all local vimrc files in users project foo and bar
let g:localvimrc_whitelist='/home/user/projects/\(foo\|bar\)/.*'
" you can also use lists of patterns
let g:localvimrc_whitelist=['/home/user/project1/', '/opt/project2/', '/usr/local/projects/vim-[^/]*/']
```

- Default: No whitelist
Expand All @@ -219,6 +221,8 @@ Example:
``` {.vim}
" blacklist all local vimrc files in shared project directory
let g:localvimrc_blacklist='/share/projects/.*'
" you can also use lists of patterns
let g:localvimrc_whitelist=['/share/projects/.*', '/usr/share/other-projects/.*']
```

- Default: No blacklist
Expand Down
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 450ead1

Please sign in to comment.