I wrote:

> I was wondering where to trigger SafeState.  I first thought it would be
> sufficient to do this higher up, where we are going to wait for the user
> to type a character and nothing is pending.  Then it's safe to deal with
> any callbacks.
> 
> However, think of this scenario:
>       1. In a safe state, SafeState is triggered.
>       2. Waiting for a character, receive a message.
>       3. Invoke callback for the message, it uses ch_evalexpr().
>       4. While in ch_evalexpr() another message arrives.  Since it's
>          not safe now, work is postponed.
>       5. ch_evalexpr() finishes
>       6. go back to waiting for a character
> 
> Now, so long as the user doesn't type anything, the work won't be
> executed.  That may take long time.  Or the user is actually waiting for
> the work to be done, which is a kind of deadlock.
> 
> Thus it seems that we need to trigger SafeState also before 6.  Under
> the condition we started waiting for a character in a safe state.
> And it was not safe at some moment (to avoid it being triggered too
> often).
> 
> It does mean that the display won't be updated, thus we would need to do
> that, like when a timer callback was invoked.
> 
> Does this sound OK?

I decided to give it a go and did an implementation of SafeState.
It triggers in Normal, Insert and Command-line mode when nothing is
pending.  And when a blocking channel call has been made, where the
state was safe before blocking, so that when something is postponed it
can be handled afterwards.

It may be that we need to check more conditions whether it is actually
"safe".  And some things depend on what the requirements for "safe" are.
E.g. currently it is not checking for Visual mode, you can use mode()
for that.  And it doesn't check whether the screen is scrolled (not sure
how you would check for that, might need the state() function).

When SafeState is triggered after the blocking channel call, we are in
the input loop, thus no screen update will take place.  You can use
:redraw, but in Command-line mode that might not work well.

Anyway, please try it out, so we can decide whether we can keep
SafeState, modify it, or perhaps drop it.

-- 
       We're knights of the round table
       We dance whene'er we're able
       We do routines and chorus scenes
       With footwork impeccable.
       We dine well here in Camelot
       We eat ham and jam and spam a lot.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201909161032.x8GAWMtC008318%40masaka.moolenaar.net.

Raspunde prin e-mail lui