1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:40:06 +08:00

Website: add vim#command api doc (#2412)

This commit is contained in:
Wang Shidong 2019-01-05 01:55:57 -06:00 committed by GitHub
parent 5ee5c57c8d
commit e1d6f0d883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 264 additions and 66 deletions

View File

@ -8,42 +8,33 @@
scriptencoding utf-8
let s:FILE = SpaceVim#api#import('file')
let s:SYS = SpaceVim#api#import('system')
let s:AUTODOC = SpaceVim#api#import('dev#autodoc')
let s:AUTODOC.autoformat = 1
function! SpaceVim#dev#api#update() abort
let [start, end] = s:find_position()
if start != 0 && end != 0
if end - start > 1
exe (start + 1) . ',' . (end - 1) . 'delete'
endif
call append(start, s:generate_content())
silent! Neoformat
endif
let s:AUTODOC.begin = '^<!-- SpaceVim api list start -->$'
let s:AUTODOC.end = '^<!-- SpaceVim api list end -->$'
let s:AUTODOC.content_func = function('s:generate_content')
call s:AUTODOC.update()
endfunction
function! SpaceVim#dev#api#updateCn() abort
let [start, end] = s:find_position_cn()
if start != 0 && end != 0
if end - start > 1
exe (start + 1) . ',' . (end - 1) . 'delete'
endif
call append(start, s:generate_content_cn())
silent! Neoformat
endif
let s:AUTODOC.begin = '^<!-- SpaceVim api cn list start -->$'
let s:AUTODOC.end = '^<!-- SpaceVim api cn list end -->$'
let s:AUTODOC.content_func = function('s:generate_content_cn')
call s:AUTODOC.update()
endfunction
function! s:find_position() abort
let start = search('^<!-- SpaceVim api list start -->$','bwnc')
let end = search('^<!-- SpaceVim api list end -->$','bnwc')
return sort([start, end])
endfunction
function! s:find_position_cn() abort
let start = search('^<!-- SpaceVim api cn list start -->$','bwnc')
let end = search('^<!-- SpaceVim api cn list end -->$','bnwc')
return sort([start, end])
function! s:generate_content_cn() abort
let content = ['', '## 可用 APIs', '']
let content += s:layer_list_cn()
let content += ['']
return content
endfunction
function! s:generate_content() abort
@ -53,27 +44,25 @@ function! s:generate_content() abort
return content
endfunction
function! s:generate_content_cn() abort
let content = ['', '## 可用 APIs', '']
let content += s:layer_list_cn()
let content += ['']
return content
endfunction
function! s:layer_list() abort
let layers = SpaceVim#util#globpath('~/.SpaceVim/', 'docs/api/**/*.md')
let list = [
\ '| Name | Description |',
\ '| ---------- | ------------ |'
\ ]
if s:SYS.isWindows
let pattern = join(['', 'docs', 'api', ''], s:FILE.separator . s:FILE.separator)
else
let pattern = join(['', 'docs', 'api', ''], s:FILE.separator)
endif
for layer in layers
let name = split(layer, '/docs/api/')[1][:-4] . '/'
let url = name
let name = split(layer, pattern)[1][:-4] . s:FILE.separator
let url = join(split(name, s:FILE.separator), '/') . '/'
let content = readfile(layer)
if len(content) > 3
let line = '| [' . join(split(name, '/'), '#') . '](' . url . ') | ' . content[2][14:-2] . ' | '
let line = '| [' . join(split(name, s:FILE.separator), '#') . '](' . url . ') | ' . content[2][14:-2] . ' | '
else
let line = '| [' . join(split(name, '/'), '#') . '](' . url . ') | can not find Description |'
let line = '| [' . join(split(name, s:FILE.separator), '#') . '](' . url . ') | can not find Description |'
endif
call add(list, line)
endfor
@ -86,14 +75,19 @@ function! s:layer_list_cn() abort
\ '| 名称 | 描述 |',
\ '| ---------- | ------------ |'
\ ]
if s:SYS.isWindows
let pattern = join(['', 'docs', 'cn', 'api', ''], s:FILE.separator . s:FILE.separator)
else
let pattern = join(['', 'docs', 'cn', 'api', ''], s:FILE.separator)
endif
for layer in layers
let name = split(layer, '/docs/cn/api/')[1][:-4] . '/'
let url = name
let name = split(layer, pattern)[1][:-4] . s:FILE.separator
let url = join(split(name, s:FILE.separator), '/') . '/'
let content = readfile(layer)
if len(content) > 3
let line = '| [' . join(split(name, '/'), '#') . '](' . url . ') | ' . content[2][14:-2] . ' | '
let line = '| [' . join(split(name, s:FILE.separator), '#') . '](' . url . ') | ' . content[2][14:-2] . ' | '
else
let line = '| [' . join(split(name, '/'), '#') . '](' . url . ') | can not find Description |'
let line = '| [' . join(split(name, s:FILE.separator), '#') . '](' . url . ') | can not find Description |'
endif
call add(list, line)
endfor

