toggle inactive mode the same way as the other modes

This commit is contained in:
Bailey Ling 2013-07-16 02:06:50 +00:00
parent 294f07d975
commit 5fefc84413

View File

@ -1,6 +1,5 @@
" vim: ts=2 sts=2 sw=2 fdm=indent " vim: ts=2 sts=2 sw=2 fdm=indent
let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running') let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running')
let s:lastmode = ''
let s:airline_highlight_map = { let s:airline_highlight_map = {
\ 'mode' : 'Al2', \ 'mode' : 'Al2',
@ -31,20 +30,21 @@ endfunction
function! airline#load_theme(name) function! airline#load_theme(name)
let g:airline_theme = a:name let g:airline_theme = a:name
let inactive_colors = g:airline#themes#{g:airline_theme}#inactive "also lazy loads the theme let inactive_colors = g:airline#themes#{g:airline_theme}#inactive "also lazy loads the theme
call airline#highlight(['inactive'], '_inactive') let w:airline_lastmode = ''
let s:lastmode = '' let w:airline_active = 1
call airline#highlight(['inactive'])
call airline#update_highlight() call airline#update_highlight()
endfunction endfunction
function! airline#highlight(modes, ...) function! airline#highlight(modes)
" draw the base mode, followed by any overrides " draw the base mode, followed by any overrides
let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val') let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val')
for mode in mapped for mode in mapped
for key in s:airline_highlight_groups for key in s:airline_highlight_groups
if exists('g:airline#themes#{g:airline_theme}#{mode}[key]') if exists('g:airline#themes#{g:airline_theme}#{mode}[key]')
let colors = g:airline#themes#{g:airline_theme}#{mode}[key] let colors = g:airline#themes#{g:airline_theme}#{mode}[key]
let group_suffix = a:0 ? a:1 : '' let suffix = a:modes[0] == 'inactive' ? '_inactive' : ''
call airline#exec_highlight(s:airline_highlight_map[key].group_suffix, colors) call airline#exec_highlight(s:airline_highlight_map[key].suffix, colors)
endif endif
endfor endfor
endfor endfor
@ -100,6 +100,7 @@ function! s:get_section(key)
endfunction endfunction
function! airline#update_statusline(active) function! airline#update_statusline(active)
let w:airline_active = a:active
if s:is_excluded_window() if s:is_excluded_window()
call setwinvar(winnr(), '&statusline', '') call setwinvar(winnr(), '&statusline', '')
return return
@ -115,9 +116,9 @@ function! airline#update_statusline(active)
let l:status_color = a:active ? "%#Al6#" : "%#Al6_inactive#" let l:status_color = a:active ? "%#Al6#" : "%#Al6_inactive#"
let l:file_flag_color = a:active ? "%#Al7#" : "%#Al7_inactive#" let l:file_flag_color = a:active ? "%#Al7#" : "%#Al7_inactive#"
let sl = l:mode_color let sl = '%{airline#update_highlight()}'
if a:active if a:active
let sl.='%{airline#update_highlight()} '.s:get_section('a').' ' let sl.=l:mode_color.' '.s:get_section('a').' '
let sl.=l:mode_sep_color let sl.=l:mode_sep_color
let sl.=a:active ? g:airline_left_sep : g:airline_left_alt_sep let sl.=a:active ? g:airline_left_sep : g:airline_left_alt_sep
let sl.=l:info_color let sl.=l:info_color
@ -147,26 +148,29 @@ endfunction
let g:airline_current_mode_text = '' let g:airline_current_mode_text = ''
function! airline#update_highlight() function! airline#update_highlight()
let l:m = mode() if w:airline_active
if l:m ==# "i" let l:m = mode()
let l:mode = ['insert'] if l:m ==# "i"
elseif l:m ==# "R" let l:mode = ['insert']
let l:mode = ['replace'] elseif l:m ==# "R"
elseif l:m ==? "v" || l:m ==# "" let l:mode = ['replace']
let l:mode = ['visual'] elseif l:m ==? "v" || l:m ==# ""
let l:mode = ['visual']
else
let l:mode = ['normal']
endif
let g:airline_current_mode_text = get(g:airline_mode_map, l:m, l:m)
else else
let l:mode = ['normal'] let l:mode = ['inactive']
endif endif
if &modified | call add(l:mode, 'modified') | endif if &modified | call add(l:mode, 'modified') | endif
if &paste | call add(l:mode, 'paste') | endif if &paste | call add(l:mode, 'paste') | endif
let mode_string = join(l:mode) let mode_string = join(l:mode)
if s:lastmode != mode_string if !exists('w:airline_lastmode') || w:airline_lastmode != mode_string
call airline#highlight(l:mode) call airline#highlight(l:mode)
let s:lastmode = mode_string let w:airline_lastmode = mode_string
endif endif
let g:airline_current_mode_text = get(g:airline_mode_map, l:m, l:m)
return '' return ''
endfunction endfunction