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
While you work, they are appearing in some predefined buffer.
Thanks in advance.