Created
December 18, 2013 23:51
-
-
Save qickstarter/8031905 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:get_gem_paths() " {{{ | |
if !exists('s:gem_path') | |
let s:gem_path = {} | |
endif | |
let project_dir = s:V.path2project_directory(getcwd()) | |
if !has_key(s:gem_path, project_dir) | |
let result = system('bundle show --paths') | |
if result =~ 'Could not locate Gemfile' | |
let s:gem_path[project_dir] = [] | |
else | |
let s:gem_path[project_dir] = map(split(result, '\n'), 'v:val . "/lib"') | |
endif | |
endif | |
return s:gem_path[project_dir] | |
endfunction " }}} | |
function! s:build_path(path) "{{{ | |
let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',') | |
if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$' | |
let path = substitute(&g:path,',,$',',','') . ',' . path | |
endif | |
return path | |
endfunction"}}} | |
function! s:set_gem_paths() "{{{ | |
let gem_paths = join(s:get_gem_paths(), ',') | |
if stridx(&l:path, gem_paths) == -1 | |
execute 'setlocal path+=' . gem_paths | |
endif | |
endfunction"}}} | |
function! s:get_vital() "{{{ | |
if !exists('s:V') | |
if exists('*neocomplete#util#get_vital') | |
let s:V = neocomplete#util#get_vital() | |
elseif exists('*unite#util#get_vital') | |
let s:V = unite#util#get_vital() | |
elseif exists('*vital#of') | |
let s:V = vital#of('vital') | |
else | |
echomsg 'vital.vim is not found!!' | |
endif | |
endif | |
return s:V | |
endfunction"}}} | |
function! s:load_gem_paths() "{{{ | |
if !empty(s:get_vital()) | |
call s:set_gem_paths() | |
endif | |
if exists('s:loaded_gem_paths') | |
return | |
endif | |
let s:loaded_gem_paths = 1 | |
augroup GemPath | |
autocmd! | |
autocmd FileType Rakefile,ruby call s:set_gem_paths() | |
augroup END | |
endfunction"}}} | |
command! LoadGem call s:load_gem_paths() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment