From f3af0f8772ebeaa31685b7903be729c640740cb7 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Sat, 3 Jun 2017 13:53:31 +0100 Subject: [PATCH] Emacs: Backup Mutt files on save --- .emacs.d/init.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 448aa120..2f098076 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -113,11 +113,19 @@ To view where the bindings are set in your config files, lookup ;;; Mail with Mutt support. (add-hook 'mail-mode-hook 'mail-text) (add-to-list 'auto-mode-alist '("/tmp/mutt-.*" . mail-mode)) +(defun mutt-backup-buffer () + "Create a copy of the current buffer. +This is useful for recovery in case Mutt hangs before sending the +e-mail." + (when (not (boundp 'mutt-backup)) + (set (make-local-variable 'mutt-backup) (make-temp-file (concat (buffer-name) "-")))) + (copy-file buffer-file-name mutt-backup t)) (defun mutt-check-buffer () - (when (and (string-match "/tmp/mutt-.*" (buffer-file-name)) - (require 'with-editor nil t)) - ;; Just like git commits. - (with-editor-mode))) + (when (string-match "/tmp/mutt-.*" (buffer-file-name)) + (when (require 'with-editor nil t) + ;; Just like git commits. + (with-editor-mode)) + (add-hook 'after-save-hook 'mutt-backup-buffer nil t))) (add-hook 'find-file-hook 'mutt-check-buffer) ;;; Makefile