mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 21:10:05 +08:00
Improve system api (#1780)
* Improve system api * Update apis * Update apis * Update apis * Update apis * Update apis * Update file api * Update build options of vimproc
This commit is contained in:
parent
7eb600aef4
commit
3eb94b292e
99
.SpaceVim.d/autoload/SpaceVim/dev/api.vim
Normal file
99
.SpaceVim.d/autoload/SpaceVim/dev/api.vim
Normal file
@ -0,0 +1,99 @@
|
||||
"=============================================================================
|
||||
" api.vim --- Develop script for update api index
|
||||
" Copyright (c) 2016-2017 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg at 163.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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])
|
||||
endfunction
|
||||
|
||||
function! s:generate_content() abort
|
||||
let content = ['', '## Available APIs', '', 'here is the list of all available APIs, and welcome to contribute to SpaceVim.', '']
|
||||
let content += s:layer_list()
|
||||
return content
|
||||
endfunction
|
||||
|
||||
function! s:generate_content_cn() abort
|
||||
let content = ['', '## 可用 APIs', '']
|
||||
let content += s:layer_list_cn()
|
||||
return content
|
||||
endfunction
|
||||
|
||||
function! s:layer_list() abort
|
||||
let layers = SpaceVim#util#globpath('~/.SpaceVim/', 'docs/api/**/*.md')
|
||||
let list = [
|
||||
\ '| Name | Description |',
|
||||
\ '| ---------- | ------------ |'
|
||||
\ ]
|
||||
for layer in layers
|
||||
let name = split(layer, '/docs/api/')[1][:-4] . '/'
|
||||
let url = name
|
||||
let content = readfile(layer)
|
||||
if len(content) > 3
|
||||
let line = '| [' . join(split(name, '/'), '#') . '](' . url . ') | ' . content[2][14:-2] . ' | '
|
||||
else
|
||||
let line = '| [' . join(split(name, '/'), '#') . '](' . url . ') | can not find Description |'
|
||||
endif
|
||||
call add(list, line)
|
||||
endfor
|
||||
return list
|
||||
endfunction
|
||||
|
||||
function! s:layer_list_cn() abort
|
||||
let layers = SpaceVim#util#globpath('~/.SpaceVim/', 'docs/cn/api/**/*.md')
|
||||
let list = [
|
||||
\ '| 名称 | 描述 |',
|
||||
\ '| ---------- | ------------ |'
|
||||
\ ]
|
||||
for layer in layers
|
||||
let name = split(layer, '/docs/cn/api/')[1][:-4] . '/'
|
||||
let url = name
|
||||
let content = readfile(layer)
|
||||
if len(content) > 3
|
||||
let line = '| [' . join(split(name, '/'), '#') . '](' . url . ') | ' . content[2][14:-2] . ' | '
|
||||
else
|
||||
let line = '| [' . join(split(name, '/'), '#') . '](' . url . ') | can not find Description |'
|
||||
endif
|
||||
call add(list, line)
|
||||
endfor
|
||||
return list
|
||||
endfunction
|
@ -14,17 +14,24 @@ let s:system['isLinux'] = has('unix') && !has('macunix') && !has('win32unix')
|
||||
|
||||
let s:system['isOSX'] = has('macunix')
|
||||
|
||||
|
||||
" windows, unix, cygwin, mac, linux
|
||||
|
||||
function! s:name() abort
|
||||
if s:system.isLinux
|
||||
return 'Linux'
|
||||
return 'linux'
|
||||
elseif s:system.isWindows
|
||||
return 'Windows'
|
||||
if has('win32unix')
|
||||
return 'cygwin'
|
||||
else
|
||||
return 'windows'
|
||||
endif
|
||||
else
|
||||
return 'OSX'
|
||||
return 'mac'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:system['name'] = function('s:name')
|
||||
let s:system['name'] = s:name()
|
||||
|
||||
function! s:isDarwin() abort
|
||||
if exists('s:is_darwin')
|
||||
|
@ -15,7 +15,7 @@ function! SpaceVim#layers#core#plugins() abort
|
||||
elseif g:spacevim_filemanager ==# 'vimfiler'
|
||||
call add(plugins, ['Shougo/vimfiler.vim',{'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1, 'on_cmd' : ['VimFiler', 'VimFilerBufferDir']}])
|
||||
call add(plugins, ['Shougo/unite.vim',{ 'merged' : 0 , 'loadconf' : 1}])
|
||||
call add(plugins, ['Shougo/vimproc.vim', {'build' : ['make']}])
|
||||
call add(plugins, ['Shougo/vimproc.vim', {'build' : [(executable('gmake') ? 'gmake' : 'make')]}])
|
||||
endif
|
||||
call add(plugins, ['benizi/vim-automkdir'])
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
let s:VIM_CO = SpaceVim#api#import('vim#compatible')
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:LIST = SpaceVim#api#import('data#list')
|
||||
let s:SYS = SpaceVim#api#import('system')
|
||||
|
||||
|
||||
" init values
|
||||
@ -110,7 +111,7 @@ function! s:get_uninstalled_plugins() abort
|
||||
endfunction
|
||||
|
||||
|
||||
function! SpaceVim#plugins#manager#reinstall(...)
|
||||
function! SpaceVim#plugins#manager#reinstall(...) abort
|
||||
call dein#reinstall(a:1)
|
||||
endfunction
|
||||
|
||||
@ -448,8 +449,7 @@ function! s:msg_on_build_start(name) abort
|
||||
endfunction
|
||||
|
||||
function! s:get_build_argv(build) abort
|
||||
" TODO check os
|
||||
return a:build
|
||||
return a:build[s:SYS.name]
|
||||
endfunction
|
||||
" + foo.vim: Updating...
|
||||
if has('nvim')
|
||||
@ -643,7 +643,7 @@ else
|
||||
endi
|
||||
|
||||
" Public API: SpaceVim#plugins#manager#terminal {{{
|
||||
function! SpaceVim#plugins#manager#terminal()
|
||||
function! SpaceVim#plugins#manager#terminal() abort
|
||||
for id in keys(s:pulling_repos)
|
||||
call s:JOB.stop(str2nr(id))
|
||||
endfor
|
||||
|
@ -9,9 +9,9 @@ function! WINDOWS()
|
||||
return (has('win16') || has('win32') || has('win64'))
|
||||
endfunction
|
||||
function! OnmiConfigForJsp()
|
||||
let pos1 = search("</script>","nb",line("w0"))
|
||||
let pos2 = search("<script","nb",line("w0"))
|
||||
let pos3 = search("</script>","n",line("w$"))
|
||||
let pos1 = search('</script>','nb',line('w0'))
|
||||
let pos2 = search('<script','nb',line('w0'))
|
||||
let pos3 = search('</script>','n',line('w$'))
|
||||
let pos0 = line('.')
|
||||
if pos1 < pos2 && pos2 < pos0 && pos0 < pos3
|
||||
set omnifunc=javascriptcomplete#CompleteJS
|
||||
@ -37,7 +37,7 @@ endf
|
||||
function! ToggleBG()
|
||||
let s:tbg = &background
|
||||
" Inversion
|
||||
if s:tbg == "dark"
|
||||
if s:tbg ==# 'dark'
|
||||
set background=light
|
||||
else
|
||||
set background=dark
|
||||
@ -46,7 +46,7 @@ endfunction
|
||||
function! BracketsFunc()
|
||||
let line = getline('.')
|
||||
let col = col('.')
|
||||
if line[col - 2] == "]"
|
||||
if line[col - 2] ==# ']'
|
||||
return "{}\<esc>i"
|
||||
else
|
||||
return "{\<cr>}\<esc>O"
|
||||
@ -191,11 +191,3 @@ fu! UpdateStarredRepos()
|
||||
endfor
|
||||
return 1
|
||||
endf
|
||||
|
||||
|
||||
function! TestBot(argv) abort
|
||||
endfunction
|
||||
|
||||
function! TestBot(argv) abort
|
||||
|
||||
endfunction
|
||||
|
@ -8,14 +8,6 @@
|
||||
|
||||
let s:SYSTEM = SpaceVim#api#import('system')
|
||||
|
||||
" Fsep && Psep
|
||||
if has('win16') || has('win32') || has('win64')
|
||||
let s:Psep = ';'
|
||||
let s:Fsep = '\'
|
||||
else
|
||||
let s:Psep = ':'
|
||||
let s:Fsep = '/'
|
||||
endif
|
||||
"Use English for anything in vim
|
||||
try
|
||||
if s:SYSTEM.isWindows
|
||||
|
45
docs/api.md
Normal file
45
docs/api.md
Normal file
@ -0,0 +1,45 @@
|
||||
---
|
||||
title: "APIs"
|
||||
description: "A list of available APIs in SpaceVim, provide compatible functions for vim and neovim."
|
||||
redirect_from: "/apis/"
|
||||
---
|
||||
|
||||
# SpaceVim APIs
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Introduction](#introduction)
|
||||
- [Available APIs](#available-apis)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Introduction
|
||||
|
||||
SpaceVim provides many public apis, you can use this apis in your plugins.
|
||||
This is an example for how to load API, and how to use the public functions within the APIs.
|
||||
|
||||
```vim
|
||||
" use SpaceVim#api#import() to load the API
|
||||
let s:file = SpaceVim#api#import('file')
|
||||
let s:system = SpaceVim#api#import('system')
|
||||
|
||||
" check the if current os is Windows.
|
||||
if s:system.isWindows
|
||||
echom "Os is Windows"
|
||||
endif
|
||||
echom s:file.separator
|
||||
echom s:file.pathSeparator
|
||||
```
|
||||
|
||||
<!-- SpaceVim api list start -->
|
||||
|
||||
## Available APIs
|
||||
|
||||
here is the list of all available APIs, and welcome to contribute to SpaceVim.
|
||||
|
||||
| Name | Description |
|
||||
| ----------------- | ------------------------------------------------------------------- |
|
||||
| [file](file/) | file API provides some besic functions and values for current os. |
|
||||
| [system](system/) | system API provides some besic functions and values for current os. |
|
||||
|
||||
<!-- SpaceVim api list end -->
|
@ -1,14 +1,32 @@
|
||||
---
|
||||
title: "file api"
|
||||
description: "file API provides some besic functions and values for current os."
|
||||
---
|
||||
|
||||
# [APIs](https://spacevim.org/apis) : file
|
||||
# [Available APIs](../) >> file
|
||||
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [values](#values)
|
||||
- [functions](#functions)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## values
|
||||
|
||||
name | values | description
|
||||
----- |:----:| ------------------
|
||||
separator | `/` or `\` | The system-dependent name-separator character.
|
||||
pathSeparator | `:` or `;` | The system-dependent path-separator character.
|
||||
| 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 |
|
||||
|
@ -1,15 +1,21 @@
|
||||
---
|
||||
title: "system api"
|
||||
description: "system API provides some besic functions and values for current os."
|
||||
---
|
||||
|
||||
# [APIs](https://spacevim.org/apis) : system
|
||||
# [Available 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
|
||||
| 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 |
|
||||
|
28
docs/apis.md
28
docs/apis.md
@ -1,28 +0,0 @@
|
||||
---
|
||||
title: "APIs"
|
||||
---
|
||||
|
||||
# SpaceVim public APIs:
|
||||
|
||||
SpaceVim provide many public apis, you can use this apis in your plugins. SpaceVim api got inspired by [vital.vim](https://github.com/vim-jp/vital.vim)
|
||||
|
||||
## Usage
|
||||
|
||||
```viml
|
||||
|
||||
let s:file = SpaceVim#api#import('file')
|
||||
let s:system = SpaceVim#api#import('system')
|
||||
|
||||
if s:system.isWindows
|
||||
echom "Os is Windows"
|
||||
endif
|
||||
echom s:file.separator
|
||||
echom s:file.pathSeparator
|
||||
```
|
||||
|
||||
here is the list of all the apis, and welcome to contribute to SpaceVim.
|
||||
|
||||
name | description | documentation
|
||||
----- |:----:| -------
|
||||
file | basic api about file and directory | [readme](https://spacevim.org/api/file)
|
||||
system | basic api about system | [readme](https://spacevim.org/api/system)
|
@ -1,6 +1,7 @@
|
||||
---
|
||||
title: "公共 API"
|
||||
description: "SpaceVim 公共 API 提供了一套开发插件的公共函数,以及 neovim 和 vim 的兼容组件"
|
||||
redirect_from: "/cn/apis/"
|
||||
lang: cn
|
||||
---
|
||||
|
||||
@ -26,8 +27,13 @@ echom s:file.pathSeparator
|
||||
|
||||
以下为可用的公共 apis,欢迎贡献新的 apis
|
||||
|
||||
<!-- SpaceVim api cn list start -->
|
||||
|
||||
名称 | 描述 | 文档
|
||||
----- |:----:| -------
|
||||
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)
|
||||
|
||||
<!-- SpaceVim api cn list end -->
|
||||
|
@ -288,7 +288,7 @@ You are free to choose a reasonable height size but the width size should be aro
|
||||
|
||||
## Build with SpaceVim
|
||||
|
||||
SpaceVim provide a lot of public [APIs](https://spacevim.org/apis), you can create plugins base on this APIs. also you can add a badge to the README.md of your plugin.
|
||||
SpaceVim provide a lot of public [APIs](../api/), you can create plugins base on this APIs. also you can add a badge to the README.md of your plugin.
|
||||
|
||||
![](https://img.shields.io/badge/build%20with-SpaceVim-ff69b4.svg)
|
||||
|
||||
|
@ -219,7 +219,7 @@ call SpaceVim#custom#SPC('nore', ['G', 't'], 'echom 1', 'echomessage 1', 1)
|
||||
### 私有模块
|
||||
|
||||
这一部分简单介绍了模块的组成,更多关于新建模块的内容可以阅读
|
||||
SpaceVim 的[模块首页](layers/)。
|
||||
SpaceVim 的[模块首页](../layers/)。
|
||||
|
||||
**目的**
|
||||
|
||||
@ -264,7 +264,7 @@ SpaceVim 集成了多种使用 UI 插件,如常用的文件树、语法树等
|
||||
| `SPC T n` | 切换至下一个随机主题 |
|
||||
| `SPC T s` | 通过 Unite 选择主题 |
|
||||
|
||||
可以在[主题模块](layers/colorscheme/)中查看 SpaceVim 支持的所有主题。
|
||||
可以在[主题模块](../layers/colorscheme/)中查看 SpaceVim 支持的所有主题。
|
||||
|
||||
**注意**:
|
||||
|
||||
@ -753,11 +753,9 @@ Denite/Unite 是一个强大的信息筛选浏览器,这类似于 emacs 中的
|
||||
如果添加来自于 github.com 的插件,可以 `用户名/仓库名` 这一格式,将该插件添加到 `custom_plugins`,示例如下:
|
||||
|
||||
```toml
|
||||
# custom plugins {{{
|
||||
[[custom_plugins]]
|
||||
name = 'lilydjwg/colorizer'
|
||||
merged = 0
|
||||
# }}}
|
||||
```
|
||||
|
||||
#### 界面元素显示切换
|
||||
|
@ -25,7 +25,7 @@ colorscheme 模块为 SpaceVim 提供了一系列常用的颜色主题,默认
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'colorscheme'
|
||||
name = "colorscheme"
|
||||
```
|
||||
|
||||
## 模块配置
|
||||
@ -57,7 +57,7 @@ SpaceVim 支持在配置文件中通过 `colorscheme_bg` 这一选项来设置
|
||||
```toml
|
||||
[options]
|
||||
colorscheme = "onedark"
|
||||
colorscheme_bg = 'dark'
|
||||
colorscheme_bg = "dark"
|
||||
```
|
||||
|
||||
这一模块提供了,在启动时随机选择主题,而不是使用默认的主题。这一特性可以很
|
||||
@ -65,6 +65,6 @@ SpaceVim 支持在配置文件中通过 `colorscheme_bg` 这一选项来设置
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'colorscheme'
|
||||
name = "colorscheme"
|
||||
random-theme = true
|
||||
```
|
||||
|
@ -291,7 +291,7 @@ You are free to choose a reasonable height size but the width size should be aro
|
||||
|
||||
## Build with SpaceVim
|
||||
|
||||
SpaceVim provide a lot of public [APIs](../apis/), you can create plugins base on this APIs. also you can add a badge to the README.md of your plugin.
|
||||
SpaceVim provide a lot of public [APIs](../api/), you can create plugins base on this APIs. also you can add a badge to the README.md of your plugin.
|
||||
|
||||
![](https://img.shields.io/badge/build%20with-SpaceVim-ff69b4.svg)
|
||||
|
||||
|
@ -308,7 +308,7 @@ the variable colorschemes. For instance, to specify `desert`:
|
||||
| `SPC T n` | switch to next random colorscheme listed in colorscheme layer. |
|
||||
| `SPC T s` | select a theme using a unite buffer. |
|
||||
|
||||
all the included colorscheme can be found in [colorscheme layer](layers/colorscheme/).
|
||||
all the included colorscheme can be found in [colorscheme layer](../layers/colorscheme/).
|
||||
|
||||
**NOTE**:
|
||||
|
||||
@ -816,11 +816,9 @@ All plugins can be easily discovered via `<leader> l p`.
|
||||
If you want to add plugin from github, just add the repo name to the SpaceVim option `custom_plugins`:
|
||||
|
||||
```toml
|
||||
# custom plugins {{{
|
||||
[[custom_plugins]]
|
||||
name = 'lilydjwg/colorizer'
|
||||
merged = 0
|
||||
# }}}
|
||||
```
|
||||
|
||||
#### Toggles
|
||||
|
@ -25,7 +25,7 @@ To use this configuration layer, add this snippet to your custom configuration f
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'colorscheme'
|
||||
name = "colorscheme"
|
||||
```
|
||||
|
||||
## Configuration
|
||||
@ -55,13 +55,13 @@ Vim background color. SpaceVim support to change the background color with
|
||||
```toml
|
||||
[options]
|
||||
colorscheme = "onedark"
|
||||
colorscheme_bg = 'dark'
|
||||
colorscheme_bg = "dark"
|
||||
```
|
||||
|
||||
colorscheme layer support random colorscheme on startup. just load this layer with layer option `random-theme`
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'colorscheme'
|
||||
name = "colorscheme"
|
||||
random-theme = true
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user