Refactor BufWrite/BufLeave autocmds

This commit is contained in:
Kevin Cotugno 2018-12-13 07:22:59 -08:00
parent df68c1d595
commit fced85576c

View File

@ -85,19 +85,36 @@ function TrimTrailingLines()
call winrestview(view) call winrestview(view)
endfunction endfunction
augroup maximus function OnWrite()
if Writeable()
call CleanFile()
endif
endfunction
autocmd BufWrite * call TrimTrailingInvisibles() | call TrimTrailingLines() function OnLeave()
autocmd BufLeave * if &buftype == '' if Writeable()
call CleanFile()
write
GitGutter
endif
endfunction
function CleanFile()
call TrimTrailingInvisibles() | call TrimTrailingLines()
endfunction
function Writeable()
return &buftype == ''
\ && !&readonly \ && !&readonly
\ && &modifiable \ && &modifiable
\ && &modified \ && &modified
\ && expand("%:t") != "" \ && expand("%:t") != ""
\ | call TrimTrailingInvisibles() endfunction
\ | call TrimTrailingLines()
\ | w augroup maximus
\ | GitGutter
\ | endif autocmd BufWrite * call OnWrite()
autocmd BufLeave * call OnLeave()
augroup END augroup END