Open man9ourah opened 4 years ago
I would very much like this, I am trying to lazyload vim-gfm-syntax
only for markdown files in git repositories that are being pushed to github.
function! s:CheckIfGithub()
let cwd = getcwd()
let parent_dir = expand('%:p:h')
exe 'cd ' . parent_dir
" call asyncrun#run('', {'mode': 'async', 'cwd': '<root>', 'raw': 1},'git remote show origin | grep "Push URL" | grep "github.com/" | wc -l')
let github = system('git remote show origin | grep "Push URL" | grep "github.com/" | wc -l')
exe 'cd ' . cwd
" if in a git repo
if !v:shell_error && github > 0
packadd vim-gfm-syntax
let b:gfm_syntax_enable = 1
let g:gfm_syntax_enable_always = 0
let g:markdown_fenced_languages = ['cpp', 'ruby', 'json']
endif
endfunction
I'd basically like to replace system
with a non-blocking version of it.
+1 for adding the callback function and more flexible API. /cc @skywind3000
For now one can use autocmd events which would triggered when job finished:
let g:AsyncGitCallback = 'echom g:asyncrun_status' " vim command, or use call()
augroup AsyncRunEvents
autocmd!
autocmd User AsyncRunStop exec g:AsyncGitCallback
augroup END
Useful variables to use here:
g:asyncrun_status
(either running
, success
, or failure
) : To know whether the job has succeed or not, one can read the variable. g:asyncrun_info
: the current running commandline string. Usually the args
argument to asyncrun#run()
function.But this has many downsides because the callback should be defined as a global variable/function (i.e. it's not per job). Also it seems we cannot access the information/context of the ran job. As can seen in s:AsyncRun_Job_OnFinish
, all the job information is private (s:...
scope variables).
See also: https://github.com/skywind3000/asyncrun.vim/wiki/Display-Progress-in-Status-Line-or-Airline
Hello,
Thanks for an Awesome plugin!
Is there a way to specify a callback function that will be called with the command output as an argument after the command finishes. Probably passing
Funcref
as an argument toasyncrun#run
.For example, something like:
call asyncrun#run("", {"callback": "g:AsyncGitCallback"}, cmd)
Then,
function g:AsyncGitCallback(output)
should be called with the argumentoutput
being the command output.I feel it is more straightforward and suitable than having to read the quickfix in the callback function using
post=call\ AsyncGitCallback()
Thanks!