1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:20:04 +08:00

Add tabmanager

This commit is contained in:
wsdjeg 2017-05-12 21:56:04 +08:00
parent 103d4f9c26
commit 843d32b3f5
6 changed files with 115 additions and 4 deletions

View File

@ -14,13 +14,15 @@ 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', '')
let Initfunc = get(a:opts, 'initfunc', '')
if empty(buf)
exe mode buf
exe mode | enew
else
exe mode buf
endif
exe cmd
if !empty(Initfunc)
call call(Initfunc, [])
endif
endfunction
@ -29,6 +31,6 @@ func! s:self.resize(size, ...) abort
exe cmd 'resize' a:size
endf
fu! SpaceVim#api#vim#buffer#get()
fu! SpaceVim#api#vim#buffer#get() abort
return deepcopy(s:self)
endf

View File

@ -19,3 +19,12 @@ function! s:self._jump(tabnr, bufid) abort
exe winnr . 'wincmd w'
endif
endfunction
function! s:self.get_tree() abort
call self._update()
return self._tree
endfunction
function! SpaceVim#api#vim#tab#get() abort
return deepcopy(s:self)
endfunction

View File

@ -29,6 +29,8 @@ function! SpaceVim#layers#ui#config() abort
\ 'toggle-colorcolume', 1)
call SpaceVim#mapping#space#def('nnoremap', ['t', 'b'], 'call ToggleBG()',
\ 'toggle background', 1)
call SpaceVim#mapping#space#def('nnoremap', ['t', 't'], 'call SpaceVim#plugins#tabmanager#open()',
\ 'Open tabs manager', 1)
call SpaceVim#mapping#space#def('nnoremap', ['t', 'f'], 'call call('
\ . string(s:_function('s:toggle_colorcolumn')) . ', [])',
\ 'toggle-colorcolume', 1)

View File

@ -0,0 +1,61 @@
" APIs
let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:TABs = SpaceVim#api#import('vim#tab')
" Interface
function! SpaceVim#plugins#tabmanager#open() abort
call s:BUFFER.open(
\ {
\ 'bufname' : '__Tabmanager__',
\ 'initfunc' : function('s:init_buffer'),
\ }
\ )
call s:BUFFER.resize(30)
call s:update_context()
endfunction
" local functions
function! s:init_buffer() abort
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nomodifiable nospell
setf SpaceVimTabsManager
nnoremap <silent> <buffer> q :bd<CR>
nnoremap <silent> <buffer> <CR> :call <SID>jump()<CR>
endfunction
function! s:update_context() abort
setl modifiable
let tree = s:TABs.get_tree()
let ctx = []
for page in keys(tree)
call add(ctx, 'Tab #' . page)
for _buf in tree[page]
if getbufvar(_buf, '&buflisted')
call add(ctx, ' ' . _buf . ':' . bufname(_buf))
endif
endfor
endfor
call setline(1, ctx)
setl nomodifiable
endfunction
function! s:jump() abort
let t = s:tabid()
let b = s:bufid()
q
call s:TABs._jump(t,b)
endfunction
function! s:tabid() abort
for i in range(0, line('.'))
if getline(line('.') - i) =~# '^Tab'
return matchstr(getline(line('.') - i), '\d\+$')
endif
endfor
endfunction
function! s:bufid() abort
let id = str2nr(split(getline('.'), ':')[0])
return id
endfunction

View File

@ -0,0 +1,20 @@
if exists('g:_SpaceVimTabsManager_ftplugin')
finish
else
let g:_SpaceVimTabsManager_ftplugin = 1
endif
function! SpaceVimTabsManager#statusline(...)
if &ft ==# 'SpaceVimTabsManager'
call airline#extensions#apply_left_override('SpaceVimTabs', '')
" Alternatively, set the various w:airline_section variables
"let w:airline_section_a = 'SpaceVimPluginManager'
"let w:airline_section_b = ''
"let w:airline_section_c = ''
"let w:airline_render_left = 1
"let w:airline_render_right = 0
endif
endfunction
try
call airline#add_statusline_func('SpaceVimTabsManager#statusline')
catch
endtry

View File

@ -0,0 +1,17 @@
sy match TabManTName '^Tab #\d\+$\|^".*\zsTab#'
sy match TabManCurTName '^Tab #\d\+\ze\*$'
sy match TabManAtv '\*$'
sy match TabManLead '[|`]-'
sy match TabManTag '+$'
sy match TabManHKey '" \zs[^:]*\ze[:,]'
sy match TabManHSpecial '\[[^ ]\+\]'
sy match TabManHelp '^".*' contains=TabManHKey,TabManTName,TabManHSpecial
hi def link TabManTName Directory
hi def link TabManCurTName Identifier
hi def link TabManAtv Title
hi def link TabManLead Special
hi def link TabManTag Title
hi def link TabManHKey Identifier
hi def link TabManHSpecial Special
hi def link TabManHelp String