4

I am writing a VIM plugin in Python. I would like to be able to run a function that would wait for events in the background and update a buffer when needed, without freezing the whole window. Is that possible?

I tried running a separate thread using the threading module, which didn't help. The changes in the buffer are reflected only when the function returns (and the blocking thread terminates).

Clarification: I have a function that may take dozens of seconds to return the updates. I need to update one of the buffers with the returned data (and call the function again).

How do I call it "asynchronously" and not have the window frozen? If I can do it by spanning a separate process, how do I set up the IPC?

Another update: What if I create a temp file, have a separate process write to it, and watch for FileChangedShell as suggested here to automatically refresh it?

(If there is no "it's not going to work" answer and no better ideas in my mind, I will try this in a while and update with results).

Community
  • 1
  • 1
Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175
  • I've always thought vim was singled threaded and that it was very hard to do anything multi threaded – FDinoff Aug 31 '13 at 03:41
  • @FDinoff I've come across something like that; but couldn't quite understand what it meant. Hopefully, asking a direct question will get me some clarity on the issue. – Lev Levitsky Aug 31 '13 at 03:44

1 Answers1

0

This may be abstract without knowing the details. But would polling for the event data to be present works for your plugin? Way back i was writing some vim plugin for ensime ( scala compeletion daemon ) and had a similar problem. For me opening a new process and waiting for data to be present in socket was working pretty well. This was obviously due to the fact that the server itself was asynchronous and used to write result on the socket in the order they were recieved. Hope this helps.

FUD
  • 5,114
  • 7
  • 39
  • 61
  • I'm not sure I understand your suggestion. Did you spawn a process and have it write updates to a socket? How were you reading it then, didn't you have the same problem of blocking while reading? I tried to clarify my question, fwiw. – Lev Levitsky Aug 31 '13 at 09:31