mirror of
https://github.com/vim-airline/vim-airline.git
synced 2026-01-29 14:22:10 +08:00
Merge branch 'dev'
This commit is contained in:
@@ -43,7 +43,6 @@ function! airline#switch_theme(name)
|
||||
let w:airline_lastmode = ''
|
||||
call airline#update_statusline()
|
||||
call airline#load_theme()
|
||||
call airline#check_mode()
|
||||
endfunction
|
||||
|
||||
function! airline#switch_matching_theme()
|
||||
@@ -82,6 +81,7 @@ function! airline#update_statusline()
|
||||
call s:invoke_funcrefs(context, g:airline_statusline_funcrefs)
|
||||
endfunction
|
||||
|
||||
let s:contexts = {}
|
||||
let s:core_funcrefs = [
|
||||
\ function('airline#extensions#apply'),
|
||||
\ function('airline#extensions#default#apply') ]
|
||||
@@ -89,11 +89,13 @@ function! s:invoke_funcrefs(context, funcrefs)
|
||||
let builder = airline#builder#new(a:context)
|
||||
let err = airline#util#exec_funcrefs(a:funcrefs + s:core_funcrefs, builder, a:context)
|
||||
if err == 1
|
||||
call setwinvar(a:context.winnr, '&statusline', builder.build())
|
||||
let a:context.line = builder.build()
|
||||
let s:contexts[a:context.winnr] = a:context
|
||||
call setwinvar(a:context.winnr, '&statusline', '%!airline#statusline('.a:context.winnr.')')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#check_mode()
|
||||
function! airline#statusline(winnr)
|
||||
if get(w:, 'airline_active', 1)
|
||||
let l:m = mode()
|
||||
if l:m ==# "i"
|
||||
@@ -123,6 +125,7 @@ function! airline#check_mode()
|
||||
call airline#highlighter#highlight(l:mode)
|
||||
let w:airline_lastmode = mode_string
|
||||
endif
|
||||
return ''
|
||||
|
||||
return s:contexts[a:winnr].line
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ function! airline#builder#new(context)
|
||||
let builder._context = a:context
|
||||
let builder._side = 1
|
||||
let builder._curgroup = ''
|
||||
let builder._line = '%{airline#check_mode()}'
|
||||
let builder._line = ''
|
||||
return builder
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
let s:ext = {}
|
||||
let s:ext._theme_funcrefs = []
|
||||
|
||||
function! s:ext.add_statusline_func(name) dict
|
||||
call airline#add_statusline_func(a:name)
|
||||
endfunction
|
||||
@@ -11,8 +13,11 @@ endfunction
|
||||
function! s:ext.add_inactive_statusline_func(name) dict
|
||||
call airline#add_inactive_statusline_func(a:name)
|
||||
endfunction
|
||||
function! s:ext.add_theme_func(name) dict
|
||||
call add(self._theme_funcrefs, function(a:name))
|
||||
endfunction
|
||||
|
||||
let s:script_path = resolve(expand('<sfile>:p:h'))
|
||||
let s:script_path = tolower(resolve(expand('<sfile>:p:h')))
|
||||
|
||||
let s:filetype_overrides = {
|
||||
\ 'netrw': [ 'netrw', '%f' ],
|
||||
@@ -109,9 +114,7 @@ function! s:is_excluded_window()
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#load_theme()
|
||||
if get(g:, 'loaded_ctrlp', 0)
|
||||
call airline#extensions#ctrlp#load_theme()
|
||||
endif
|
||||
call airline#util#exec_funcrefs(s:ext._theme_funcrefs, g:airline#themes#{g:airline_theme}#palette)
|
||||
endfunction
|
||||
|
||||
function! s:sync_active_winnr()
|
||||
@@ -178,20 +181,25 @@ function! airline#extensions#load()
|
||||
call airline#extensions#virtualenv#init(s:ext)
|
||||
endif
|
||||
|
||||
if (get(g:, 'airline#extensions#whitespace#enabled', 1) && get(g:, 'airline_detect_whitespace', 1))
|
||||
call airline#extensions#whitespace#init(s:ext)
|
||||
endif
|
||||
if (get(g:, 'airline#extensions#syntastic#enabled', 1) && get(g:, 'airline_enable_syntastic', 1))
|
||||
\ && exists(':SyntasticCheck')
|
||||
call airline#extensions#syntastic#init(s:ext)
|
||||
endif
|
||||
|
||||
if (get(g:, 'airline#extensions#whitespace#enabled', 1) && get(g:, 'airline_detect_whitespace', 1))
|
||||
call airline#extensions#whitespace#init(s:ext)
|
||||
endif
|
||||
|
||||
if get(g:, 'airline#extensions#tabline#enabled', 0)
|
||||
call airline#extensions#tabline#init(s:ext)
|
||||
endif
|
||||
|
||||
" load all other extensions not part of the default distribution
|
||||
for file in split(globpath(&rtp, "autoload/airline/extensions/*.vim"), "\n")
|
||||
" we have to check both resolved and unresolved paths, since it's possible
|
||||
" that they might not get resolved properly (see #187)
|
||||
if stridx(resolve(fnamemodify(file, ':p')), s:script_path) < 0
|
||||
\ && stridx(fnamemodify(file, ':p'), s:script_path) < 0
|
||||
if stridx(tolower(resolve(fnamemodify(file, ':p'))), s:script_path) < 0
|
||||
\ && stridx(tolower(fnamemodify(file, ':p')), s:script_path) < 0
|
||||
let name = fnamemodify(file, ':t:r')
|
||||
if !get(g:, 'airline#extensions#'.name.'#enabled', 1)
|
||||
continue
|
||||
|
||||
@@ -14,15 +14,15 @@ function! airline#extensions#ctrlp#generate_color_map(dark, light, white)
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#ctrlp#load_theme()
|
||||
if exists('g:airline#themes#{g:airline_theme}#palette.ctrlp')
|
||||
let theme = g:airline#themes#{g:airline_theme}#palette.ctrlp
|
||||
function! airline#extensions#ctrlp#load_theme(palette)
|
||||
if exists('a:palette.ctrlp')
|
||||
let theme = a:palette.ctrlp
|
||||
else
|
||||
let s:color_template = has_key(g:airline#themes#{g:airline_theme}#palette, s:color_template) ? s:color_template : 'insert'
|
||||
let s:color_template = has_key(a:palette, s:color_template) ? s:color_template : 'insert'
|
||||
let theme = airline#extensions#ctrlp#generate_color_map(
|
||||
\ g:airline#themes#{g:airline_theme}#palette[s:color_template]['airline_c'],
|
||||
\ g:airline#themes#{g:airline_theme}#palette[s:color_template]['airline_b'],
|
||||
\ g:airline#themes#{g:airline_theme}#palette[s:color_template]['airline_a'])
|
||||
\ a:palette[s:color_template]['airline_c'],
|
||||
\ a:palette[s:color_template]['airline_b'],
|
||||
\ a:palette[s:color_template]['airline_a'])
|
||||
endif
|
||||
for key in keys(theme)
|
||||
call airline#highlighter#exec(key, theme[key])
|
||||
@@ -60,5 +60,6 @@ function! airline#extensions#ctrlp#init(ext)
|
||||
\ 'prog': 'airline#extensions#ctrlp#ctrlp_airline_status',
|
||||
\ }
|
||||
call a:ext.add_statusline_func('airline#extensions#ctrlp#apply')
|
||||
call a:ext.add_theme_func('airline#extensions#ctrlp#load_theme')
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ function! airline#extensions#default#apply(builder, context)
|
||||
if airline#util#getwinvar(winnr, 'airline_render_left', active || (!active && !g:airline_inactive_collapse))
|
||||
call <sid>build_sections(a:builder, a:context, s:layout[0])
|
||||
else
|
||||
call a:builder.add_section('airline_a', '%f%m ')
|
||||
call a:builder.add_section('airline_b', ' %f%m ')
|
||||
call a:builder.add_section('airline_c', '')
|
||||
endif
|
||||
|
||||
|
||||
85
autoload/airline/extensions/tabline.vim
Normal file
85
autoload/airline/extensions/tabline.vim
Normal file
@@ -0,0 +1,85 @@
|
||||
" MIT License. Copyright (c) 2013 Bailey Ling.
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
|
||||
let s:excludes = get(g:, 'airline#extensions#tabline#excludes', [])
|
||||
|
||||
function! airline#extensions#tabline#init(ext)
|
||||
set showtabline=2
|
||||
set tabline=%!airline#extensions#tabline#get()
|
||||
|
||||
call a:ext.add_theme_func('airline#extensions#tabline#load_theme')
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#load_theme(palette)
|
||||
call airline#highlighter#exec('airline_tab', a:palette.normal.airline_b)
|
||||
call airline#highlighter#exec('airline_tabsel', a:palette.normal.airline_a)
|
||||
call airline#highlighter#exec('airline_tabtype', a:palette.visual.airline_a)
|
||||
call airline#highlighter#exec('airline_tabfill', a:palette.normal.airline_c)
|
||||
call airline#highlighter#exec('airline_tabmod', a:palette.insert.airline_a)
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#get()
|
||||
if tabpagenr('$') == 1
|
||||
return s:get_buffers()
|
||||
else
|
||||
return s:get_tabs()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#title(n)
|
||||
let buflist = tabpagebuflist(a:n)
|
||||
let winnr = tabpagewinnr(a:n)
|
||||
return airline#extensions#tabline#get_buffer_name(buflist[winnr - 1])
|
||||
endfunction
|
||||
|
||||
function! airline#extensions#tabline#get_buffer_name(nr)
|
||||
let name = bufname(a:nr)
|
||||
if empty(name)
|
||||
return '[No Name]'
|
||||
endif
|
||||
return fnamemodify(name, s:fmod)
|
||||
endfunction
|
||||
|
||||
function! s:get_buffers()
|
||||
let b = airline#builder#new({'active': 1})
|
||||
let cur = bufnr('%')
|
||||
for nr in range(1, bufnr('$'))
|
||||
if buflisted(nr) && bufexists(nr)
|
||||
for ex in s:excludes
|
||||
if match(bufname(nr), ex)
|
||||
continue
|
||||
endif
|
||||
endfor
|
||||
if cur == nr
|
||||
if g:airline_detect_modified && getbufvar(nr, '&modified')
|
||||
let group = 'airline_tabmod'
|
||||
else
|
||||
let group = 'airline_tabsel'
|
||||
endif
|
||||
else
|
||||
let group = 'airline_tab'
|
||||
endif
|
||||
call b.add_section(group, '%( %{airline#extensions#tabline#get_buffer_name('.nr.')} %)')
|
||||
endif
|
||||
endfor
|
||||
call b.add_section('airline_tabfill', '')
|
||||
call b.split()
|
||||
call b.add_section('airline_tabtype', ' buffers ')
|
||||
return b.build()
|
||||
endfunction
|
||||
|
||||
function! s:get_tabs()
|
||||
let b = airline#builder#new({'active': 1})
|
||||
for i in range(1, tabpagenr('$'))
|
||||
let group = i == tabpagenr() ? 'airline_tabsel' : 'airline_tab'
|
||||
call b.add_section(group, ' %{len(tabpagebuflist(tabpagenr()))}%( %'.i.'T %{airline#extensions#tabline#title('.i.')} %)')
|
||||
endfor
|
||||
call b.add_raw('%T')
|
||||
call b.add_section('airline_tabfill', '')
|
||||
call b.split()
|
||||
call b.add_section('airline_tab', ' %999XX ')
|
||||
call b.add_section('airline_tabtype', ' tabs ')
|
||||
return b.build()
|
||||
endfunction
|
||||
|
||||
@@ -13,6 +13,44 @@ function! s:gui2cui(rgb, fallback)
|
||||
return rgb[0]+rgb[1]+rgb[2]
|
||||
endfunction
|
||||
|
||||
function! s:get_syn(group, what)
|
||||
" need to pass in mode, known to break on 7.3.547
|
||||
let mode = has('gui_running') ? 'gui' : 'cterm'
|
||||
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, mode)
|
||||
if empty(color) || color == -1
|
||||
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, mode)
|
||||
endif
|
||||
if empty(color) || color == -1
|
||||
if has('gui_running')
|
||||
let color = a:what ==# 'fg' ? '#000000' : '#FFFFFF'
|
||||
else
|
||||
let color = a:what ==# 'fg' ? 0 : 1
|
||||
endif
|
||||
endif
|
||||
return color
|
||||
endfunction
|
||||
|
||||
function! s:get_array(fg, bg, opts)
|
||||
let fg = a:fg
|
||||
let bg = a:bg
|
||||
return has('gui_running')
|
||||
\ ? [ fg, bg, '', '', join(a:opts, ',') ]
|
||||
\ : [ '', '', fg, bg, join(a:opts, ',') ]
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#get_highlight(group, ...)
|
||||
let fg = s:get_syn(a:group, 'fg')
|
||||
let bg = s:get_syn(a:group, 'bg')
|
||||
let reverse = synIDattr(synIDtrans(hlID(a:group)), 'reverse', has('gui_running') ? 'gui' : 'term')
|
||||
return reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#get_highlight2(fg, bg, ...)
|
||||
let fg = s:get_syn(a:fg[0], a:fg[1])
|
||||
let bg = s:get_syn(a:bg[0], a:bg[1])
|
||||
return s:get_array(fg, bg, a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#exec(group, colors)
|
||||
let colors = a:colors
|
||||
if s:is_win32term
|
||||
@@ -50,6 +88,7 @@ endfunction
|
||||
|
||||
function! airline#highlighter#add_separator(from, to, inverse)
|
||||
let s:separators[a:from.a:to] = [a:from, a:to, a:inverse]
|
||||
call <sid>exec_separator({}, a:from, a:to, a:inverse, '')
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#highlight(modes)
|
||||
|
||||
@@ -15,42 +15,12 @@ function! airline#themes#generate_color_map(section1, section2, section3, file)
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
function! s:get_syn(group, what)
|
||||
" need to pass in mode, known to break on 7.3.547
|
||||
let mode = has('gui_running') ? 'gui' : 'cterm'
|
||||
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, mode)
|
||||
if empty(color) || color == -1
|
||||
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, mode)
|
||||
endif
|
||||
if empty(color) || color == -1
|
||||
if has('gui_running')
|
||||
let color = a:what ==# 'fg' ? '#000000' : '#FFFFFF'
|
||||
else
|
||||
let color = a:what ==# 'fg' ? 0 : 1
|
||||
endif
|
||||
endif
|
||||
return color
|
||||
endfunction
|
||||
|
||||
function! s:get_array(fg, bg, opts)
|
||||
let fg = a:fg
|
||||
let bg = a:bg
|
||||
return has('gui_running')
|
||||
\ ? [ fg, bg, '', '', join(a:opts, ',') ]
|
||||
\ : [ '', '', fg, bg, join(a:opts, ',') ]
|
||||
endfunction
|
||||
|
||||
function! airline#themes#get_highlight(group, ...)
|
||||
let fg = s:get_syn(a:group, 'fg')
|
||||
let bg = s:get_syn(a:group, 'bg')
|
||||
let reverse = synIDattr(synIDtrans(hlID(a:group)), 'reverse', has('gui_running') ? 'gui' : 'term')
|
||||
return reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
|
||||
return call('airline#highlighter#get_highlight', [a:group] + a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#themes#get_highlight2(fg, bg, ...)
|
||||
let fg = s:get_syn(a:fg[0], a:fg[1])
|
||||
let bg = s:get_syn(a:bg[0], a:bg[1])
|
||||
return s:get_array(fg, bg, a:000)
|
||||
return call('airline#highlighter#get_highlight2', [a:fg, a:bg] + a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#themes#patch(palette)
|
||||
|
||||
Reference in New Issue
Block a user