diff --git a/autoload/SpaceVim/api/vim/buffer.vim b/autoload/SpaceVim/api/vim/buffer.vim index f6c1ffe14..3a7d5ac37 100644 --- a/autoload/SpaceVim/api/vim/buffer.vim +++ b/autoload/SpaceVim/api/vim/buffer.vim @@ -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 diff --git a/autoload/SpaceVim/api/vim/tab.vim b/autoload/SpaceVim/api/vim/tab.vim index a287f0fc8..a40745ca9 100644 --- a/autoload/SpaceVim/api/vim/tab.vim +++ b/autoload/SpaceVim/api/vim/tab.vim @@ -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 diff --git a/autoload/SpaceVim/layers/ui.vim b/autoload/SpaceVim/layers/ui.vim index 41b8e6678..66b434d26 100644 --- a/autoload/SpaceVim/layers/ui.vim +++ b/autoload/SpaceVim/layers/ui.vim @@ -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) diff --git a/autoload/SpaceVim/plugins/tabmanager.vim b/autoload/SpaceVim/plugins/tabmanager.vim new file mode 100644 index 000000000..ce8ad5d62 --- /dev/null +++ b/autoload/SpaceVim/plugins/tabmanager.vim @@ -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 q :bd + nnoremap :call jump() +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 + diff --git a/ftplugin/SpaceVimTabsManager.vim b/ftplugin/SpaceVimTabsManager.vim new file mode 100644 index 000000000..d280c9bde --- /dev/null +++ b/ftplugin/SpaceVimTabsManager.vim @@ -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 diff --git a/syntax/SpaceVimTabsManager.vim b/syntax/SpaceVimTabsManager.vim new file mode 100644 index 000000000..1877e20de --- /dev/null +++ b/syntax/SpaceVimTabsManager.vim @@ -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