-
-
Save bstaint/7834e0efedc4d1467f8e8d2dd8760a19 to your computer and use it in GitHub Desktop.
This file contains 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
" Depends | |
" asyncrun.vim | |
" vim-ingo-library | |
" | |
" example .vimproject | |
" let $VIRTUAL_ENV = ingo#fs#path#Combine(expand("%:p:h"), '.venv') | |
" function RunnerMain() | |
" " python3 -m unittest discover -v -s tests -p "*_test.py" | |
" return 'python app.py' | |
" endfunction | |
if exists("loaded_runner_plugin") | |
finish | |
endif | |
let loaded_runner_plugin = 1 | |
function! RunnerPathAppend(path) | |
if ingo#str#find#StartIndex($PATH, a:path) == -1 | |
let $PATH = a:path.';'.$PATH | |
endif | |
endfunction | |
" Load vimproject | |
function! s:RunnerLoad() | |
if filereadable(".vimproject") | |
source .vimproject | |
" echom "Load vimproject" | |
if exists("$VIRTUAL_ENV") | |
call RunnerPathAppend(ingo#fs#path#Combine($VIRTUAL_ENV, 'Scripts')) | |
endif | |
endif | |
endfunction | |
function! s:RunnerInput() | |
let cmdlist = RunnerMain() | |
if type(cmdlist) == type([]) | |
let idx = inputlist(["select run command:"] + | |
\ map(copy(cmdlist), {k,v -> (k+1).'. '.v})) - 1 | |
if idx < 0 || idx >= len(cmdlist) | |
throw 'UnknownIndex' | |
endif | |
let command = get(cmdlist, idx) | |
return command | |
elseif type(cmdlist) == type("") | |
return cmdlist | |
else | |
throw 'UnknownType' | |
endif | |
endfunction | |
" Run script | |
function! s:Runner() | |
let command = 'AsyncRun -raw -program=make %' | |
if exists("*RunnerMain") | |
try | |
let command = s:RunnerInput() | |
if command !=# "" | |
let command = 'AsyncRun -raw '.command | |
endif | |
catch /UnknownType/ | |
call ingo#msg#ErrorMsg("Unknown RunnerMain type.") | |
catch /UnknownIndex/ | |
endtry | |
endif | |
let status = !exists('g:asyncrun_status') | |
\ || g:asyncrun_status != 'running' | |
try | |
if status | |
silent exe command | |
silent 8copen | |
else | |
silent AsyncStop | |
endif | |
catch /E499/ | |
" Ignore missing scripts | |
endtry | |
endfunction | |
call s:RunnerLoad() | |
command! -nargs=0 Runner call s:Runner() | |
command! -nargs=0 RunnerLoad call s:RunnerLoad() | |
nmap <silent> <Plug>Runner :call <SID>Runner()<CR> | |
if !hasmapto('<Plug>Runner', 'n') | |
nmap <F6> <Plug>Runner | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment