From 423aed15fcf6a7f88985c2f88d031f432f1749c5 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 12 Mar 2021 16:49:49 -0500 Subject: [PATCH] Delete backing temp file upon wiping buffer We should probably default buftype to wipe so that these don't stack up indefinitely by default, but one step at a time. --- autoload/fugitive.vim | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 21f65a3..0466782 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2241,7 +2241,9 @@ function! s:TempReadPre(file) abort if has_key(s:temp_files, s:cpath(a:file)) let dict = s:temp_files[s:cpath(a:file)] setlocal nomodeline - setlocal bufhidden=delete + if empty(&bufhidden) + setlocal bufhidden=delete + endif setlocal buftype=nowrite setlocal nomodifiable if len(dict.dir) @@ -2269,10 +2271,20 @@ function! s:TempReadPost(file) abort return '' endfunction +function! s:TempDelete(file) abort + let key = s:cpath(a:file) + if has_key(s:temp_files, key) + call delete(a:file) + call remove(s:temp_files, key) + endif + return '' +endfunction + augroup fugitive_temp autocmd! autocmd BufReadPre * exe s:TempReadPre( expand(':p')) autocmd BufReadPost * exe s:TempReadPost(expand(':p')) + autocmd BufWipeout * exe s:TempDelete( expand(':p')) augroup END " Section: :Git