mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 01:40:05 +08:00
Add type func (#3666)
This commit is contained in:
parent
c0a652c028
commit
31768c56ce
@ -134,6 +134,50 @@ function! s:self.is_qf_win(winnr) abort
|
||||
return a:winnr ==# self.get_qf_winnr()
|
||||
endfunction
|
||||
|
||||
function! s:self.is_number(var) abort
|
||||
return type(a:var) ==# 0
|
||||
endfunction
|
||||
|
||||
function! s:self.is_string(var) abort
|
||||
return type(a:var) ==# 1
|
||||
endfunction
|
||||
|
||||
function! s:self.is_func(var) abort
|
||||
return type(a:var) ==# 2
|
||||
endfunction
|
||||
|
||||
function! s:self.is_list(var) abort
|
||||
return type(a:var) ==# 3
|
||||
endfunction
|
||||
|
||||
function! s:self.is_dict(var) abort
|
||||
return type(a:var) ==# 4
|
||||
endfunction
|
||||
|
||||
function! s:self.is_float(var) abort
|
||||
return type(a:var) ==# 5
|
||||
endfunction
|
||||
|
||||
function! s:self.is_bool(var) abort
|
||||
return type(a:var) ==# 6
|
||||
endfunction
|
||||
|
||||
function! s:self.is_none(var) abort
|
||||
return type(a:var) ==# 7
|
||||
endfunction
|
||||
|
||||
function! s:self.is_job(var) abort
|
||||
return type(a:var) ==# 8
|
||||
endfunction
|
||||
|
||||
function! s:self.is_channel(var) abort
|
||||
return type(a:var) ==# 9
|
||||
endfunction
|
||||
|
||||
function! s:self.is_blob(var) abort
|
||||
return type(a:var) ==# 10
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#api#vim#get() abort
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
|
@ -9,6 +9,7 @@
|
||||
let s:TOML = SpaceVim#api#import('data#toml')
|
||||
let s:JSON = SpaceVim#api#import('data#json')
|
||||
let s:FILE = SpaceVim#api#import('file')
|
||||
let s:VIM = SpaceVim#api#import('vim')
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
|
||||
function! SpaceVim#custom#profile(dict) abort
|
||||
@ -241,13 +242,13 @@ function! s:opt_type(opt) abort
|
||||
" @bugupstream viml-parser seem do not think this is used argument
|
||||
let opt = a:opt
|
||||
let var = get(g:, 'spacevim_' . opt, '')
|
||||
if type(var) == type('')
|
||||
if s:VIM.is_string(var)
|
||||
return '[string]'
|
||||
elseif type(var) == 5
|
||||
elseif s:VIM.is_bool(var)
|
||||
return '[boolean]'
|
||||
elseif type(var) == 0
|
||||
elseif s:VIM.is_number(var)
|
||||
return '[number]'
|
||||
elseif type(var) == 3
|
||||
elseif s:VIM.is_list(var)
|
||||
return '[list]'
|
||||
endif
|
||||
endfunction
|
||||
|
62
docs/api/vim.md
Normal file
62
docs/api/vim.md
Normal file
@ -0,0 +1,62 @@
|
||||
---
|
||||
title: "vim api"
|
||||
description: "vim API provides general vim functions."
|
||||
---
|
||||
|
||||
# [Available APIs](../) >> vim
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Intro](#intro)
|
||||
- [Functions](#functions)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Intro
|
||||
|
||||
vim API provides general vim functions.
|
||||
|
||||
## Functions
|
||||
|
||||
**Type checking:**
|
||||
|
||||
- `is_number(var)`
|
||||
- `is_string(var)`
|
||||
- `is_func(var)`
|
||||
- `is_list(var)`
|
||||
- `is_dict(var)`
|
||||
- `is_float(var)`
|
||||
- `is_bool(var)`
|
||||
- `is_none(var)`
|
||||
- `is_job(var)`
|
||||
- `is_channel(var)`
|
||||
- `is_blob(var)`
|
||||
|
||||
here is an example for using type checking functions:
|
||||
|
||||
```vim
|
||||
let s:VIM = SpaceVim#api#import('vim')
|
||||
let var = 'hello world'
|
||||
if s:VIM.is_string(var)
|
||||
echo 'It is a string'
|
||||
endif
|
||||
```
|
||||
|
||||
**Others:**
|
||||
|
||||
- `win_set_cursor(winid, pos)`: change the cursor position of specific window.
|
||||
- `jumps()`: return the jump list
|
||||
- `setbufvar(bufnr, dict)`: the second argv is a dictionary, set all the options based on the keys in `dict`.
|
||||
for example:
|
||||
```vim
|
||||
let s:VIM = SpaceVim#api#import('vim')
|
||||
call s:VIM.setbufvar(s:bufnr, {
|
||||
\ '&filetype' : 'leaderGuide',
|
||||
\ '&number' : 0,
|
||||
\ '&relativenumber' : 0,
|
||||
\ '&list' : 0,
|
||||
\ '&modeline' : 0,
|
||||
\ '&wrap' : 0,
|
||||
\ '&buflisted' : 0,
|
||||
\ }
|
||||
```
|
@ -1825,7 +1825,7 @@ function! s:make_tasks() abort
|
||||
return {}
|
||||
endif
|
||||
endfunction
|
||||
call SpaceVim#plugins#tasks#reg_provider(funcref('s:make_tasks'))
|
||||
call SpaceVim#plugins#tasks#reg_provider(function('s:make_tasks'))
|
||||
```
|
||||
|
||||
with above configuration, you will see following tasks in SpaceVim repo:
|
||||
|
Loading…
Reference in New Issue
Block a user