From 5b78ae2ec9fc4a21d442c18a9fa794f9e921e00f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Jan 2021 22:50:02 -0600 Subject: Add a timer to recentf-mode Autosave the recentf-list, but only when no Emacs frame is focused. --- config.org | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/config.org b/config.org index 0fa3911..eed895a 100644 --- a/config.org +++ b/config.org @@ -799,12 +799,19 @@ from [[https://www.reddit.com/r/emacs/comments/km9by4/weekly_tipstricketc_thread (recentf-mode +1) ;; save recentf list when focusing away - (defun acdw/save-recentf-when-nonfocused () - "Save `recentf-file' when out of focus." - (acdw/when-unfocused #'recentf-save-list)) + (defun acdw/maybe-save-recentf () + "Save `recentf-file' when out of focus, but only if we haven't + in five minutes." + (defvar recentf-last-save (time-convert nil 'integer) + "How long it's been since we last saved the recentf list.") + + (when (> (time-convert (time-since recentf-last-save) 'integer) + (* 60 5)) + (setq recentf-last-save (time-convert nil 'integer)) + (acdw/when-unfocused #'recentf-save-list))) (add-function :after after-focus-change-function - #'acdw/save-recentf-when-nonfocused) + #'acdw/maybe-save-recentf) #+END_SRC ** Undo -- cgit 1.4.1-21-gabe81