2

CASE 1:

Have your autocmd command be setup like this:

autocmd User ALELintPost call SayHello() " ALELintPost is async

And your SayHello function set up like this

function! SayHello() abort
    echo "Hello World!"
endfunction

The function correctly executes, but the message isn't echoed.

CASE 2:

function! SayHello2() abort
    echo "Hello World!"
endfunction

function! SayHello() abort
    let timer=timer_start(500, { timer -> execute('call SayHello2()') }) " Or however you wanna call, really... It doesn't work
endfunction

Also doesn't work.


There is a library called Echodoc who seems to be dedicated to printing stuff there (it's also a plugin). It uses the typical echo methods like I'm currently trying to.

https://github.com/Shougo/echodoc.vim/blob/master/autoload/echodoc.vim#L200

Perhaps it's able to echo directly because the methods aren't asynchronous?

Is there some register/buffer/place I can write to in order to cheat this?

Or am I doing something wrong?

Please let me know!


I found out a solution and posted the answer below.

  • timer_start is invalid syntax. you must use call timer_start( because it is a function – Mass Aug 12 '18 at 17:42
  • Thanks @Mass but that wasn't it. That code I posted there was just a snippet I wrote by hand for exemplifying purposes. Still, thanks for trying to help! – resolritter Aug 13 '18 at 3:20
0

The solution for my case is to use Vim's sandbox command.

http://vimdoc.sourceforge.net/htmldoc/eval.html#sandbox

I don't know how it works internally, but it solves my problem.

function! SayHello2()
    let g:GLOBAL_VAR='WORKS!' " Sandboxed functions accesses the global context normally
    echo "Hello World!"
endfunction

function! SayHello()
    sandbox call SayHello2()
endfunction

autocmd User ALELintPost call SayHello()

As it can be seen in the example above, you can still access the global scope, execute commands and perform most "function stuff" inside of the sandboxed context.

However, since Vim claims it controls the evaluation's side-effects in some way, it might not work exactly as a regular function call for every single case. It works for mine. : - ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.