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.
This commit is contained in:
parent
c8a36e14e9
commit
1fb184305b
@ -7,13 +7,9 @@ if !airline#util#has_fugitive()
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
function! s:ModifierFlags()
|
||||||
let s:has_autochdir = exists("+autochdir") && &autochdir
|
return (exists("+autochdir") && &autochdir) ? ':p' : ':.'
|
||||||
if s:has_autochdir
|
endfunction
|
||||||
let s:fmod = ':p'
|
|
||||||
else
|
|
||||||
let s:fmod = ':.'
|
|
||||||
endif
|
|
||||||
|
|
||||||
function! airline#extensions#fugitiveline#bufname()
|
function! airline#extensions#fugitiveline#bufname()
|
||||||
if !exists('b:fugitive_name')
|
if !exists('b:fugitive_name')
|
||||||
@ -31,15 +27,16 @@ function! airline#extensions#fugitiveline#bufname()
|
|||||||
endtry
|
endtry
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let fmod = s:ModifierFlags()
|
||||||
if empty(b:fugitive_name)
|
if empty(b:fugitive_name)
|
||||||
return fnamemodify(bufname('%'), s:fmod)
|
return fnamemodify(bufname('%'), fmod)
|
||||||
else
|
else
|
||||||
return fnamemodify(b:fugitive_name, s:fmod). " [git]"
|
return fnamemodify(b:fugitive_name, fmod). " [git]"
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#fugitiveline#init(ext)
|
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
|
" 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')
|
call airline#parts#define_raw('path', '%<%{airline#extensions#fugitiveline#bufname()}%m')
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user