summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Rische <leon.rische@me.com>2020-07-01 14:15:02 +0200
committerLeon Rische <leon.rische@me.com>2020-07-01 14:15:02 +0200
commit547e7b20d02a9ab32b2684be54efc3b7fd511e2c (patch)
treec13b8415971b9c5fcc08c6c346039d83e384f1c5
parentbf9dd33cc90942e6822fe778c3d660e03f8d7bb3 (diff)
Write history file only once per review
-rw-r--r--org-fc.el35
1 files changed, 25 insertions, 10 deletions
diff --git a/org-fc.el b/org-fc.el
index 6cf48a8..fce30f2 100644
--- a/org-fc.el
+++ b/org-fc.el
@@ -1486,6 +1486,7 @@ EASE, BOX and INTERVAL are the current parameters of the card."
(defclass org-fc-review-session ()
((current-item :initform nil)
+ (history :initform nil)
(ratings :initform nil :initarg :ratings)
(cards :initform nil :initarg :cards)))
@@ -1499,6 +1500,29 @@ EASE, BOX and INTERVAL are the current parameters of the card."
'(:total 0 :again 0 :hard 0 :good 0 :easy 0))
:cards cards))
+(defun org-fc-review-history-add (elements)
+ "Add ELEMENTS to review history."
+ (push
+ elements
+ (slot-value org-fc-review--current-session 'history)))
+
+(defun org-fc-review-history-save ()
+ "Save all history entries in the current session."
+ (when org-fc-review--current-session
+ (append-to-file
+ (concat
+ (mapconcat
+ (lambda (elements) (mapconcat #'identity elements "\t"))
+ (reverse (slot-value org-fc-review--current-session 'history))
+ "\n")
+ "\n")
+ nil
+ org-fc-review-history-file)
+ (setf (slot-value org-fc-review--current-session 'history) nil)))
+
+;; Make sure the history is saved even if Emacs is killed
+(add-hook 'kill-emacs-hook #'org-fc-review-history-save)
+
(defun org-fc-session-cards-pending-p (session)
"Check if there are any cards in SESSION."
(not (null (oref session cards))))
@@ -1533,16 +1557,6 @@ EASE, BOX and INTERVAL are the current parameters of the card."
(defvar org-fc-review--current-session nil
"Current review session.")
-;;;; Writing Review History
-
-(defun org-fc-review-history-add (elements)
- "Add ELEMENTS to the history csv file."
- (append-to-file
- (concat
- (mapconcat #'identity elements "\t")
- "\n")
- nil
- org-fc-review-history-file))
;;;; Reading / Writing Review Data
@@ -1953,6 +1967,7 @@ rating the card."
(interactive)
(org-fc-review-reset)
(run-hooks 'org-fc-after-review-hook)
+ (org-fc-review-history-save)
(setq org-fc-review--current-session nil))
;;; Dashboard