I have a job I want to run in the background of vim, and update my status line with the periodic results of that job.
I'm able to setup the timer, call the external job and get my response back. I'm able to echom
the response and see it in :messages
.
I am unable to get my global variable to take hold of the new value though.
Here is the vimscript:
let g:please_vim_why = 'an echo example'
let g:why_vim_why = -1
function! TimerRun(timer)
call jobstart('date', {'on_stdout': 'TimerCallback'})
endfunction
function! TimerCallback(j, d, e)
echom a:d[0]
let g:why_vim_why = a:d[0]
endfunction
let timer = timer_start(2000, 'TimerRun', {'repeat': -1})
Run via nvim -u godwhyvimwhydoyouhateme.vim
to load it as your vimrc.
Now if you go :echo g:please_vim_why
, you'll see the response, 'an echo example'.
If you run :messages
, you'll see a repeated output of the date.
If you run :echo g:why_vim_why
you will see no output.
I thought maybe it might be a:d
is scoped and gets garbage collected after the function, but let g:why_vim_why = 'not a good joke' . a:d[0]
, sets the variable to 'not a good joke' but doesn't concatenate anything.
Why VIM? Why?
job_start
instead ofjobstart
).