From 7469672a46da4b569cb30caacc232394a65db0f5 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Tue, 30 Apr 2019 17:06:08 +0200 Subject: [PATCH] extensions: Allow customization of filetypes Define the variable :let g:airline_filetype_overrides to allow for specific customization how a specific filetype will be displayed. For e.g. a German display, you can use: > :let g:airline_filetype_overrides = {'help': ['Hilfe', ':%f']} < This defines how section a and b will look like for a window with that specific filetype. Closes #1888 --- autoload/airline/extensions.vim | 30 ++++++++++++++++-------------- doc/airline.txt | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index f6eedfad..c68a228c 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -23,12 +23,15 @@ endfunction let s:script_path = tolower(resolve(expand(':p:h'))) let s:filetype_overrides = { + \ 'defx': ['defx', '%{b:defx.paths[0]}'], \ 'gundo': [ 'Gundo', '' ], + \ 'help': [ 'Help', '%f' ], \ 'minibufexpl': [ 'MiniBufExplorer', '' ], \ 'nerdtree': [ get(g:, 'NERDTreeStatusline', 'NERD'), '' ], \ 'startify': [ 'startify', '' ], \ 'vim-plug': [ 'Plugins', '' ], \ 'vimfiler': [ 'vimfiler', '%{vimfiler#get_status_string()}' ], + \ 'vimshell': ['vimshell','%{vimshell#get_status_string()}'], \ } let s:filetype_regex_overrides = {} @@ -58,18 +61,13 @@ function! airline#extensions#apply_left_override(section1, section2) endfunction function! airline#extensions#apply(...) + let filetype_overrides = get(s:, 'filetype_overrides', {}) + call extend(filetype_overrides, get(g:, 'airline_filetype_overrides', {}), 'force') if s:is_excluded_window() return -1 endif - if &buftype == 'help' - call airline#extensions#apply_left_override('Help', '%f') - let w:airline_section_x = '' - let w:airline_section_y = '' - let w:airline_render_right = 1 - endif - if &buftype == 'terminal' let w:airline_section_x = '' let w:airline_section_y = '' @@ -81,11 +79,20 @@ function! airline#extensions#apply(...) let w:airline_section_c = bufname(winbufnr(winnr())) endif - if has_key(s:filetype_overrides, &ft) - let args = s:filetype_overrides[&ft] + if has_key(filetype_overrides, &ft) && + \ ((&filetype == 'help' && &buftype == 'help') || &filetype !~ 'help') + " for help files only override it, if the buftype is also of type 'help', + " else it would trigger when editing Vim help files + let args = filetype_overrides[&ft] call airline#extensions#apply_left_override(args[0], args[1]) endif + if &buftype == 'help' + let w:airline_section_x = '' + let w:airline_section_y = '' + let w:airline_render_right = 1 + endif + for item in items(s:filetype_regex_overrides) if match(&ft, item[0]) >= 0 call airline#extensions#apply_left_override(item[1][0], item[1][1]) @@ -213,14 +220,9 @@ function! airline#extensions#load() endif if exists(':VimShell') - let s:filetype_overrides['vimshell'] = ['vimshell','%{vimshell#get_status_string()}'] let s:filetype_regex_overrides['^int-'] = ['vimshell','%{substitute(&ft, "int-", "", "")}'] endif - if exists(':Defx') - let s:filetype_overrides['defx'] = ['defx', '%{b:defx.paths[0]}'] - endif - if get(g:, 'airline#extensions#branch#enabled', 1) && ( \ airline#util#has_fugitive() || \ airline#util#has_lawrencium() || diff --git a/doc/airline.txt b/doc/airline.txt index d92b621d..590e7e3a 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -203,12 +203,27 @@ values): statusline modified > let g:airline_exclude_filetypes = [] " see source for current list < +* define the set of names to be displayed instead of a specific filetypes (for + section a and b): > + + let g:airline_filetype_overrides = { + \ 'defx': ['defx', '%{b:defx.paths[0]}'], + \ 'gundo': [ 'Gundo', '' ], + \ 'help': [ 'Help', '%f' ], + \ 'minibufexpl': [ 'MiniBufExplorer', '' ], + \ 'nerdtree': [ get(g:, 'NERDTreeStatusline', 'NERD'), '' ], + \ 'startify': [ 'startify', '' ], + \ 'vim-plug': [ 'Plugins', '' ], + \ 'vimfiler': [ 'vimfiler', '%{vimfiler#get_status_string()}' ], + \ 'vimshell': ['vimshell','%{vimshell#get_status_string()}'], + \ } +< * defines whether the preview window should be excluded from have its window statusline modified (may help with plugins which use the preview window heavily) > let g:airline_exclude_preview = 0 < -* disable the Airline customization for selective windows (this is a +* disable the Airline customization for selected windows (this is a window-local variable so you can disable it per-window) > let w:airline_disabled = 1