mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 00:20:05 +08:00
Add job api
This commit is contained in:
parent
54bf408f2c
commit
ddb5600744
@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "file api"
|
||||
---
|
||||
|
||||
# [APIs](https://spacevim.org/apis) : file
|
||||
|
||||
## values
|
||||
|
||||
name | values | description
|
||||
----- |:----:| ------------------
|
||||
separator | `/` or `\` | The system-dependent name-separator character.
|
||||
pathSeparator | `:` or `;` | The system-dependent path-separator character.
|
||||
|
||||
## functions
|
@ -1,15 +0,0 @@
|
||||
---
|
||||
title: "system api"
|
||||
---
|
||||
|
||||
# [APIs](https://spacevim.org/apis) : system
|
||||
|
||||
## values
|
||||
|
||||
name | values | description
|
||||
----- |:----:| ------------------
|
||||
isWindows | 0 or 1 | check if the os is windows
|
||||
isLinux | 0 or 1 | check if the os is linux
|
||||
isOSX | 0 or 1 | check if the os is OSX
|
||||
|
||||
## functions
|
0
docs/cn/api/file.md
Normal file
0
docs/cn/api/file.md
Normal file
43
docs/cn/api/job.md
Normal file
43
docs/cn/api/job.md
Normal file
@ -0,0 +1,43 @@
|
||||
---
|
||||
title: "异步协同 API"
|
||||
---
|
||||
|
||||
# [APIs](https://spacevim.org/cn/apis) : job
|
||||
|
||||
`job` API 提供了一套可以兼容 neovim 和 vim 的异步控制机制,具体实现模型是参考的 neovim 的模型,具体示例如下:
|
||||
|
||||
```vim
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
|
||||
function! s:on_stdout(id, data, event) abort
|
||||
" do something with stdout
|
||||
endfunction
|
||||
|
||||
function! s:on_stderr(id, data, event) abort
|
||||
" do something with stderr
|
||||
endfunction
|
||||
|
||||
function! s:on_exit(id, data, event) abort
|
||||
" handle exit code
|
||||
endfunction
|
||||
|
||||
let cmd = ['python', 'test.py']
|
||||
|
||||
call s:JOB.start(cmd,
|
||||
\ {
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
|
||||
```
|
||||
|
||||
以上代码可以在 vim 或者 neovim 中异步运行命令,甚至对于老版本的 vim 也兼容,但是在老版本 vim 中执行的时候不是异步的。
|
||||
|
||||
|
||||
## functions
|
||||
|
||||
| 名称 | 描述 |
|
||||
| ------------------ | ---------------------------- |
|
||||
| `start(cmd, argv)` | 开始一个 job, 并返回 job id. |
|
0
docs/cn/api/system.md
Normal file
0
docs/cn/api/system.md
Normal file
@ -1,5 +1,6 @@
|
||||
---
|
||||
title: "公共 API"
|
||||
description: "SpaceVim 公共 API 提供了一套开发插件的公共函数,以及 neovim 和 vim 的兼容组件"
|
||||
lang: cn
|
||||
---
|
||||
|
||||
@ -9,6 +10,8 @@ SpaceVim 提供了许多公共的 apis,你可以在你的插件中使用这些
|
||||
|
||||
## 使用方法
|
||||
|
||||
可以使用 `SpaceVim#api#import()` 方法导入 API。参考以下示例:
|
||||
|
||||
```viml
|
||||
|
||||
let s:file = SpaceVim#api#import('file')
|
||||
@ -25,5 +28,6 @@ echom s:file.pathSeparator
|
||||
|
||||
名称 | 描述 | 文档
|
||||
----- |:----:| -------
|
||||
file | 文件 API | [readme](https://spacevim.org/api/file)
|
||||
system | 系统 API | [readme](https://spacevim.org/api/system)
|
||||
file | 文件 API | [readme](https://spacevim.org/cn/api/file)
|
||||
system | 系统 API | [readme](https://spacevim.org/cn/api/system)
|
||||
job | 异步协同 API | [readme](https://spacevim.org/cn/api/job)
|
||||
|
Loading…
Reference in New Issue
Block a user