Brad Beveridge wrote:

> Hi all, I'm working with a Vim that has been hacked so that you can
> get callbacks when data appears on a socket.
> Basically, our callback system works in pretty much the same way as
> the code in FEAT_SNIFF.  We add the filedescriptors that we are
> interested in to the select/poll code in os_unix, if there is data
> pending on a socket then we callback a registered function, which
> should clear the data from the socket.
> In my particular case, the callback calls into Lisp code in our
> embedded Lisp interpreter, which writes data to buffers using
> ml_replace and ml_append.
> 
> Q1) Is using ml_append from (effectively) within RealWaitForChar a bad
> thing?  At the moment it appears to work properly.

Yes.  You never know where in Vim you are, the caller may not handle the
situation that the text changes unexpectedly.  It's similar to
autocommands, which have caused crashes in the past.

> At the moment, after the callback has run we call
> screen_update(NOT_VALID).  However, from what I can see, calling
> screen_update may (does?) re-call RealWaitForChar, which can retrigger
> the callback, etc.
> Q2) Is this nesting of RealWaitForChar a bad thing? (I thing it may
> be)

Yes, it must be avoided.

> Q3) What is the correct way/place to trigger screen_update(NOT_VALID)?
>  How should I trigger it from within RealWaitForChar?

In RealWaitForChar() put a special key in the input buffer and handle
this key in the main loop.

> One other point to consider, although we may do callbacks,
> RealWaitForChar may not have keyboard input - what should
> RealWaitForChar return in this case?

If there is no input Vim should exit, because it won't do anything
useful.  A script is also considered input in this context.

> If the list would like to see this code, I can post a patch, or you
> can use Darcs to get a Vim+Callbacks+ECL from
> http://theclapp.org/repos/vim70+async+ecl/.
> 
> Q4) Would this callback mechanism be more generally useful for other
> scripting engines?

Yes, if you can implement it for various systems (at least Unix, Mac and
MS-Windows).

If I would have time I would look into making the code that waits for a
character to be typed more generic.  Currently quite a bit of code is
repeated for every system.

-- 
hundred-and-one symptoms of being an internet addict:
193. You ask your girlfriend to drive home so you can sit back with
     your PDA and download the information to your laptop

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Reply via email to