From 6e177aa3d3259440498fab04cb1790e458dffdbe Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 7 Apr 2020 21:30:12 -0700 Subject: [PATCH] =?UTF-8?q?Ensure=20idle=20timer=20for=20=E2=80=98recentf-?= =?UTF-8?q?save-list=E2=80=99=20only=20gets=20created=20once?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oni-core.el | 9 +++++++-- test/oni-core-test.el | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/oni-core.el b/oni-core.el index dbea8c3..212d126 100644 --- a/oni-core.el +++ b/oni-core.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2020.0407.015402 +;; Version: 2020.0407.212814 ;; Package-Requires: (oni-data-dir expand-region multiple-cursors embrace helpful) ;; This program is free software; you can redistribute it and/or modify @@ -35,6 +35,9 @@ (defalias 'yes-or-no-p 'y-or-n-p) +(defvar oni-core--recentf-idle-timer nil + "Internal variable keeping track of a timer started for ‘recentf-save-list’.") + (defun oni-core--destroy-trailing-whitespace () "Delete trailing whitespace everywhere, except in Markdown buffers." (if (not (eq major-mode 'markdown-mode)) @@ -144,7 +147,9 @@ (global-set-key (kbd "C-") 'winner-undo) (global-set-key (kbd "C-") 'winner-redo) -(run-with-idle-timer 10 t 'recentf-save-list) +(unless oni-core--recentf-idle-timer + (setq oni-core--recentf-idle-timer + (run-with-idle-timer 10 t 'recentf-save-list))) (electric-indent-mode -1) (winner-mode) diff --git a/test/oni-core-test.el b/test/oni-core-test.el index 0672fb3..eb9886e 100644 --- a/test/oni-core-test.el +++ b/test/oni-core-test.el @@ -59,3 +59,12 @@ (oni-core-move-end-of-dwim) (oni-core-move-end-of-dwim) (should (equal 21 (point))))) + +(ert-deftest oni-core-loading-is-idempotent-recentf-idle-timer () + "Test that loading ‘oni-core’ is idempotent in regards to an idle timer." + ;; We already loaded it with the ‘require’ call above. We load it again so we + ;; can check that the timer set up in it doesn’t appear twice. + (load-library "oni-core") + (let* ((pred (lambda (elt) (eq 'recentf-save-list (aref elt 5)))) + (matches (delete nil (mapcar pred timer-idle-list)))) + (should (eq 1 (length matches)))))