From 1fb184305bbd0da45fb87f8a690ac29599ce1a15 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 25 Mar 2019 12:34:09 +0100 Subject: [PATCH] fugitiveline: simplify modify logic The 'autochdir' option could be toggled on later in a session. So do not set the has_autochdir flag once the file is read, but evaluate it every time the corresponding function is called. While at it, get rid of the s:fmod variable. Instead let a helper function return the correct modifier flags depending on the value of the 'autochdir' option. --- autoload/airline/extensions/fugitiveline.vim | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/autoload/airline/extensions/fugitiveline.vim b/autoload/airline/extensions/fugitiveline.vim index 7f39b5c..1dfbb24 100644 --- a/autoload/airline/extensions/fugitiveline.vim +++ b/autoload/airline/extensions/fugitiveline.vim @@ -7,13 +7,9 @@ if !airline#util#has_fugitive() finish endif - -let s:has_autochdir = exists("+autochdir") && &autochdir -if s:has_autochdir - let s:fmod = ':p' -else - let s:fmod = ':.' -endif +function! s:ModifierFlags() + return (exists("+autochdir") && &autochdir) ? ':p' : ':.' +endfunction function! airline#extensions#fugitiveline#bufname() if !exists('b:fugitive_name') @@ -31,15 +27,16 @@ function! airline#extensions#fugitiveline#bufname() endtry endif + let fmod = s:ModifierFlags() if empty(b:fugitive_name) - return fnamemodify(bufname('%'), s:fmod) + return fnamemodify(bufname('%'), fmod) else - return fnamemodify(b:fugitive_name, s:fmod). " [git]" + return fnamemodify(b:fugitive_name, fmod). " [git]" endif endfunction function! airline#extensions#fugitiveline#init(ext) - if s:has_autochdir + if exists("+autochdir") && &autochdir " if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well call airline#parts#define_raw('path', '%<%{airline#extensions#fugitiveline#bufname()}%m') else