1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-22 08:45:42 +08:00
* Add vimautoload\SpaceVim\api\job.vimmessage api

* Add scriptnames func

* Add vim#buffer is_cmdwin

* Add test for vim#buffer is_cmdwin()

* Update buffer.vim

* Update buffer.vader

* Add vim buffer api

* Add resize func

* Fix test

* Add vim#tab api
This commit is contained in:
Timg 2017-05-07 23:34:27 +08:00 committed by Wang Shidong
parent b03ca97e13
commit 81d7f535b8
6 changed files with 166 additions and 0 deletions

View File

@ -0,0 +1,34 @@
let s:self = {}
if exists('*getcmdwintype')
function! s:self.is_cmdwin() abort
return getcmdwintype() !=# ''
endfunction
else
function! s:self.is_cmdwin() abort
return bufname('%') ==# '[Command Line]'
endfunction
endif
function! s:self.open(opts) abort
let buf = get(a:opts, 'bufname', '')
let mode = get(a:opts, 'mode', 'vertical topleft split')
let cmd = get(a:opts, 'cmd', '')
if empty(buf)
exe mode bufopt
else
exe mode buf
endif
exe cmd
endfunction
func! s:self.resize(size, ...) abort
let cmd = get(a:000, 0, 'vertical')
exe cmd 'resize' a:size
endf
fu! SpaceVim#api#vim#buffer#get()
return deepcopy(s:self)
endf

View File

@ -0,0 +1,50 @@
" ============================================================================
" File: message.vim
" Description: vim#message api of SpaceVim
" Author: L-stt
" Website: https://spacevim.org
" License: MIT
" ============================================================================
""
" @section vim#message, api-vim-message
" @parentsection api
function! SpaceVim#api#vim#compatible#get() abort
return map({
\ 'echo' : '',
\ 'echomsg': '',
\ 'error': '',
\ 'warn': '',
\ },
\ "function('s:' . v:key)"
\ )
endfunction
function! s:echo(hl, msg) abort
execute 'echohl' a:hl
try
echo a:msg
finally
echohl None
endtry
endfunction
function! s:echomsg(hl, msg) abort
execute 'echohl' a:hl
try
for m in split(a:msg, "\n")
echomsg m
endfor
finally
echohl None
endtry
endfunction
function! s:error(msg) abort
call s:echomsg('ErrorMsg', a:msg)
endfunction
function! s:warn(msg) abort
call s:echomsg('WarningMsg', a:msg)
endfunction

View File

@ -0,0 +1,49 @@
" ============================================================================
" File: sid.vim
" Description: vim#sid api of SpaceVim
" Author: L-stt
" Website: https://spacevim.org
" License: MIT
" ============================================================================
""
" @section sid, api-vim-sid
" @parentsection api
"" Capture command
let s:self = {}
let s:self._cache = {}
function! s:self._capture(command) abort
try
let save_verbose = &verbose
let &verbose = 0
redir => out
silent execute a:command
finally
redir END
let &verbose = save_verbose
endtry
return out
endfunction
function! s:self._unify_path(path) abort
return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?'))
endfunction
"" Capture command and return lines
function! s:self._capture_lines(command) abort
return split(self._capture(a:command), "\n")
endfunction
function! s:self.scriptnames() abort
let sdict = {} " { sid: path }
for line in self._capture_lines(':scriptnames')
let [sid, path] = split(line, '\m^\s*\d\+\zs:\s\ze')
let sdict[str2nr(sid)] = self._unify_path(path) " str2nr(): ' 1' -> 1
endfor
return sdict
endfunction
function! SpaceVim#api#vim#sid#get() abort
return deepcopy(s:self)
endfunction

View File

@ -0,0 +1,17 @@
let s:self = {}
let s:self._tree = {}
function! s:self._update() abort
let tabnr = tabpagenr('$')
if tabnr > 1
for i in range(1, tabnr)
let buffers = tabpagebuflist(i)
let self._tree[i] = buffers
endfor
endif
endfunction
function! s:self._jump(tabnr, bufid) abort
endfunction

View File

@ -47,6 +47,8 @@ CONTENTS *SpaceVim-contents*
24. tmux...........................................|SpaceVim-layer-tmux| 24. tmux...........................................|SpaceVim-layer-tmux|
6. API........................................................|SpaceVim-api| 6. API........................................................|SpaceVim-api|
1. cmdlinemenu................................|SpaceVim-api-cmdlinemenu| 1. cmdlinemenu................................|SpaceVim-api-cmdlinemenu|
2. sid............................................|SpaceVim-api-vim-sid|
3. vim#message................................|SpaceVim-api-vim-message|
7. FAQ........................................................|SpaceVim-faq| 7. FAQ........................................................|SpaceVim-faq|
============================================================================== ==============================================================================
@ -909,6 +911,14 @@ Create a cmdline selection menu from a list of {items}, each item should be a
list of two value in it, first one is the description, and the next one should list of two value in it, first one is the description, and the next one should
be a funcrc. be a funcrc.
==============================================================================
SID *SpaceVim-api-vim-sid*
" Capture command
==============================================================================
VIM#MESSAGE *SpaceVim-api-vim-message*
============================================================================== ==============================================================================
FAQ *SpaceVim-faq* FAQ *SpaceVim-faq*

View File

@ -0,0 +1,6 @@
Execute ( SpaceVim api: vim#buffer ):
new
let buffer = SpaceVim#api#import('vim#buffer')
call buffer.open({'bufname':'foo', 'cmd' : 'setl buftype=nofile bufhidden=wipe'})
AssertEqual bufname('%'), 'foo'
AssertEqual &buftype, 'nofile'