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 authored and Cash Weaver committed Oct 13, 2022
1 parent 028af3d commit a58bbb3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
5 changes: 5 additions & 0 deletions org-fc-position.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
"Return t if POS is due; else nil."
(time-less-p (oref pos due) (current-time)))

(cl-defmethod org-fc-position-new-p ((pos org-fc-position))
"Return t if the provided POS ition is new; nil otherwise."
(eq -1 (oref pos box)))

(defun org-fc-positions--filter-due (positions)
"Filter POSITIONS to include only enabled and due positions."
(let ((due-enabled-positions (cl-loop for pos in positions
Expand All @@ -76,5 +80,6 @@
(oref (oref b card) id)))))
(-distinct positions)))


(provide 'org-fc-position)
;;; org-fc-position.el ends here
69 changes: 67 additions & 2 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-awk)
(require 'org-fc-core)
Expand Down Expand Up @@ -88,6 +89,34 @@ 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'.
-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.
- `session': Each review session will include, at most, `org-fc-review-new-limit' new cards.
- `day': New cards will be limited to `org-fc-review-new-limit' across review sessions; resets at midnight."
: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'.
Not persisted; resets when reloading Emacs!")

(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'.
Not persisted; resets when reloading Emacs!")

;;; Main Review Functions

;;;###autoload
Expand All @@ -108,9 +137,22 @@ Valid contexts:
(org-fc-cards--to-positions cards)))
(positions (if org-fc-shuffle-positions
(org-fc-shuffle positions)
positions))
(positions (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 cards)
(message "No cards due right now")
(if (null positions)
(message "No positions due right now")
(progn
(setq org-fc-review--session
(org-fc-review-session--create positions))
Expand Down Expand Up @@ -226,6 +268,8 @@ same ID as the current card in the session."
(id (oref card id))
(now (time-to-seconds (current-time)))
(delta (- now org-fc-review--timestamp)))
(when (org-fc-position-new-p card)
(cl-incf org-fc-review-new-limit--new-seen-today))
(org-fc-review-add-rating org-fc-review--session rating)
(org-fc-review-update-data path id pos rating delta)
(org-fc-review-reset)
Expand Down Expand Up @@ -648,6 +692,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 a58bbb3

Please sign in to comment.