Created
August 24, 2016 18:47
-
-
Save deathlyfrantic/68cace55a5357571ab7ab79436cbf2f9 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
" expiremental async job running thing with status window for neovim. never quite finished it. | |
function! UnmapEscKey() | |
unmap <Esc> | |
echo '' | |
endfunction | |
" log job output to a scratch buffer | |
function! s:LogAsyncJob(job_id, data, event) | |
let cur_buf_win = bufwinnr('%') | |
let job_buf_win = bufwinnr('job_output') | |
execute job_buf_win . 'wincmd w' | |
if a:event != 'exit' | |
let str = ''.join(a:data) | |
else | |
let str = 'Job finished. Press <Esc> to delete output.' | |
execute "nnoremap <buffer> <Esc> :bw job_output<CR>:call UnmapEscKey()<CR>" | |
endif | |
call append(line('$'), str) | |
execute 'normal! G' | |
execute cur_buf_win . 'wincmd w' | |
endfunction | |
" run jobs asynchronously, sup neovim | |
function! s:RunAsyncJob(command) | |
let callbacks = { | |
\ 'on_stdout': function('s:LogAsyncJob'), | |
\ 'on_stderr': function('s:LogAsyncJob'), | |
\ 'on_exit': function('s:LogAsyncJob') | |
\ } | |
if !bufexists('job_output') | |
let savedsplitbelow = &splitbelow | |
execute '5 sp job_output' | |
setlocal buftype=nofile bufhidden=hide noswapfile | |
autocmd QuitPre <buffer> bd job_output | |
let &splitbelow = savedsplitbelow | |
endif | |
let job = jobstart(a:command, callbacks) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment