l3kn / org-fc

Spaced Repetition System for Emacs org-mode
https://www.leonrische.me/fc/index.html
GNU General Public License v3.0
258 stars 31 forks source link

Timer to automatically flip cards. #123

Closed vkar-hub closed 6 months ago

vkar-hub commented 6 months ago

Hi, Is there a way I can flip a card after x seconds?

l3kn commented 6 months ago

It might be possible to start a timer in the org-fc-after-setup-hook and have it delete the timer and flip the card.

To avoid having the timer of one card flip a different one when you flip it manually, you could add a org-fc-after-flip-hook (maybe also a org-fc-after-review-hook) that checks if the timer is still running and deletes it.

org-fc-audio.el uses a similar approach to play audio files and stop the playback if the card if flipped or the review ends.

vkar-hub commented 6 months ago

That's a great starting point. Thanks. I'll give that a go.

l3kn commented 6 months ago

Did you get it to work as expected? If you want to share your code, there's a new https://github.com/l3kn/org-fc-extras repository I'm using for some extensions to org-fc. Alternatively, I can also add a link to your own repository if you'd prefer that.

vkar-hub commented 6 months ago

Mostly. What I have right now is this:

 (defvar recall-timer nil)

   (defun cancel-recall-timer ()
     "Cancel the recall timer if it is running."
     (when recall-timer
       (cancel-function-timers recall-timer)
       (setq recall-timer nil)))

   (defun autoflip-flashcard (seconds)
     "Automatically flip a card after x seconds."
     (cancel-recall-timer)
     (setq recall-timer (run-at-time seconds nil
                   (lambda ()
                     (org-fc-review-flip)))))

  (add-hook 'org-fc-after-setup-hook (lambda () (autoflip-flashcard 30)))
  (add-hook 'org-fc-after-flip-hook 'cancel-recall-timer)

This works fine except org-fc-review-flip flips to another instance of flip mode instead of rate mode and I'm not quite sure how to resolve that.

Disclaimer: I am very new to this so I'm not very familiar with writing or sharing code.