From cead8efb48fbd770757f74246fefd1a3c7bec8ef Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Thu, 13 Jul 2023 16:47:35 +0200 Subject: [PATCH] term: allow to customize section_a and section_z closes: #2647 --- autoload/airline/extensions/term.vim | 33 ++++++++++++++++++++-------- doc/airline.txt | 8 +++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/autoload/airline/extensions/term.vim b/autoload/airline/extensions/term.vim index 3bc25bb8..be5e92ce 100644 --- a/autoload/airline/extensions/term.vim +++ b/autoload/airline/extensions/term.vim @@ -6,31 +6,46 @@ scriptencoding utf-8 call airline#parts#define_function('tmode', 'airline#extensions#term#termmode') call airline#parts#define('terminal', {'text': get(g:airline_mode_map, 't', 't'), 'accent': 'bold'}) -let s:spc = g:airline_symbols.space -let s:section_a = airline#section#create_left(['terminal', 'tmode']) -let s:section_z = airline#section#create(['linenr', 'maxlinenr']) +function! s:GetAirlineSection() + if exists("g:airline_section_z_term") + let section_z = g:airline_section_z_term + else + let section_z = airline#section#create(['linenr', 'maxlinenr']) + endif + + if exists("g:airline_section_a_term") + let section_a = g:airline_section_a_term + else + let section_a = airline#section#create_left(['terminal', 'tmode']) + endif + return [section_a, section_z] +endfunction function! airline#extensions#term#apply(...) abort if &buftype ==? 'terminal' || bufname(a:2.bufnr)[0] ==? '!' - call a:1.add_section_spaced('airline_a', s:section_a) + let sections = s:GetAirlineSection() + let spc = g:airline_symbols.space + call a:1.add_section_spaced('airline_a', sections[0]) call a:1.add_section_spaced('airline_b', s:neoterm_id(a:2.bufnr)) - call a:1.add_section('airline_term', s:spc.s:termname(a:2.bufnr)) + call a:1.add_section('airline_term', spc.s:termname(a:2.bufnr)) call a:1.split() call a:1.add_section('airline_y', '') - call a:1.add_section_spaced('airline_z', s:section_z) + call a:1.add_section_spaced('airline_z', sections[1]) return 1 endif endfunction function! airline#extensions#term#inactive_apply(...) abort if getbufvar(a:2.bufnr, '&buftype') ==? 'terminal' - call a:1.add_section_spaced('airline_a', s:section_a) + let sections = s:GetAirlineSection() + let spc = g:airline_symbols.space + call a:1.add_section_spaced('airline_a', sections[0]) call a:1.add_section_spaced('airline_b', s:neoterm_id(a:2.bufnr)) - call a:1.add_section('airline_term', s:spc.s:termname(a:2.bufnr)) + call a:1.add_section('airline_term', spc.s:termname(a:2.bufnr)) call a:1.split() call a:1.add_section('airline_y', '') - call a:1.add_section_spaced('airline_z', s:section_z) + call a:1.add_section_spaced('airline_z', sections[1]) return 1 endif endfunction diff --git a/doc/airline.txt b/doc/airline.txt index 8cb21ecb..59ea9c67 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -1446,6 +1446,14 @@ Vim-Airline comes with a small extension for the styling the builtin let g:airline#extensions#term#enabled = 1 default: 1 +* Use custom section_z > + let g:airline_section_z_term = '%p%% ☰ %l/%L, %v' + default: airline#section#create(['linenr', 'maxlinenr']) + +* Use custom section_a > + let g:airline_section_a_term = '%p%% ☰ %l/%L, %v' + default: airline#section#create_left(['terminal', 'tmode']) + ------------------------------------- *airline-tabws* vim-tabws