Once again, I only replied to Bram. Sorry. On 28/08/06, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
Brad Beveridge wrote: > <SNIP> > > > > 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 what level in the stack is it safe to call ml_append, etc? How do > I tell Vim to retreat up to that level, is there code that I can look > at? At the moment I'm trying to do it by adding to an entry to > keymap.h:key_extra, pushing 3 bytes into buf in os_unix.c (just like > the cursorhold), but I have no idea how to get right out into > main_loop. A problem was recently reported with CursorHold: a two-character command is interrupted, because the K_CURSORHOLD is put in the typeahead buffer. I currently don't know a good solution. Doing the work at a lower level has the problem that the caller of vgetc() may be confused, while putting something in the input buffer has the problem just mentioned. A complicated way would be to check all places where vgetc() is (indirectly) called and handle special keys there. That should at least work when something like a double quote was typed. In your case, if you know exactly what is going to be done in the event handler, you may do some things at a low level. But for something like the CursorHold event, which can do anything (including switching to another buffer), this will not be acceptable.
I would like to let the callback code do anything really - and we currently do have code that requests switches to another buffer. So are you saying that the cursor hold code is probably not a good example to work from here? The more I learn about how Vim works internally, the more I think my existing network code is anywhere from "slightly broken" to "very broken under the right conditions". That doesn't make me very happy :( I guess that I'll just need to sift through the Vim code some more until I grok it better. Any help is very welcome :) Cheers Brad