Skip to content

Commit

Permalink
feat: Allow user to limit new cards shown daily
Browse files Browse the repository at this point in the history
  • Loading branch information
cashpw committed Sep 19, 2022
1 parent 447f5ac commit 4be1c1d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
5 changes: 5 additions & 0 deletions org-fc-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ element."
:id (plist-get card :id)
:type (plist-get card :type)
:due (plist-get pos :due)
:box (plist-get pos :box)
:position (plist-get pos :position)))
(plist-get card :positions)))

Expand Down Expand Up @@ -643,6 +644,10 @@ Positions are shuffled in a way that preserves the order of the
#'cdr
(sort positions (lambda (a b) (> (car a) (car b)))))))

(defun org-fc-position-new-p (pos)
"Return t if the provided POS ition is new; nil otherwise."
(eq -1 (plist-get pos :box)))

;;; Demo Mode

;;;###autoload
Expand Down
69 changes: 62 additions & 7 deletions org-fc-review.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
;;; Code:

(require 'eieio)
(require 'dash)

(require 'org-fc-core)

Expand Down Expand Up @@ -79,6 +80,26 @@ Used to calculate the time needed for reviewing a card.")
"Track if the current buffer was open before the review.")
(make-variable-buffer-local 'org-fc-reviewing-existing-buffer)

(defcustom org-fc-review-new-limit -1
"Limits the number of new positions shown per `org-fc-review-new-limit-schedule'. Resets at midnight.
-1 for unlimited."
:type 'integer
:group 'org-fc)

(defcustom org-fc-review-new-limit-schedule 'session
"The schedule at which to limit the inclusion of new positions. "
:type '(choice (const session)
(const day))
:group 'org-fc)

(defvar org-fc-review-new-limit--new-seen-today -1
"Remaining new cards for today's reviews.
Don't access directly! Use `org-fc-review-new-limit--get-remaining'.")

(defvar org-fc-review-new-limit--reset-day nil
"The day number on which we should reset `org-fc-review-new-limit--new-seen-today'.")

;;; Main Review Functions

;;;###autoload
Expand All @@ -94,15 +115,28 @@ Valid contexts:
(when (yes-or-no-p "Flashcards are already being reviewed. Resume? ")
(org-fc-review-resume))
(let* ((index (org-fc-index context))
(cards (org-fc-index-filter-due index)))
(if org-fc-shuffle-positions
(setq cards (org-fc-index-shuffled-positions cards))
(setq cards (org-fc-index-positions cards)))
(if (null cards)
(message "No cards due right now")
(cards (org-fc-index-filter-due index))
(positions (if org-fc-shuffle-positions
(org-fc-index-shuffled-positions cards)
(org-fc-index-positions cards)))
(positions-limited-new (if (> org-fc-review-new-limit 0)
(let ((remaining-new (org-fc-review-new-limit--get-remaining)))
(cl-remove-if
(lambda (pos)
(cond
((org-fc-position-new-p pos)
(when (>= remaining-new 0)
(cl-decf remaining-new))
(< remaining-new 0))
(t
nil)))
positions))
positions)))
(if (null positions-limited-new)
(message "No positions due right now")
(progn
(setq org-fc-review--session
(org-fc-make-review-session cards))
(org-fc-make-review-session positions-limited-new))
(run-hooks 'org-fc-before-review-hook)
(org-fc-review-next-card))))))

Expand Down Expand Up @@ -573,6 +607,27 @@ removed."
(unless (and (derived-mode-p 'org-mode) org-fc-review--session)
(org-fc-review-edit-mode -1))))


;;;; Daily limit

(defun org-fc-review-new-limit--get-remaining ()
"Return the remaining new cards for the `org-fc-review-new-card-schedule'."
(when (and org-fc-review-new-limit
(> org-fc-review-new-limit 0))
(cond
((eq 'session
org-fc-review-new-limit-schedule)
org-fc-review-new-limit)
((eq 'day
org-fc-review-new-limit-schedule)
(let ((current-day (time-to-days (current-time))))
(when (or (not org-fc-review-new-limit--reset-day)
(= org-fc-review-new-limit--reset-day current-day))
(setq org-fc-review-new-limit--reset-day (1+ current-day)
org-fc-review-new-limit--new-seen-today 0))
(- org-fc-review-new-limit
org-fc-review-new-limit--new-seen-today))))))

;;; Footer

(provide 'org-fc-review)
Expand Down

0 comments on commit 4be1c1d

Please sign in to comment.