From 0099ea4927b9b5e7599d33cbc835ede09184b66b Mon Sep 17 00:00:00 2001 From: srdusr Date: Thu, 31 Aug 2023 17:53:09 +0200 Subject: Still trying to fix annoying timestamp issue --- autoload/utils.vim | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'autoload') diff --git a/autoload/utils.vim b/autoload/utils.vim index 3bb83bf..f11a769 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -165,6 +165,24 @@ autocmd! BufNewFile,BufRead *.* call utils#DisableBr() "------------------------------------------------- +" Annoying timestamp issue on write (The file has been changed since reading it...) +"function! utils#ProcessFileChangedShell() +" if v:fcs_reason == 'mode' || v:fcs_reason == 'time' +" let v:fcs_choice = '' +" else +" let v:fcs_choice = 'ask' +" endif +"endfunction +"autocmd FileChangedShell call utils#ProcessFileChangedShell() +" +"let lastline = line('$') +"let bufcontents = getline(1, lastline) +"edit! +"call setline(1, bufcontents) +"if line('$') > lastline +" execute lastline+1.',$:d _' +"endif + " Annoying timestamp issue on write (The file has been changed since reading it...) function! utils#ProcessFileChangedShell() if v:fcs_reason == 'mode' || v:fcs_reason == 'time' @@ -173,7 +191,21 @@ function! utils#ProcessFileChangedShell() let v:fcs_choice = 'ask' endif endfunction + +" Triggered when the file is changed externally autocmd FileChangedShell call utils#ProcessFileChangedShell() +" Triggered before writing the buffer to the file +autocmd BufWritePre call utils#BeforeWrite() + +function! utils#BeforeWrite() + let lastline = line('$') + let bufcontents = getline(1, lastline) + edit! + call setline(1, bufcontents) + if line('$') > lastline + execute lastline+1.',$:d _' + endif +endfunction "------------------------------------------------- -- cgit v1.2.3