From 25059d43b122e1546ab120e27e363126fc39a1ca Mon Sep 17 00:00:00 2001 From: Russell Hancox Date: Mon, 24 Mar 2014 14:01:31 -0400 Subject: [PATCH 1/2] Save branch head to a buffer variable Save branch head to a buffer-local variable to prevent looking up the VCS head for every status line refresh. --- autoload/airline/extensions/branch.vim | 29 +++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index c0f63db9..0abce4d4 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -11,35 +11,41 @@ if !s:has_fugitive && !s:has_lawrencium && !s:has_vcscommand endif function! airline#extensions#branch#head() - let head = '' + if exists('b:airline_head') + return b:airline_head + endif + + let b:airline_head = '' if s:has_fugitive && !exists('b:mercurial_dir') - let head = fugitive#head() + let b:airline_head = fugitive#head() - if empty(head) && s:has_fugitive_detect && !exists('b:git_dir') + if empty(b:airline_head) && s:has_fugitive_detect && !exists('b:git_dir') call fugitive#detect(getcwd()) - let head = fugitive#head() + let b:airline_head = fugitive#head() endif endif - if empty(head) + if empty(b:airline_head) if s:has_lawrencium - let head = lawrencium#statusline() + let b:airline_head = lawrencium#statusline() endif endif - if empty(head) + if empty(b:airline_head) if s:has_vcscommand call VCSCommandEnableBufferSetup() if exists('b:VCSCommandBufferInfo') - let head = get(b:VCSCommandBufferInfo, 0, '') + let b:airline_head = get(b:VCSCommandBufferInfo, 0, '') endif endif endif - return empty(head) || !s:check_in_path() - \ ? '' - \ : head + if empty(b:airline_head) || !s:check_in_path() + let b:airline_head = '' + endif + + return b:airline_head endfunction function! airline#extensions#branch#get_head() @@ -79,4 +85,3 @@ function! airline#extensions#branch#init(ext) autocmd BufReadPost * unlet! b:airline_file_in_root endfunction - From 13297cee03a3003b66a4ec07b734066cb32b7e04 Mon Sep 17 00:00:00 2001 From: Russell Hancox Date: Fri, 28 Mar 2014 10:53:13 -0400 Subject: [PATCH 2/2] Add CursorHold autocmd to unset airline_head --- autoload/airline/extensions/branch.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 0abce4d4..9ac1b56e 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -84,4 +84,5 @@ function! airline#extensions#branch#init(ext) call airline#parts#define_function('branch', 'airline#extensions#branch#get_head') autocmd BufReadPost * unlet! b:airline_file_in_root + autocmd CursorHold * unlet! b:airline_head endfunction