From 3c2dd3463a596f2606a88d4649b9ec4de83a2f15 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Thu, 14 Oct 2021 14:20:15 +1300 Subject: [PATCH] Better mail backup writing --- .vim/after/ftplugin/mail.vim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.vim/after/ftplugin/mail.vim b/.vim/after/ftplugin/mail.vim index 45b5492..2ab8174 100644 --- a/.vim/after/ftplugin/mail.vim +++ b/.vim/after/ftplugin/mail.vim @@ -196,7 +196,18 @@ fun! DelegateCompletion(next) endif endfun -autocmd BufWritePost exe 'write ' . fnameescape((exists('$TMPDIR') ? expand('$TMPDIR') : '/tmp') . '/mail.backup.' . strftime('%Y-%m-%d-%H%M%S')) +function! WriteMailBackup() + let l:tmpdir = fnameescape((exists('$TMPDIR') ? expand('$TMPDIR') : '/tmp')) + let l:tgtdir = l:tmpdir . '/mail-backups' + call mkdir(l:tgtdir, "p", 0o700) + let l:modified = &modified + let l:filename = l:tgtdir . '/' . strftime('%Y-%m-%d-%H%M%S') . '.msg' + exe 'silent update! ' . l:filename + if 0 && l:modified + echo 'Backup written to ' . l:filename + endif +endfunction +autocmd BufWritePre call WriteMailBackup() let g:markdown_in_mail = 1 runtime! ftplugin/markdown.vim -- 2.39.5