View File

@ -46,6 +46,15 @@ function! s:self._complete_opt(part, opt) abort
endif
endfunction
function! s:self._complete_opt_list(part, opt) abort
let complete = self.options[a:opt].complete
if type(complete) == type([])
return complete
else
return getcompletion(a:part, complete)
endif
endfunction
function! s:self.complete(ArgLead, CmdLine, CursorPos) abort
let argvs = split(a:CmdLine)
let last_argv = split(a:CmdLine)[-1]
@ -69,6 +78,30 @@ function! s:self.complete(ArgLead, CmdLine, CursorPos) abort
endfunction
function! s:self.completelist(ArgLead, CmdLine, CursorPos) abort
let argvs = split(a:CmdLine)
let last_argv = split(a:CmdLine)[-1]
let msg = 'ArgLead: ' . a:ArgLead . ' CmdLine: ' . a:CmdLine . ' CursorPos: '
\ . a:CursorPos . ' LastArgv: ' . last_argv
call add(self._message, msg)
if a:ArgLead == '' && index(keys(self.options), last_argv) == -1
return keys(self.options)
elseif a:ArgLead == '' && index(keys(self.options), last_argv) != -1
return self._complete_opt_list(a:ArgLead, last_argv)
elseif !empty(a:ArgLead) && len(argvs) >= 3
\ && index(keys(self.options), argvs[-2]) != -1
return self._complete_opt_list(a:ArgLead, argvs[-2])
elseif !empty(a:ArgLead) && (
\ (len(argvs) >= 3 && index(keys(self.options), argvs[-2]) == -1)
\ ||
\ (len(argvs) ==2 )
\ )
return keys(self.options)
endif
endfunction
function! s:self.debug() abort
echo join(self._message, "\n")
endfunction

View File

