维姆Python的缓冲区.append(线)切换窗口焦点

2024-06-08 05:33:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用这个python代码从单独的线程填充Vim的缓冲区。在

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()

我不确定是否允许从不同的线程访问Vim的缓冲区,我想知道是否有一些安全的调度方式。 但如果允许的话,我希望消除追加行发生时光标跳转的问题。在

所以为了重现行为,把代码保存到名称.vim在Vim中归档并打开它。那么

^{pr2}$

然后呢

PythonAppendTest

行将被添加到临时缓冲区10次。只要把光标移回你原来所在的窗口,你就会明白我在说什么。在

如果您想知道为什么有人需要从单独的线程向缓冲区添加行,下面是一个示例:

  • unix顶部
  • unix尾部
  • rss
  • 电子邮件

工作时,它们会出现在某个预定义的缓冲区中。在

提前谢谢。在


Tags: 代码testimportnumbertimebufferunixcode

热门问题