From 25059d43b122e1546ab120e27e363126fc39a1ca Mon Sep 17 00:00:00 2001 From: Russell Hancox Date: Mon, 24 Mar 2014 14:01:31 -0400 Subject: [PATCH] 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 c0f63db..0abce4d 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 -