123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- " "Is it possible, after sourcing ~/.exrc, to traverse from $HOME down
-
-
-
-
- " "Example: current dir is ~/a/b/c. Files are sourced in this order:
-
- " No messages if some of .exrc does not exist."
-
-
-
-
-
-
-
-
-
-
-
- " " Global stuff that needs to be updated/override
- " let g:bar = 'bar' " YES! This is a global variable!
-
- " " Local stuff that needs to be defined once for each buffer
-
-
-
-
-
-
- " " Global stuff that needs to be defined once only => functions
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- let s:k_version = 109
- if exists("g:loaded_local_vimrc")
- \ && (g:loaded_local_vimrc >= s:k_version)
- \ && !exists('g:force_reload_local_vimrc')
- finish
- endif
- let g:loaded_local_vimrc_vim = s:k_version
- let s:cpo_save=&cpo
- set cpo&vim
-
-
-
- command! -nargs=0 SourceLocalVimrc call s:Main(expand('%:p'))
-
-
-
- function! s:LocalVimrcName()
- return exists('g:local_vimrc') ? g:local_vimrc : '_vimrc_local.vim'
- endfunction
-
- let s:local_vimrc = s:LocalVimrcName()
-
-
- let s:home = substitute($HOME, '/\|\\', '[/\\\\]', 'g')
-
-
-
- let s:re_last_path = '^/\=$\|^[A-Za-z]:[/\\]\+$\|^//$\|^\\\\$'.
- \ ((s:home != '') ? ('\|^'.s:home.'$') : '')
-
-
- function! s:SourceLocal(path)
- let up_path = fnamemodify(a:path,':h')
- if up_path == '.'
- if ! isdirectory(a:path)
- call lh#common#warning_msg("[local_vimrc] The current file '".expand('%:p:')."' seems to be in a non-existant directory: '".a:path."'")
- endif
- let up_path = getcwd()
- endif
- " call confirm('crt='.a:path."\nup=".up_path."\n$HOME=
- " echomsg ('crt='.a:path."\nup=".up_path."\n$HOME=
- if (a:path !~ s:re_last_path)
- if (up_path !~ s:re_last_path)
-
- call s:SourceLocal(up_path)
- elseif filereadable(up_path.'/'.s:local_vimrc)
-
- if &verbose >= 2
- echo 'Check '.up_path.' for '.s:local_vimrc.' ... found!'
- endif
- exe 'source '.escape(up_path.'/'.s:local_vimrc, ' \$,')
- elseif &verbose >= 2
- echo 'Check '.up_path.' for '.s:local_vimrc.' ... none!'
- endif
- endif
-
-
-
- if filereadable(a:path.'/'.s:local_vimrc)
- if &verbose >= 2
- echo 'Check '.a:path.' for '.s:local_vimrc.' ... found!'
- endif
- exe 'source '.escape(a:path.'/'.s:local_vimrc, ' \$,')
- elseif &verbose >= 2
- echo 'Check '.a:path.' for '.s:local_vimrc.' ... none!'
- endif
- endfunction
-
- function! s:CheckForbiddenPath(path)
- let ok = a:path !~ '^\(s\=ftp:\|s\=http:\|scp:\|^$\)'
- return ok
- endfunction
-
- function! s:Main(path)
-
- if !s:CheckForbiddenPath(a:path)
- return
- else
- call s:SourceLocal(a:path)
- endif
- endfunction
-
-
- function! s:IncrementVersionOnSave()
- let l = search('let s:k_version', 'n')
- if l > 0
- let nl = substitute(getline(l), '\(let\s\+s:k_version\s*=\s*\)\(\d\+\)\s*$', '\=submatch(1).(1+submatch(2))', '')
- call setline(l, nl)
- endif
- endfunction
-
-
-
- aug LocalVimrc
- au!
- au BufEnter * :call s:Main(expand('<afile>:p:h'))
- exe 'au BufWritePre '.s:local_vimrc . ' call s:IncrementVersionOnSave()'
- aug END
-
-
-
- let &cpo=s:cpo_save
-
|