2

如何使用 SpaceVim 的 Job API

 2 years ago
source link: https://wsdjeg.spacevim.org/how-to-use-spacevim-job-api/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何使用 SpaceVim 的 Job API


因为 Vim8 和 Neovim 实现的 job 函数存在很大的区别,并且使用的方式也是不一样的。在制作插件时,如果需要同时兼容 Vim 和 Neovim 就会存在很大的麻烦。因此,在 SpaceVim 中,实现了一个 job API,使用示例如下:

let  s:JOB = SpaceVim#api#import('job')
let s:command = ['echo', 'hello world']
function! s:stdout(id, data, event)
    " the data is a list of string
    for line in a:data
        echo line
    endfor
endf
call s:JOB.start(s:command, {
    \ 'on_stdout' : function('s:stdout'),
    \ }
    \ )

这个 API 的实现,参考了 neovim job 的模型。支持如下参数:

  • on_stdout
  • on_stderr
  • on_exit

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK