aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--oni-core.el9
-rw-r--r--test/oni-core-test.el9
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 <tom@ryuslash.org>
;; 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-<left>") 'winner-undo)
(global-set-key (kbd "C-<right>") '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)))))