views:

255

answers:

1

Hello Guys,

I am trying to fill Vim's buffer from separate thread by using this python code.

python << PYTHON_CODE

import vim
import time

buffer_number = -1
class AppendLineTest( Thread ):
   def run(self):
      buffer = vim.buffers[buffer_number - 1]

      for i in range(10):
         buffer.append('Line number %s' % i)
         time.sleep(1)

PYTHON_CODE

function! s:test()
   split TestBuffer
   exec 'python buffer_number = '.bufnr('%')

   setlocal noswapfile
   setlocal bufhidden=delete
   setlocal buftype=nofile
   setlocal nobuflisted
   setlocal nonumber
   setlocal nowrap
   setlocal nocursorline

   python AppendLineTest().start()
endfunction

command! -nargs=0 PythonAppendTest call s:test()

I am not sure that accessing Vim's buffers from separate threads are allowed and wonder is there some safe dispatch way. But if it is allowed, I would like to get rid of the cursor jumping when append line taking place.

So to reproduce the behavior, save the code to some name.vim file and open it in the Vim. Then

:source %

And then

PythonAppendTest

Lines will be added 10 times to the temporary buffer. Just move cursor back to the window where you were and you will understand what I am talking about.

If you wonder why can someone need to add lines to buffers from the separate thread, here is an example:

  • unix top
  • unix tail
  • rss
  • email

While you work, they are appearing in some predefined buffer.

Thanks in advance.

+1  A: 

I don't think Vim is very tolerant of multiple threads without patching. There's a lot more detail in the discussion at this link, but I suspect that what you want is far from trivial.

Al
Thanks for the link. Too sad.
Mykola Golubyev