mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 10:40:03 +08:00
Improve tabline (#2242)
This commit is contained in:
parent
81aa834657
commit
6718b72a98
@ -11,6 +11,7 @@
|
||||
|
||||
[![Build Status](https://travis-ci.org/SpaceVim/SpaceVim.svg?branch=master)](https://travis-ci.org/SpaceVim/SpaceVim)
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/eh3t5oph70abp665/branch/master?svg=true)](https://ci.appveyor.com/project/wsdjeg/spacevim/branch/master)
|
||||
[![Docker Build Status](https://img.shields.io/docker/build/spacevim/spacevim.svg)](https://hub.docker.com/r/spacevim/spacevim/)
|
||||
[![codecov](https://codecov.io/gh/SpaceVim/SpaceVim/branch/master/graph/badge.svg)](https://codecov.io/gh/SpaceVim/SpaceVim/branch/master)
|
||||
![Version](https://img.shields.io/badge/version-1.6.0--dev-8700FF.svg)
|
||||
[![GPLv3 License](https://img.shields.io/badge/license-GPLv3-blue.svg)](LICENSE)
|
||||
|
@ -18,16 +18,26 @@
|
||||
" <
|
||||
|
||||
scriptencoding utf-8
|
||||
let s:messletters = SpaceVim#api#import('messletters')
|
||||
let s:file = SpaceVim#api#import('file')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
let s:HI = SpaceVim#api#import('vim#highlight')
|
||||
let s:SYS = SpaceVim#api#import('system')
|
||||
|
||||
if exists('g:_spacevim_tabline_loaded')
|
||||
finish
|
||||
endif
|
||||
|
||||
let g:_spacevim_tabline_loaded = 1
|
||||
let s:buffers = s:BUFFER.listed_buffers()
|
||||
|
||||
" loadding APIs {{{
|
||||
let s:MESSLETTERS = SpaceVim#api#import('messletters')
|
||||
let s:FILE = SpaceVim#api#import('file')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
let s:HI = SpaceVim#api#import('vim#highlight')
|
||||
let s:LOG = SpaceVim#logger#derive('tabline ')
|
||||
let s:SYS = SpaceVim#api#import('system')
|
||||
" }}}
|
||||
|
||||
|
||||
" init
|
||||
let s:buffers = s:BUFFER.listed_buffers()
|
||||
|
||||
let s:separators = {
|
||||
\ 'arrow' : ["\ue0b0", "\ue0b2"],
|
||||
\ 'curve' : ["\ue0b4", "\ue0b6"],
|
||||
@ -43,17 +53,11 @@ let s:i_separators = {
|
||||
\ 'nil' : ['', ''],
|
||||
\ }
|
||||
|
||||
function! s:tabname(id) abort
|
||||
if g:spacevim_buffer_index_type == 3
|
||||
let id = s:messletters.index_num(a:id)
|
||||
elseif g:spacevim_buffer_index_type == 4
|
||||
let id = a:id
|
||||
else
|
||||
let id = s:messletters.bubble_num(a:id, g:spacevim_buffer_index_type) . ' '
|
||||
endif
|
||||
let fn = fnamemodify(bufname(a:id), ':t')
|
||||
|
||||
function! s:tabname(bufnr) abort
|
||||
let fn = fnamemodify(bufname(a:bufnr), ':t')
|
||||
if g:spacevim_enable_tabline_ft_icon || get(g:, 'spacevim_enable_tabline_filetype_icon', 0)
|
||||
let icon = s:file.fticon(fn)
|
||||
let icon = s:FILE.fticon(fn)
|
||||
if !empty(icon)
|
||||
let fn = fn . ' ' . icon
|
||||
endif
|
||||
@ -61,99 +65,118 @@ function! s:tabname(id) abort
|
||||
if empty(fn)
|
||||
return 'No Name'
|
||||
else
|
||||
return id . fn
|
||||
return fn
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:need_show_bfname(stack, nr) abort
|
||||
let dupbufs = filter(a:stack, "fnamemodify(bufname(v:val), ':t') ==# fnamemodify(bufname(a:nr), ':t')")
|
||||
if len(dupbufs) >= 2
|
||||
for i in dupbufs
|
||||
call setbufvar(i, '_spacevim_statusline_showbfname', 1)
|
||||
endfor
|
||||
function! s:wrap_id(id) abort
|
||||
if g:spacevim_buffer_index_type == 3
|
||||
let id = s:MESSLETTERS.index_num(a:id)
|
||||
elseif g:spacevim_buffer_index_type == 4
|
||||
let id = a:id
|
||||
else
|
||||
let id = s:MESSLETTERS.bubble_num(a:id, g:spacevim_buffer_index_type) . ' '
|
||||
endif
|
||||
return id
|
||||
endfunction
|
||||
|
||||
function! s:buffer_item(bufnr, ...) abort
|
||||
let name = s:tabname(a:bufnr)
|
||||
let item = {
|
||||
\ 'bufnr' : a:bufnr,
|
||||
\ 'len' : strlen(name) + 3,
|
||||
\ 'bufname' : name,
|
||||
\ 'tabnr' : get(a:000, 0, -1),
|
||||
\ }
|
||||
return item
|
||||
endfunction
|
||||
|
||||
" check if the items len longer than &columns
|
||||
function! s:check_len(items) abort
|
||||
let len = 0
|
||||
for item in a:items
|
||||
let len += item.len
|
||||
endfor
|
||||
return len > &columns - 25
|
||||
endfunction
|
||||
|
||||
function! s:is_modified(nr) abort
|
||||
return getbufvar(a:nr, '&modified', 0)
|
||||
endfunction
|
||||
|
||||
" cache shown_items
|
||||
let s:shown_items = []
|
||||
function! SpaceVim#layers#core#tabline#get() abort
|
||||
let nr = tabpagenr('$')
|
||||
let t = ''
|
||||
" the stack should be the bufnr stack of tabline
|
||||
let stack = []
|
||||
if nr > 1
|
||||
let ct = tabpagenr()
|
||||
if ct == 1
|
||||
let t = '%#SpaceVim_tabline_a# '
|
||||
else
|
||||
let t = '%#SpaceVim_tabline_b# '
|
||||
endif
|
||||
let index = 1
|
||||
for i in range(1, nr)
|
||||
if i == ct
|
||||
let t .= '%#SpaceVim_tabline_a#'
|
||||
endif
|
||||
let buflist = tabpagebuflist(i)
|
||||
let winnr = tabpagewinnr(i)
|
||||
let bufname = bufname(buflist[winnr - 1])
|
||||
" let bufname = bufname(tabpagebuflist(i)[tabpagewinnr(i) - 1])
|
||||
if s:SYS.isWindows
|
||||
let bufname = substitute(bufname, '\\[', '[', 'g')
|
||||
let bufname = substitute(bufname, '\\]', ']', 'g')
|
||||
endif
|
||||
let name = fnamemodify(bufname, ':t')
|
||||
let tabname = gettabvar(i, '_spacevim_tab_name', '')
|
||||
if has('tablineat')
|
||||
let t .= '%' . index . '@SpaceVim#layers#core#tabline#jump@'
|
||||
elseif !has('nvim')
|
||||
let t .= '%' . index . 'T'
|
||||
endif
|
||||
if g:spacevim_buffer_index_type == 3
|
||||
let id = s:messletters.index_num(i)
|
||||
elseif g:spacevim_buffer_index_type == 4
|
||||
let id = i
|
||||
else
|
||||
let id = s:messletters.circled_num(i, g:spacevim_buffer_index_type)
|
||||
endif
|
||||
if empty(tabname)
|
||||
if empty(name)
|
||||
let name = 'No Name'
|
||||
endif
|
||||
call add(stack, buflist[winnr - 1])
|
||||
call s:need_show_bfname(stack, buflist[winnr - 1])
|
||||
if g:spacevim_enable_tabline_ft_icon || get(g:, 'spacevim_enable_tabline_filetype_icon', 0)
|
||||
let icon = s:file.fticon(name)
|
||||
if !empty(icon)
|
||||
let name = name . ' ' . icon
|
||||
endif
|
||||
endif
|
||||
let t .= id . ' ' . name
|
||||
else
|
||||
let t .= id . ' T:' . tabname
|
||||
endif
|
||||
if i == ct - 1
|
||||
let t .= ' %#SpaceVim_tabline_b_SpaceVim_tabline_a#' . s:lsep . ' '
|
||||
elseif i == ct
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep . ' '
|
||||
else
|
||||
let t .= ' ' . s:ilsep . ' '
|
||||
endif
|
||||
let index += 1
|
||||
let tabpage_counts = tabpagenr('$')
|
||||
let all_tabline_items = []
|
||||
let shown_items = []
|
||||
|
||||
if tabpage_counts > 1
|
||||
let current_tabnr = tabpagenr()
|
||||
let previous_tabnr = tabpagenr('#')
|
||||
let matched_len = 0
|
||||
for i in range(1, tabpage_counts)
|
||||
call add(all_tabline_items, s:buffer_item(tabpagebuflist(i)[tabpagewinnr(i) - 1], i))
|
||||
endfor
|
||||
let t .= '%=%#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:rsep
|
||||
let t .= '%#SpaceVim_tabline_a# Tabs '
|
||||
else
|
||||
let s:buffers = s:BUFFER.listed_buffers()
|
||||
let g:_spacevim_list_buffers = s:buffers
|
||||
if len(s:buffers) == 0
|
||||
return ''
|
||||
if previous_tabnr < current_tabnr
|
||||
for i in range(previous_tabnr, current_tabnr)
|
||||
call add(shown_items, all_tabline_items[i - 1])
|
||||
if s:check_len(shown_items)
|
||||
let matched_len = 1
|
||||
call remove(shown_items, 0)
|
||||
endif
|
||||
endfor
|
||||
if !matched_len && current_tabnr < tabpage_counts
|
||||
for i in range(current_tabnr + 1, tabpage_counts)
|
||||
call add(shown_items, all_tabline_items[i - 1])
|
||||
if s:check_len(shown_items)
|
||||
let matched_len = 1
|
||||
call remove(shown_items, -1)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
if !matched_len && previous_tabnr > 1
|
||||
for i in reverse(range(1, previous_tabnr - 1))
|
||||
call insert(shown_items, all_tabline_items[i - 1])
|
||||
if s:check_len(shown_items)
|
||||
call remove(shown_items, 0)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
else
|
||||
for i in range(current_tabnr, previous_tabnr)
|
||||
call add(shown_items, all_tabline_items[i - 1])
|
||||
if s:check_len(shown_items)
|
||||
let matched_len = 1
|
||||
call remove(shown_items, -1)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
if !matched_len && current_tabnr > 1
|
||||
for i in reverse(range(1, current_tabnr - 1))
|
||||
call insert(shown_items, all_tabline_items[i - 1])
|
||||
if s:check_len(shown_items)
|
||||
let matched_len = 1
|
||||
call remove(shown_items, 0)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
if !matched_len && previous_tabnr < tabpage_counts
|
||||
for i in range(previous_tabnr + 1, tabpage_counts)
|
||||
call add(shown_items, all_tabline_items[i - 1])
|
||||
if s:check_len(shown_items)
|
||||
call remove(shown_items, -1)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
let ct = bufnr('%')
|
||||
let pt = index(s:buffers, ct) > 0 ? s:buffers[index(s:buffers, ct) - 1] : -1
|
||||
if ct == get(s:buffers, 0, -1)
|
||||
if getbufvar(ct, '&modified', 0)
|
||||
let t = ''
|
||||
if current_tabnr == shown_items[0].tabnr
|
||||
if getbufvar(shown_items[0].bufnr, '&modified', 0)
|
||||
let t = '%#SpaceVim_tabline_m# '
|
||||
else
|
||||
let t = '%#SpaceVim_tabline_a# '
|
||||
@ -161,69 +184,188 @@ function! SpaceVim#layers#core#tabline#get() abort
|
||||
else
|
||||
let t = '%#SpaceVim_tabline_b# '
|
||||
endif
|
||||
let index = 1
|
||||
for i in s:buffers
|
||||
if getbufvar(i, '&modified', 0) && i != ct
|
||||
let t .= '%#SpaceVim_tabline_m_i#'
|
||||
elseif i == ct
|
||||
if s:is_modified(i)
|
||||
let t .= '%#SpaceVim_tabline_m#'
|
||||
else
|
||||
let t .= '%#SpaceVim_tabline_a#'
|
||||
for item in shown_items
|
||||
let t .= item.bufname
|
||||
if item.tabnr == current_tabnr - 1
|
||||
let t .= ' %#SpaceVim_tabline_b_SpaceVim_tabline_a#' . s:lsep . '%#SpaceVim_tabline_a# '
|
||||
elseif item.tabnr == current_tabnr
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep . '%#SpaceVim_tabline_b# '
|
||||
else
|
||||
let t .= ' ' . s:ilsep . ' '
|
||||
endif
|
||||
endfor
|
||||
let t .= '%=%#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:rsep
|
||||
let t .= '%#SpaceVim_tabline_a# Tabs '
|
||||
return t
|
||||
else
|
||||
let s:buffers = s:BUFFER.listed_buffers()
|
||||
if empty(s:buffers)
|
||||
return ''
|
||||
endif
|
||||
for i in range(len(s:buffers))
|
||||
call add(all_tabline_items, s:buffer_item(s:buffers[i]))
|
||||
endfor
|
||||
let current_buf_index = index(s:buffers, s:BUFFER.bufnr())
|
||||
let previous_buf_index = index(s:buffers, s:BUFFER.bufnr('#'))
|
||||
let matched_len = 0
|
||||
if current_buf_index ==# -1
|
||||
let shown_items = filter(s:shown_items, 'buflisted(v:val.bufnr)')
|
||||
else
|
||||
if previous_buf_index < current_buf_index
|
||||
if previous_buf_index == -1
|
||||
let previous_buf_index = 0
|
||||
endif
|
||||
for i in range(previous_buf_index, current_buf_index)
|
||||
call add(shown_items, all_tabline_items[i])
|
||||
if s:check_len(shown_items)
|
||||
let matched_len = 1
|
||||
call remove(shown_items, 0)
|
||||
endif
|
||||
endfor
|
||||
if !matched_len && current_buf_index < len(s:buffers) - 1
|
||||
for i in range(current_buf_index + 1, len(s:buffers) - 1)
|
||||
call add(shown_items, all_tabline_items[i])
|
||||
if s:check_len(shown_items)
|
||||
let matched_len = 1
|
||||
call remove(shown_items, -1)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
if !matched_len && previous_buf_index > 0
|
||||
for i in reverse(range(0, previous_buf_index - 1))
|
||||
call insert(shown_items, all_tabline_items[i])
|
||||
if s:check_len(shown_items)
|
||||
call remove(shown_items, 0)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
else
|
||||
let t .= '%#SpaceVim_tabline_b#'
|
||||
if previous_buf_index == -1
|
||||
let previous_buf_index = len(s:s:buffers) - 1
|
||||
endif
|
||||
for i in range(current_buf_index, previous_buf_index)
|
||||
call add(shown_items, all_tabline_items[i])
|
||||
if s:check_len(shown_items)
|
||||
let matched_len = 1
|
||||
call remove(shown_items, -1)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
if !matched_len && current_buf_index > 0
|
||||
for i in reverse(range(0, current_buf_index - 1))
|
||||
call insert(shown_items, all_tabline_items[i])
|
||||
if s:check_len(shown_items)
|
||||
let matched_len = 1
|
||||
call remove(shown_items, 0)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
if !matched_len && previous_buf_index < len(s:buffers) - 1
|
||||
for i in range(previous_buf_index + 1, len(s:buffers) - 1)
|
||||
call add(shown_items, all_tabline_items[i])
|
||||
if s:check_len(shown_items)
|
||||
call remove(shown_items, -1)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
let name = fnamemodify(bufname(i), ':t')
|
||||
if empty(name)
|
||||
let name = 'No Name'
|
||||
let s:shown_items = shown_items
|
||||
let g:_spacevim_list_buffers = map(deepcopy(s:shown_items), 'v:val.bufnr')
|
||||
endif
|
||||
if empty(shown_items)
|
||||
return ''
|
||||
endif
|
||||
let t = ''
|
||||
" how many buffers before the first item are hidden.
|
||||
let right_hidden_buffer_number = index(s:buffers, shown_items[0].bufnr)
|
||||
let left_hidden_buffer_number = len(s:buffers) - 1 - index(s:buffers, shown_items[-1].bufnr)
|
||||
if right_hidden_buffer_number > 0
|
||||
let t .= '%#SpaceVim_tabline_a#' . ' << '. right_hidden_buffer_number
|
||||
endif
|
||||
if s:BUFFER.bufnr() == shown_items[0].bufnr
|
||||
if s:is_modified(shown_items[0].bufnr)
|
||||
if right_hidden_buffer_number > 0
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_m#' . s:lsep
|
||||
endif
|
||||
let t .= '%#SpaceVim_tabline_m# '
|
||||
else
|
||||
if right_hidden_buffer_number > 0
|
||||
let t .= ' ' . s:ilsep
|
||||
endif
|
||||
let t .= '%#SpaceVim_tabline_a# '
|
||||
endif
|
||||
call add(stack, i)
|
||||
call s:need_show_bfname(stack, i)
|
||||
" here is the begin of a tab name
|
||||
else
|
||||
if right_hidden_buffer_number > 0
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep
|
||||
endif
|
||||
let t .= '%#SpaceVim_tabline_b# '
|
||||
endif
|
||||
let index = 1
|
||||
for item in shown_items[:-2]
|
||||
if has('tablineat')
|
||||
let t .= '%' . index . '@SpaceVim#layers#core#tabline#jump@'
|
||||
endif
|
||||
if g:spacevim_buffer_index_type == 3
|
||||
let id = s:messletters.index_num(index(s:buffers, i) + 1)
|
||||
elseif g:spacevim_buffer_index_type == 4
|
||||
let id = index(s:buffers, i) + 1
|
||||
else
|
||||
let id = s:messletters.circled_num(index(s:buffers, i) + 1, g:spacevim_buffer_index_type)
|
||||
endif
|
||||
if g:spacevim_enable_tabline_ft_icon || get(g:, 'spacevim_enable_tabline_filetype_icon', 0)
|
||||
let icon = s:file.fticon(name)
|
||||
if !empty(icon)
|
||||
let name = name . ' ' . icon
|
||||
endif
|
||||
endif
|
||||
let t .= id . ' ' . name
|
||||
" here is the end of a tabname
|
||||
if has('tablineat')
|
||||
let t .= '%X'
|
||||
endif
|
||||
if i == ct
|
||||
if s:is_modified(i)
|
||||
let t .= ' %#SpaceVim_tabline_m_SpaceVim_tabline_b#' . s:lsep . ' '
|
||||
else
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep . ' '
|
||||
endif
|
||||
elseif i == pt
|
||||
if getbufvar(ct, '&modified', 0)
|
||||
let t .= ' %#SpaceVim_tabline_b_SpaceVim_tabline_m#' . s:lsep . ' '
|
||||
else
|
||||
let t .= ' %#SpaceVim_tabline_b_SpaceVim_tabline_a#' . s:lsep . ' '
|
||||
endif
|
||||
else
|
||||
let t .= ' %#SpaceVim_tabline_b#' . s:ilsep . ' '
|
||||
endif
|
||||
let t .= s:wrap_id(index) . item.bufname
|
||||
let index += 1
|
||||
if item.bufnr == s:BUFFER.bufnr()
|
||||
if s:is_modified(item.bufnr)
|
||||
let t .= ' %#SpaceVim_tabline_m_SpaceVim_tabline_b#' . s:lsep . '%#SpaceVim_tabline_b# '
|
||||
else
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep . '%#SpaceVim_tabline_b# '
|
||||
endif
|
||||
elseif index(s:buffers, s:BUFFER.bufnr()) > 0 && item.bufnr == s:buffers[index(s:buffers, s:BUFFER.bufnr()) - 1]
|
||||
if s:is_modified(item.bufnr)
|
||||
let t .= ' %#SpaceVim_tabline_b_SpaceVim_tabline_m#' . s:lsep . '%#SpaceVim_tabline_m# '
|
||||
else
|
||||
let t .= ' %#SpaceVim_tabline_b_SpaceVim_tabline_a#' . s:lsep . '%#SpaceVim_tabline_a# '
|
||||
endif
|
||||
else
|
||||
let t .= ' ' . s:ilsep . ' '
|
||||
endif
|
||||
endfor
|
||||
let item = shown_items[-1]
|
||||
if has('tablineat')
|
||||
let t .= '%' . index . '@SpaceVim#layers#core#tabline#jump@'
|
||||
endif
|
||||
let t .= s:wrap_id(index) . item.bufname
|
||||
if item.bufnr == s:BUFFER.bufnr()
|
||||
if left_hidden_buffer_number > 0
|
||||
if s:is_modified(item.bufnr)
|
||||
let t .= ' %#SpaceVim_tabline_m_SpaceVim_tabline_a#' . s:lsep
|
||||
let t .= ' %#SpaceVim_tabline_a#' . left_hidden_buffer_number . ' >>'
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep . '%#SpaceVim_tabline_b#'
|
||||
else
|
||||
let t .= ' ' . s:ilsep
|
||||
let t .= ' ' . left_hidden_buffer_number . ' >>'
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep . '%#SpaceVim_tabline_b#'
|
||||
endif
|
||||
else
|
||||
if s:is_modified(item.bufnr)
|
||||
let t .= ' %#SpaceVim_tabline_m_SpaceVim_tabline_b#' . s:lsep . '%#SpaceVim_tabline_b#'
|
||||
else
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep . '%#SpaceVim_tabline_b#'
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if left_hidden_buffer_number > 0
|
||||
let t .= ' %#SpaceVim_tabline_b_SpaceVim_tabline_a#' . s:lsep
|
||||
let t .= ' %#SpaceVim_tabline_a#' . left_hidden_buffer_number . ' >>'
|
||||
let t .= ' %#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:lsep . '%#SpaceVim_tabline_b#'
|
||||
else
|
||||
let t .= ' ' . s:ilsep
|
||||
endif
|
||||
endif
|
||||
" how many buffers after the last item are hidden?
|
||||
let t .= '%=%#SpaceVim_tabline_a_SpaceVim_tabline_b#' . s:rsep
|
||||
let t .= '%#SpaceVim_tabline_a# Buffers '
|
||||
return t
|
||||
endif
|
||||
return t
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#core#tabline#config() abort
|
||||
let [s:lsep , s:rsep] = get(s:separators, g:spacevim_statusline_separator, s:separators['arrow'])
|
||||
let [s:ilsep , s:irsep] = get(s:i_separators, g:spacevim_statusline_iseparator, s:separators['arrow'])
|
||||
@ -238,40 +380,28 @@ function! SpaceVim#layers#core#tabline#config() abort
|
||||
\ . i . ")<cr>', 'Switch to airline tab " . i
|
||||
\ . "', '', 'tabline index " . i . "')"
|
||||
endfor
|
||||
call SpaceVim#mapping#def('nmap', '<leader>-', ':bprevious<cr>', 'Switch to previous airline tag', '', 'window previous')
|
||||
call SpaceVim#mapping#def('nmap', '<leader>+', ':bnext<cr>', 'Switch to next airline tag', '', 'window next')
|
||||
"call SpaceVim#mapping#space#def('nmap', ['-'], 'bprevious', 'window previous', 1)
|
||||
"call SpaceVim#mapping#space#def('nmap', ['+'], 'bnext', 'window next', 1)
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#core#tabline#jump(id, ...) abort
|
||||
if get(a:000, 2, '') ==# 'm'
|
||||
if len(s:shown_items) >= a:id
|
||||
let item = s:shown_items[a:id - 1]
|
||||
let mouse = get(a:000, 2, '')
|
||||
if tabpagenr('$') > 1
|
||||
exe 'tabnext' . a:id
|
||||
quit
|
||||
else
|
||||
if len(s:buffers) >= a:id
|
||||
let bid = s:buffers[a:id - 1]
|
||||
exe 'silent b' . bid
|
||||
bd
|
||||
if mouse ==# 'm'
|
||||
exe 'tabnext' . item.tabnr
|
||||
quit
|
||||
elseif mouse ==# 'l'
|
||||
exe 'tabnext' . item.tabnr
|
||||
else
|
||||
exe 'tabnext' . item.tabnr
|
||||
endif
|
||||
endif
|
||||
elseif get(a:000, 2, '') ==# 'l'
|
||||
if tabpagenr('$') > 1
|
||||
exe 'tabnext' . a:id
|
||||
else
|
||||
if len(s:buffers) >= a:id
|
||||
let bid = s:buffers[a:id - 1]
|
||||
exe 'silent b' . bid
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if tabpagenr('$') > 1
|
||||
exe 'tabnext' . a:id
|
||||
else
|
||||
if len(s:buffers) >= a:id
|
||||
let bid = s:buffers[a:id - 1]
|
||||
exe 'silent b' . bid
|
||||
if mouse ==# 'm'
|
||||
exe 'bd ' . item.bufnr
|
||||
elseif mouse ==# 'l'
|
||||
exe 'silent b ' . item.bufnr
|
||||
else
|
||||
exe 'silent b ' . item.bufnr
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
@ -47,7 +47,7 @@ function! SpaceVim#logger#viewRuntimeLog() abort
|
||||
setl nomodifiable
|
||||
setl buftype=nofile
|
||||
setl filetype=markdown
|
||||
|
||||
call s:syntax_extra()
|
||||
endfunction
|
||||
|
||||
|
||||
@ -92,6 +92,11 @@ function! SpaceVim#logger#viewLog(...) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:syntax_extra() abort
|
||||
call matchadd('ErrorMsg','.*[\sError\s\].*')
|
||||
call matchadd('WarningMsg','.*[\sWarn\s\].*')
|
||||
endfunction
|
||||
|
||||
""
|
||||
" @public
|
||||
" Set debug level of SpaceVim. Default is 1.
|
||||
@ -111,3 +116,33 @@ endfunction
|
||||
function! SpaceVim#logger#setOutput(file) abort
|
||||
call s:LOGGER.set_file(a:file)
|
||||
endfunction
|
||||
|
||||
|
||||
" derive a logger for built-in plugins
|
||||
" [ name ] [11:31:26] [ Info ] log message here
|
||||
|
||||
let s:derive = {}
|
||||
let s:derive.origin_name = s:LOGGER.get_name()
|
||||
|
||||
function! s:derive.info(msg) abort
|
||||
call s:LOGGER.set_name(self.derive_name)
|
||||
call s:LOGGER.info(a:msg)
|
||||
call s:LOGGER.set_name(self.origin_name)
|
||||
endfunction
|
||||
|
||||
function! s:derive.warn(msg) abort
|
||||
call s:LOGGER.set_name(self.derive_name)
|
||||
call s:LOGGER.warn(a:msg)
|
||||
call s:LOGGER.set_name(self.origin_name)
|
||||
endfunction
|
||||
|
||||
function! s:derive.error(msg) abort
|
||||
call s:LOGGER.set_name(self.derive_name)
|
||||
call s:LOGGER.error(a:msg)
|
||||
call s:LOGGER.set_name(self.origin_name)
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#logger#derive(name) abort
|
||||
let s:derive.derive_name = a:name
|
||||
return deepcopy(s:derive)
|
||||
endfunction
|
||||
|
@ -13,6 +13,8 @@ let s:JOB = SpaceVim#api#import('job')
|
||||
let s:SYS = SpaceVim#api#import('system')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
let s:LIST = SpaceVim#api#import('data#list')
|
||||
|
||||
let s:LOGGER =SpaceVim#logger#derive('flygrep ')
|
||||
let s:HI = SpaceVim#api#import('vim#highlight')
|
||||
if has('nvim')
|
||||
let s:FLOATING = SpaceVim#api#import('neovim#floating')
|
||||
@ -20,12 +22,13 @@ else
|
||||
let s:FLOATING = SpaceVim#api#import('vim#floating')
|
||||
endif
|
||||
let s:JSON = SpaceVim#api#import('data#json')
|
||||
|
||||
let s:SL = SpaceVim#api#import('vim#statusline')
|
||||
let s:Window = SpaceVim#api#import('vim#window')
|
||||
" }}}
|
||||
|
||||
let s:grepid = 0
|
||||
|
||||
|
||||
" Init local options: {{{
|
||||
let s:grep_expr = ''
|
||||
let [
|
||||
@ -76,7 +79,7 @@ function! s:grep_timer(timer) abort
|
||||
let s:current_grep_pattern = s:grep_expr
|
||||
endif
|
||||
let cmd = s:get_search_cmd(s:current_grep_pattern)
|
||||
call SpaceVim#logger#info('grep cmd: ' . string(cmd))
|
||||
call s:LOGGER.info('grep cmd: ' . string(cmd))
|
||||
let s:grepid = s:JOB.start(cmd, {
|
||||
\ 'on_stdout' : function('s:grep_stdout'),
|
||||
\ 'on_stderr' : function('s:grep_stderr'),
|
||||
@ -204,7 +207,7 @@ function! s:start_filter() abort
|
||||
try
|
||||
call writefile(getbufline('%', 1, '$'), s:filter_file, 'b')
|
||||
catch
|
||||
call SpaceVim#logger#info('FlyGrep: Failed to write filter content to temp file')
|
||||
call s:LOGGER.info('Failed to write filter content to temp file')
|
||||
endtry
|
||||
call s:MPT._build_prompt()
|
||||
endfunction
|
||||
@ -386,7 +389,7 @@ endfunction
|
||||
" endif
|
||||
|
||||
function! s:grep_stderr(id, data, event) abort
|
||||
call SpaceVim#logger#error(' flygerp stderr: ' . string(a:data))
|
||||
call s:LOGGER.error(' flygerp stderr: ' . string(a:data))
|
||||
endfunction
|
||||
|
||||
function! s:grep_exit(id, data, event) abort
|
||||
@ -766,7 +769,7 @@ let s:MPT._keys.close = ["\<Esc>", "\<C-c>"]
|
||||
" dir: specific a directory for grep
|
||||
function! SpaceVim#plugins#flygrep#open(argv) abort
|
||||
if empty(s:grep_default_exe)
|
||||
call SpaceVim#logger#warn(' [flygrep] make sure you have one search tool in your PATH', 1)
|
||||
call s:LOGGER.warn(' [flygrep] make sure you have one search tool in your PATH', 1)
|
||||
return
|
||||
endif
|
||||
let s:mode = ''
|
||||
@ -824,6 +827,7 @@ function! SpaceVim#plugins#flygrep#open(argv) abort
|
||||
elseif s:grep_exe ==# 'findstr' && !empty(s:grep_dir)
|
||||
let s:grep_dir = '/D:' . s:grep_dir
|
||||
endif
|
||||
|
||||
let s:grep_opt = get(a:argv, 'opt', s:grep_default_opt)
|
||||
let s:grep_ropt = get(a:argv, 'ropt', s:grep_default_ropt)
|
||||
let s:grep_ignore_case = get(a:argv, 'ignore_case', s:grep_default_ignore_case)
|
||||
|
0
lua/spacevim/layer/core.lua
Normal file
0
lua/spacevim/layer/core.lua
Normal file
Loading…
Reference in New Issue
Block a user