From 547e7b20d02a9ab32b2684be54efc3b7fd511e2c Mon Sep 17 00:00:00 2001 From: Leon Rische Date: Wed, 1 Jul 2020 14:15:02 +0200 Subject: Write history file only once per review --- org-fc.el | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'org-fc.el') 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 -- cgit v1.2.3