Refactor BufWrite/BufLeave autocmds
This commit is contained in:
parent
df68c1d595
commit
fced85576c
@ -85,19 +85,36 @@ function TrimTrailingLines()
|
|||||||
call winrestview(view)
|
call winrestview(view)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function OnWrite()
|
||||||
|
if Writeable()
|
||||||
|
call CleanFile()
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function OnLeave()
|
||||||
|
if Writeable()
|
||||||
|
call CleanFile()
|
||||||
|
write
|
||||||
|
GitGutter
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function CleanFile()
|
||||||
|
call TrimTrailingInvisibles() | call TrimTrailingLines()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function Writeable()
|
||||||
|
return &buftype == ''
|
||||||
|
\ && !&readonly
|
||||||
|
\ && &modifiable
|
||||||
|
\ && &modified
|
||||||
|
\ && expand("%:t") != ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
augroup maximus
|
augroup maximus
|
||||||
|
|
||||||
autocmd BufWrite * call TrimTrailingInvisibles() | call TrimTrailingLines()
|
autocmd BufWrite * call OnWrite()
|
||||||
autocmd BufLeave * if &buftype == ''
|
autocmd BufLeave * call OnLeave()
|
||||||
\ && !&readonly
|
|
||||||
\ && &modifiable
|
|
||||||
\ && &modified
|
|
||||||
\ && expand("%:t") != ""
|
|
||||||
\ | call TrimTrailingInvisibles()
|
|
||||||
\ | call TrimTrailingLines()
|
|
||||||
\ | w
|
|
||||||
\ | GitGutter
|
|
||||||
\ | endif
|
|
||||||
|
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user