Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created December 14, 2012 04:29
Show Gist options
  • Select an option

  • Save draftcode/4282703 to your computer and use it in GitHub Desktop.

Select an option

Save draftcode/4282703 to your computer and use it in GitHub Desktop.
Use virtualenv python if available
" quickrun: hook/virtualenv: Use virtualenv python if available
" Author: draftcode <[email protected]>
" License: zlib License
let s:save_cpo = &cpo
set cpo&vim
let s:hook = {
\ 'config': {
\ 'enable': 0,
\ 'venv_dirname': 'env',
\ },
\ }
let s:Filepath = g:quickrun#V.System.Filepath
function! s:hook.on_module_loaded(session, context)
let l:dir = s:Filepath.dirname(a:session.config.srcfile)
while l:dir !=# s:Filepath.dirname(l:dir)
let l:venv_python = s:Filepath.join(l:dir,
\ [self.config.venv_dirname, 'bin', 'python'])
if filereadable(l:venv_python)
let a:session.config.command = l:venv_python
endif
let l:dir = s:Filepath.dirname(l:dir)
endwhile
endfunction
function! quickrun#hook#virtualenv#new()
return deepcopy(s:hook)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment