mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-13 13:50:40 +08:00
Update highlight API (#2145)
This commit is contained in:
parent
364404fc01
commit
8e4b3a555b
@ -125,6 +125,52 @@ function! s:self.hi_separator(a, b) abort
|
||||
call self.hi(hi_b_a)
|
||||
endfunction
|
||||
|
||||
function! s:self.syntax_at(...) abort
|
||||
syntax sync fromstart
|
||||
if a:0 < 2
|
||||
let l:pos = getpos('.')
|
||||
let l:cur_lnum = pos[1]
|
||||
let l:cur_col = pos[2]
|
||||
if a:0 == 0
|
||||
let l:lnum = l:cur_lnum
|
||||
let l:col = l:cur_col
|
||||
else
|
||||
let l:lnum = l:cur_lnum
|
||||
let l:col = a:1
|
||||
endif
|
||||
else
|
||||
let l:lnum = a:1
|
||||
let l:col = a:2
|
||||
endif
|
||||
call map(synstack(l:lnum, l:col), 'synIDattr(v:val, "name")')
|
||||
return synIDattr(synID(l:lnum, l:col, 1), 'name')
|
||||
endfunction
|
||||
|
||||
function! s:self.syntax_of(pattern, ...) abort
|
||||
if a:0 < 1
|
||||
let l:nth = 1
|
||||
else
|
||||
let l:nth = a:1
|
||||
endif
|
||||
|
||||
let l:pos_init = getpos('.')
|
||||
call cursor(1, 1)
|
||||
let found = search(a:pattern, 'cW')
|
||||
while found != 0 && nth > 1
|
||||
let found = search(a:pattern, 'W')
|
||||
let nth -= 1
|
||||
endwhile
|
||||
|
||||
if found
|
||||
let l:pos = getpos('.')
|
||||
let l:output = self.syntax_at(l:pos[1], l:pos[2])
|
||||
else
|
||||
let l:output = ''
|
||||
endif
|
||||
call setpos('.', l:pos_init)
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#api#vim#highlight#get() abort
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
|
37
docs/api.md
37
docs/api.md
@ -1,10 +1,9 @@
|
||||
---
|
||||
title: "APIs"
|
||||
title: Available APIs
|
||||
description: "A list of available APIs in SpaceVim, provide compatible functions for vim and neovim."
|
||||
redirect_from: "/apis/"
|
||||
---
|
||||
|
||||
# SpaceVim APIs
|
||||
# Available APIs
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
@ -13,7 +12,7 @@ redirect_from: "/apis/"
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Introduction
|
||||
#### 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.
|
||||
@ -35,21 +34,25 @@ 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#string](data/string/) | data#string API provides some besic functions and values for string. |
|
||||
| [file](file/) | file API provides some besic functions and values for current os. |
|
||||
| [job](job/) | job API provides some besic functions for running a job |
|
||||
| [logger](logger/) | logger API provides some besic functions for log message when create plugins |
|
||||
| [messletters](messletters/) | messletters API provides some besic functions for generating messletters |
|
||||
| [password](password/) | password API provides some besic functions for generating password |
|
||||
| [system](system/) | system API provides some besic functions and values for current os. |
|
||||
| [web#html](web/html/) | web#html API provides some besic functions and values for parser html file. |
|
||||
| [web#http](web/http/) | web#http API provides some besic functions and values for http request |
|
||||
| [web#xml](web/xml/) | web#xml API provides some besic 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 besic functions and values for dict. |
|
||||
| [data#string](data/string/) | data#string API provides some besic functions and values for string. |
|
||||
| [data#toml](data/toml/) | data#toml API provides some besic functions and values for toml. |
|
||||
| [file](file/) | file API provides some besic functions and values for current os. |
|
||||
| [job](job/) | job API provides some besic functions for running a job |
|
||||
| [logger](logger/) | logger API provides some besic functions for log message when create plugins |
|
||||
| [messletters](messletters/) | messletters API provides some besic functions for generating messletters |
|
||||
| [password](password/) | password API provides some besic functions for generating password |
|
||||
| [system](system/) | system API provides some besic functions and values for current os. |
|
||||
| [vim#highlight](vim/highlight/) | vim#highlight API provides some besic functions and values for getting and setting highlight info. |
|
||||
| [web#html](web/html/) | web#html API provides some besic functions and values for parser html file. |
|
||||
| [web#http](web/http/) | web#http API provides some besic functions and values for http request |
|
||||
| [web#xml](web/xml/) | web#xml API provides some besic functions and values for parser xml file. |
|
||||
|
||||
<!-- SpaceVim api list end -->
|
||||
|
28
docs/api/vim/highlight.md
Normal file
28
docs/api/vim/highlight.md
Normal file
@ -0,0 +1,28 @@
|
||||
---
|
||||
title: "vim#highlight api"
|
||||
description: "vim#highlight API provides some besic functions and values for getting and setting highlight info."
|
||||
---
|
||||
|
||||
# [Available APIs](../../) >> vim#highlight
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Intro](#intro)
|
||||
- [Functions](#functions)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Intro
|
||||
|
||||
vim#highlight API provides some besic functions and values for getting and setting highlight info.
|
||||
|
||||
## Functions
|
||||
|
||||
| function name | description |
|
||||
| ------------------------- | ---------------------------------------- |
|
||||
| `group2dict(name)` | get a dict of highligh group info |
|
||||
| `hi(info)` | run highligh command base on info |
|
||||
| `hide_in_normal(name)` | hide a group in normal |
|
||||
| `hi_separator(a, b)` | create separator for group a and group b |
|
||||
| `syntax_at(...)` | get syntax info at a position |
|
||||
| `syntax_of(pattern, ...)` | get syntax info of a pattern |
|
@ -1,23 +1,35 @@
|
||||
---
|
||||
title: "公共 API"
|
||||
description: "SpaceVim 公共 API 提供了一套开发插件的公共函数,以及 neovim 和 vim 的兼容组件"
|
||||
redirect_from: "/cn/apis/"
|
||||
lang: cn
|
||||
---
|
||||
|
||||
# SpaceVim 公共 APIs
|
||||
# 公共 API
|
||||
|
||||
SpaceVim 提供了许多公共的 apis,你可以在你的插件中使用这些公共 apis,SpaceVim 的公共 apis 借鉴与 [vital.vim](https://github.com/vim-jp/vital.vim)
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
## 使用方法
|
||||
- [简介](#简介)
|
||||
- [使用方法](#使用方法)
|
||||
- [可用 APIs](#可用-apis)
|
||||
|
||||
可以使用 `SpaceVim#api#import()` 方法导入 API。参考以下示例:
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
#### 简介
|
||||
|
||||
为了兼容不同版本的 Vim,避免使用重复的兼容函数,SpaceVim 提供了一套兼容的公共 API。开发插件时,
|
||||
可以在你的插件中使用这些公共 API,这一思想主要借鉴于 [vital.vim](https://github.com/vim-jp/vital.vim)。
|
||||
|
||||
#### 使用方法
|
||||
|
||||
可以通过 `SpaceVim#api#import()` 函数导入相关 API,参考以下示例:
|
||||
|
||||
```viml
|
||||
|
||||
" 导入 file API,并赋值给变量 s:file
|
||||
let s:file = SpaceVim#api#import('file')
|
||||
" 导入 system API,并赋值给变量 s:system
|
||||
let s:system = SpaceVim#api#import('system')
|
||||
|
||||
" 调用 system API 的 isWindows 成员变量
|
||||
if s:system.isWindows
|
||||
echom "Os is Windows"
|
||||
endif
|
||||
@ -25,15 +37,15 @@ echom s:file.separator
|
||||
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)
|
||||
#### 可用 APIs
|
||||
|
||||
| 名称 | 描述 |
|
||||
| ------------------------------- | -------------------------------------------------------------- |
|
||||
| [file](file/) | can not find Description |
|
||||
| [job](job/) | 兼容 neovim 和 vim 的异步协同 API,对于旧版 vim 采用非异步机制 |
|
||||
| [system](system/) | can not find Description |
|
||||
| [vim#highlight](vim/highlight/) | vim#highlight API 提供一些设置和获取 Vim 高亮信息的基础函数。 |
|
||||
|
||||
<!-- SpaceVim api cn list end -->
|
||||
|
||||
|
@ -4,13 +4,41 @@ description: "兼容 neovim 和 vim 的异步协同 API,对于旧版 vim 采
|
||||
lang: cn
|
||||
---
|
||||
|
||||
# [SpaceVim 公共函数](https://spacevim.org/cn/apis) - 异步协同(job)
|
||||
# [公共 API](../) >> job
|
||||
|
||||
`job` API 提供了一套可以兼容 neovim 和 vim 的异步控制机制,具体实现模型是参考的 neovim 的模型,具体示例如下:
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [简介](#简介)
|
||||
- [函数及变量](#函数及变量)
|
||||
- [使用示例](#使用示例)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
#### 简介
|
||||
|
||||
`job`API 提供了一套可以兼容 neovim 和 vim 的异步控制机制,具体实现模型是参考的 neovim 的模型。
|
||||
|
||||
#### 函数及变量
|
||||
|
||||
| 名称 | 描述 |
|
||||
| ------------------ | ---------------------------- |
|
||||
| `start(cmd, argv)` | 开始一个 job, 并返回 job id. |
|
||||
| `send(id, data)` | 传递数据至指定 id 的 job |
|
||||
| `stop(id)` | 终止指定 id 的 job |
|
||||
| `status(id)` | 查看指定 id 的 job 的状态 |
|
||||
| `list()` | 列出所有 job |
|
||||
|
||||
以上这个 api 仅提供了基础的 job 函数,当你的脚本需要用到 job 高级功能时,建议直接使用 neovim 或 vim 内置函数。
|
||||
|
||||
#### 使用示例
|
||||
|
||||
以下为通过该 API 异步执行命令 `python test.py`,并设置相关的回调函数:
|
||||
|
||||
```vim
|
||||
" 导入 job API 并赋值给 s:JOB
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
|
||||
" 定义回调函数,这里定义了三个回调函数,分别对应 stdout stderr 以及 exit。
|
||||
function! s:on_stdout(id, data, event) abort
|
||||
" do something with stdout
|
||||
endfunction
|
||||
@ -27,23 +55,13 @@ 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'),
|
||||
\ '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. |
|
||||
| `send(id, data)` | 传递数据至指定 id 的 job |
|
||||
| `stop(id)` | 终止指定 id 的 job |
|
||||
| `status(id)` | 查看指定 id 的 job 的状态 |
|
||||
| `list()` | 列出所有 job |
|
||||
|
||||
以上这个 api 仅提供了基础的 job 函数,当你的脚本需要用到 job 高级功能时,建议直接使用 neovim 或 vim 内置函数。
|
||||
|
30
docs/cn/api/vim/highlight.md
Normal file
30
docs/cn/api/vim/highlight.md
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
title: "vim#highlight api"
|
||||
description: "vim#highlight API 提供一些设置和获取 Vim 高亮信息的基础函数。"
|
||||
lang: cn
|
||||
---
|
||||
|
||||
# [可用 APIs](../../) >> vim#highlight
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Intro](#intro)
|
||||
- [Functions](#functions)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Intro
|
||||
|
||||
vim#highlight API provides some besic functions and values for getting and setting highlight info.
|
||||
|
||||
## Functions
|
||||
|
||||
| function name | description |
|
||||
| ------------------------- | ---------------------------------------- |
|
||||
| `group2dict(name)` | get a dict of highligh group info |
|
||||
| `hi(info)` | run highligh command base on info |
|
||||
| `hide_in_normal(name)` | hide a group in normal |
|
||||
| `hi_separator(a, b)` | create separator for group a and group b |
|
||||
| `syntax_at(...)` | get syntax info at a position |
|
||||
| `syntax_of(pattern, ...)` | get syntax info of a pattern |
|
||||
|
@ -68,7 +68,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
|
||||
| [core#banner](core/banner/) | This layer provides many default banner on welcome page. |
|
||||
| [core#statusline](core/statusline/) | 这一模块为 SpaceVim 提供了默认的模式化的状态了支持。 |
|
||||
| [core#tabline](core/tabline/) | SpaceVim core#tabline layer provides a better tabline for SpaceVim |
|
||||
| [core](core/) | SpaceVim core layer provides many default key bindings and features. |
|
||||
| [core](core/) | core 模块主要包括 SpaceVim 启动及基本操作所必须的插件及配置。 |
|
||||
| [cscope](cscope/) | cscope 模块为 SpaceVim 他提供了一个智能的 cscope 和 pycscope 辅助工具,可以快速调用 cscope 常用命令 |
|
||||
| [ctrlp](ctrlp/) | 提供以 ctrlp 为核心的模糊查找机制,支持模糊搜索文件、历史纪录、函数列表等。 |
|
||||
| [debug](debug/) | 这一模块为 SpaceVim 提供了 debug 的常用功能,采用 vebugger 作为后台框架,支持多种 debug 工具。 |
|
||||
@ -98,7 +98,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
|
||||
| [lang#java](lang/java/) | 这一模块为 java 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#javascript](lang/javascript/) | 这一模块为 javascript 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#julia](lang/julia/) | 这一模块为 julia 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#kotlin](lang/kotlin/) | This layer adds kotlin language support to SpaceVim |
|
||||
| [lang#kotlin](lang/kotlin/) | 该模块为 SpaceVim 提供了 kotlin 语言开发支持,包括语法高亮、语言服务器支持。 |
|
||||
| [lang#latex](lang/latex/) | 这一模块为 latex 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#lisp](lang/lisp/) | 这一模块为 lisp 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#lua](lang/lua/) | 这一模块为 lua 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
@ -114,7 +114,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
|
||||
| [lang#rust](lang/rust/) | 这一模块为 rust 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#scala](lang/scala/) | 这一模块为 scala 开发提供支持,包括语法高亮,函数列表等特性 |
|
||||
| [lang#sh](lang/sh/) | 这一模块为 shell script 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#swift](lang/swift/) | swift language support for SpaceVim, includes code completion, syntax highlighting |
|
||||
| [lang#swift](lang/swift/) | 该模块主要为 SpaceVim 提供了 swift 开发支持,包括语法高亮、语法检查等特性。 |
|
||||
| [lang#typescript](lang/typescript/) | 这一模块为 typescript 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#vim](lang/vim/) | 这一模块为 vim script 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
| [lang#vue](lang/vue/) | 这一模块为 vue 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
|
||||
@ -123,11 +123,10 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
|
||||
| [shell](shell/) | 这一模块为 SpaceVim 提供了终端集成特性,优化内置终端的使用体验 |
|
||||
| [sudo](sudo/) | sudo 提供了在 SpaceVim 中以管理员身份读写文件的功能。 |
|
||||
| [tags](tags/) | tags 模块提供全局的 tags 索引管理,提供快速检索定义和引用的功能。 |
|
||||
| [tmux](tmux/) | This layers adds extensive support for tmux |
|
||||
| [tmux](tmux/) | 该模块主要提供了一些在 Vim 内操作 tmux 的功能,使得在 tmux 窗口之间跳转更加便捷。 |
|
||||
| [tools#dash](tools/dash/) | 该模块提供对 Dash 支持,可快速查找光标位置的单词 |
|
||||
| [tools](tools/) | 集成多种常用工具,包括日历、计算器、等等多种工具类插件,该模块针对 vim8 以及 neovim 提供了更好的插件选择。 |
|
||||
| [ui](ui/) | SpaceVim ui 模块提供了一个 IDE-like 的界面,包括状态栏、文件树、语法数等等特性。 |
|
||||
| [unite](unite/) | 提供以 unite 为核心的模糊查找机制,支持模糊搜索文件、历史纪录、函数列表等。 |
|
||||
|
||||
<!-- SpaceVim layer cn list end -->
|
||||
|
@ -69,10 +69,10 @@ enable = false
|
||||
| [checkers](checkers/) | Syntax checking automatically within SpaceVim, display error on the sign column and statusline. |
|
||||
| [chinese](chinese/) | Layer for chinese users, include chinese docs and runtime messages |
|
||||
| [colorscheme](colorscheme/) | colorscheme provides a list of colorscheme for SpaceVim, default colorscheme is gruvbox with dark theme. |
|
||||
| [core#banner](core/banner/) | "This layer provides many default banner on welcome page. |
|
||||
| [core#banner](core/banner/) | This layer provides many default banner on welcome page. |
|
||||
| [core#statusline](core/statusline/) | This layer provides default statusline for SpaceVim |
|
||||
| [core#tabline](core/tabline/) | SpaceVim core#tabline layer provides a better tabline for SpaceVim |
|
||||
| [core](core/) | "SpaceVim core layer provides many default key bindings and features. |
|
||||
| [core](core/) | SpaceVim core layer provides many default key bindings and features. |
|
||||
| [cscope](cscope/) | cscope layer provides a smart cscope and pycscope helper for SpaceVim, help users win at cscope |
|
||||
| [ctrlp](ctrlp/) | This layers provide a heavily customized ctrlp centric work-flow |
|
||||
| [debug](debug/) | This layer provide debug workflow support in SpaceVim |
|
||||
@ -131,7 +131,6 @@ enable = false
|
||||
| [tools#dash](tools/dash/) | This layer provides Dash integration for SpaceVim |
|
||||
| [tools](tools/) | This layer provides some tools for vim |
|
||||
| [ui](ui/) | Awesome UI layer for SpaceVim, provide IDE-like UI for neovim and vim in both TUI and GUI |
|
||||
| [unite](unite/) | This layers provide a heavily customized Unite centric work-flow |
|
||||
|
||||
<!-- SpaceVim layer list end -->
|
||||
|
@ -106,6 +106,7 @@ The next release is v0.9.0.
|
||||
- Update key notations ([#1940](https://github.com/SpaceVim/SpaceVim/pull/1940))
|
||||
- Update getting help page in wiki ([#2025](https://github.com/SpaceVim/SpaceVim/pull/2025))
|
||||
- Add doc for missing layers ([#2139](https://github.com/SpaceVim/SpaceVim/pull/2139))
|
||||
- Add doc highlight API ([#2145](https://github.com/SpaceVim/SpaceVim/pull/2145))
|
||||
|
||||
### Others
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user