@ -1,5 +1,5 @@
---
title: Available APIs
title: Available APIs
description: "A list of available APIs in SpaceVim, provide compatible functions for vim and neovim."
---
@ -7,7 +7,7 @@ description: "A list of available APIs in SpaceVim, provide compatible functions
<!-- vim-markdown-toc GFM -->
- [Introduction](#introduction)
- [Introduction](#introduction)
- [Available APIs](#available-apis)
<!-- vim-markdown-toc -->
@ -34,26 +34,29 @@ echom s:file.pathSeparator
<!-- SpaceVim api list start -->
#### Available APIs
## Available APIs
here is the list of all available APIs, and welcome to contribute to SpaceVim.
| Name | Description |
| ---------- | ------------ |
| [data#base64](data/base64/) | data#base64 API provides base64 encode and decode functions |
| [data#dict](data/dict/) | data#dict API provides some basic functions and values for dict. |
| [data#string](data/string/) | data#string API provides some basic functions and values for string. |
| [data#toml](data/toml/) | data#toml API provides some basic functions and values for toml. |
| [file](file/) | file API provides some basic functions and values for current os. |
| [job](job/) | job API provides some basic functions for running a job |
| [logger](logger/) | logger API provides some basic functions for log message when create plugins |
| [messletters](messletters/) | messletters API provides some basic functions for generating messletters |
| [password](password/) | password API provides some basic functions for generating password |
| [system](system/) | system API provides some basic functions and values for current os. |
| [unicode#spinners](unicode/spinners/) | unicode#spinners API provides some basic functions for starting spinners timer |
| [vim#highlight](vim/highlight/) | vim#highlight API provides some basic functions and values for getting and setting highlight info. |
| [web#html](web/html/) | web#html API provides some basic functions and values for parser html file. |
| [web#http](web/http/) | web#http API provides some basic functions and values for http request |
| [web#xml](web/xml/) | web#xml API provides some basic functions and values for parser xml file. |
| Name | Description |
| ------------------------------------- | -------------------------------------------------------------------------------------------------- |
| [data#base64](data/base64/) | data#base64 API provides base64 encode and decode functions |
| [data#dict](data/dict/) | data#dict API provides some basic functions and values for dict. |
| [data#list](data/list/) | data#list API provides some basic functions and values for list. |
| [data#string](data/string/) | data#string API provides some basic functions and values for string. |
| [data#toml](data/toml/) | data#toml API provides some basic functions and values for toml. |
| [file](file/) | file API provides some basic functions and values for current os. |
| [job](job/) | job API provides some basic functions for running a job |
| [logger](logger/) | logger API provides some basic functions for log message when create plugins |
| [messletters](messletters/) | messletters API provides some basic functions for generating messletters |
| [password](password/) | password API provides some basic functions for generating password |
| [system](system/) | system API provides some basic functions and values for current os. |
| [transient-state](transient-state/) | transient state API provides some besic functions and values for current os. |
| [unicode#spinners](unicode/spinners/) | unicode#spinners API provides some basic functions for starting spinners timer |
| [vim#command](vim/command/) | vim#command API provides some basic functions and values for creatting vim custom command. |
| [vim#highlight](vim/highlight/) | vim#highlight API provides some basic functions and values for getting and setting highlight info. |
| [web#html](web/html/) | web#html API provides some basic functions and values for parser html file. |
| [web#http](web/http/) | web#http API provides some basic functions and values for http request |
| [web#xml](web/xml/) | web#xml API provides some basic functions and values for parser xml file. |
<!-- SpaceVim api list end -->

45
docs/api/vim/command.md Normal file
View File

@ -0,0 +1,45 @@
---
title: "vim#command api"
description: "vim#command API provides some basic functions and values for creatting vim custom command."
---
# [Available APIs](../../) >> vim#command
<!-- vim-markdown-toc GFM -->
- [Intro](#intro)
- [Functions](#functions)
<!-- vim-markdown-toc -->
## Intro
vim#command API provides some basic functions and values for creatting vim custom command.
```vim
let s:CMD = SpaceVim#api#import('vim#command')
let s:CMD.options = {
\ '-f' : {
\ 'description' : '',
\ 'complete' : ['text'],
\ },
\ '-d' : {
\ 'description' : 'Root directory for sources',
\ 'complete' : 'file',
\ },
\ }
function! CompleteTest(a, b, c)
return s:CMD.complete(a:a, a:b, a:c)
endfunction
function! Test(...)
endfunction
command! -nargs=* -complete=custom,CompleteTest
\ TEST :call Test(<f-args>)
```
## Functions
| function name | description |
| ------------------------------------------- | ------------------------------ |
| `complete(ArgLead, CmdLine, CursorPos)` | custom completion function |
| `completelist(ArgLead, CmdLine, CursorPos)` | customlist completion function |

View File

@ -37,16 +37,20 @@ echom s:file.separator
echom s:file.pathSeparator
```
<!-- call SpaceVim#dev#api#updateCn() -->
<!-- SpaceVim api cn list start -->
## 可用 APIs
| 名称 | 描述 |
| ------------------------------------- | ----------------------------------------------------------------------- |
| [file](file/) | can not find Description |
| [data#dict](data/dict/) | data#dict api 提供了一些处理字典变量的常用方法 |
| [file](file/) | 文件函数提供了基础的文件读写相关函数,兼容不同系统平台。 |
| [job](job/) | 兼容 neovim 和 vim 的异步协同 API对于旧版 vim 采用非异步机制 |
| [system](system/) | can not find Description |
| [system](system/) | system 函数提供了系统相关函数,包括判断当前系统平台,文件格式等函数。 |
| [unicode#spinners](unicode/spinners/) | unicode#spinners API 可启用一个定时器,根据指定的名称定时更新进度条符号 |
| [vim#command](vim/command/) | vim#command API 提供一些设置和获取 Vim 命令的基础函数。 |
| [vim#highlight](vim/highlight/) | vim#highlight API 提供一些设置和获取 Vim 高亮信息的基础函数。 |
<!-- SpaceVim api cn list end -->

View File

@ -0,0 +1,39 @@
---
title: "文件函数"
description: "文件函数提供了基础的文件读写相关函数,兼容不同系统平台。"
lang: cn
---
# [公共 API](../) >> file
<!-- vim-markdown-toc GFM -->
- [简介](#简介)
- [values](#values)
- [functions](#functions)
<!-- vim-markdown-toc -->
## 简介
文件函数提供了基础的文件读写相关函数,兼容不同系统平台。
## values
| name | description |
| ------------- | ---------------------------------------------- |
| separator | The system-dependent name-separator character. |
| pathSeparator | The system-dependent path-separator character. |
## functions
| name | description |
| ------------------------- | ----------------------------------------------- |
| `fticon(file)` | return the icon of specific file name or path |
| `write(message, file)` | append message to file |
| `override(message, file)` | override message to file |
| `read(file)` | read message from file |
| `ls(dir, if_file_only)` | list files and directorys in specific directory |
| `updateFiles(files)` | update the contents of all files |

View File

@ -0,0 +1,34 @@
---
title: "系统函数"
description: "system 函数提供了系统相关函数,包括判断当前系统平台,文件格式等函数。"
lang: cn
---
# [公共 API](../) >> system
<!-- vim-markdown-toc GFM -->
- [简介](#简介)
- [values](#values)
- [functions](#functions)
<!-- vim-markdown-toc -->
## 简介
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 |
| isDarwin | 0 or 1 | check if the os is Darwin |
## functions
| name | description |
| ---------- | -------------------------------------- |
| fileformat | return the icon of current file format |

View File

@ -0,0 +1,46 @@
---
title: "vim#command api"
description: "vim#command API 提供一些设置和获取 Vim 命令的基础函数。"
lang: cn
---
# [可用 APIs](../../) >> vim#command
<!-- vim-markdown-toc GFM -->
- [简介](#简介)
- [函数及变量](#函数及变量)
<!-- vim-markdown-toc -->
## 简介
vim#command API 提供一些设置和获取 Vim 命令的基础函数。
```vim
let s:CMD = SpaceVim#api#import('vim#command')
let s:CMD.options = {
\ '-f' : {
\ 'description' : '',
\ 'complete' : ['text'],
\ },
\ '-d' : {
\ 'description' : 'Root directory for sources',
\ 'complete' : 'file',
\ },
\ }
function! CompleteTest(a, b, c)
return s:CMD.complete(a:a, a:b, a:c)
endfunction
function! Test(...)
endfunction
command! -nargs=* -complete=custom,CompleteTest
\ TEST :call Test(<f-args>)
```
## 函数及变量
| 函数名称 | 功能描述 |
| ------------------------------------------- | ------------------------------ |
| `complete(ArgLead, CmdLine, CursorPos)` | custom completion function |
| `completelist(ArgLead, CmdLine, CursorPos)` | customlist completion function |