Skip to content

Commit

Permalink
Prompt for algorithm when creating card
Browse files Browse the repository at this point in the history
  • Loading branch information
l3kn committed Mar 13, 2024
1 parent 0f505bc commit e7dc402
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
32 changes: 24 additions & 8 deletions org-fc-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -419,20 +419,36 @@ Use `org-fc-register-algo' for adding algorithms.")
(cl-first entry)
(error "No such spacing algorithm: %s" name)))

(defun org-fc-select-algo ()
"Select a spacing algorithm."
(let* ((choice (completing-read
"Algorithm: "
(mapcar (lambda (c) (car c)) org-fc-algos)
nil
:require-match)))
choice))

;;; Card Initialization

(defun org-fc--init-card (type)
"Initialize the current card as a flashcard.
Should only be used by the init functions of card TYPEs."
(when (org-fc-entry-p)
(error "Headline is already a flashcard"))
(org-back-to-heading)
(org-set-property
org-fc-created-property
(org-fc-timestamp-in 0))
(org-set-property org-fc-type-property type)
(org-id-get-create)
(org-fc--add-tag org-fc-flashcard-tag))
(error "Headline is already a flashcard"))

(let ((algo (org-fc-select-algo)))
(when (null algo)
(error "No algorithm selected"))
(org-back-to-heading)
(org-set-property
org-fc-created-property
(org-fc-timestamp-in 0))
(org-set-property org-fc-type-property type)
(when algo
(org-set-property org-fc-algo-property algo))
(org-id-get-create)
(org-fc--add-tag org-fc-flashcard-tag)
(run-hooks 'org-fc-after-init-card-hook)))

;;; Card Types
;;;; Type Management
Expand Down
1 change: 1 addition & 0 deletions tests/erts/card_init_double.erts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Back
:PROPERTIES:
:FC_CREATED: 1970-01-01T00:00:00Z
:FC_TYPE: double
:FC_ALGO: sm2
:ID: dummy-id
:END:
:REVIEW_DATA:
Expand Down
1 change: 1 addition & 0 deletions tests/erts/card_init_normal.erts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Back
:PROPERTIES:
:FC_CREATED: 1970-01-01T00:00:00Z
:FC_TYPE: normal
:FC_ALGO: sm2
:ID: dummy-id
:END:
:REVIEW_DATA:
Expand Down
2 changes: 2 additions & 0 deletions tests/erts/card_rate_double.erts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Name: Case 1
:PROPERTIES:
:FC_CREATED: 1970-01-01T00:00:00Z
:FC_TYPE: double
:FC_ALGO: sm2
:ID: dummy-id
:END:
:REVIEW_DATA:
Expand All @@ -19,6 +20,7 @@ Back
:PROPERTIES:
:FC_CREATED: 1970-01-01T00:00:00Z
:FC_TYPE: double
:FC_ALGO: sm2
:ID: dummy-id
:END:
:REVIEW_DATA:
Expand Down
6 changes: 6 additions & 0 deletions tests/org-fc-card-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
(org-fc-test-fixture "erts/card_init_normal.erts")
(lambda ()
(org-fc-test-with-overwrites
(org-fc-test-overwrite-fun
org-fc-select-algo
(lambda () "sm2"))
(org-fc-test-overwrite-fun
time-to-seconds
(lambda () 0))
Expand Down Expand Up @@ -43,6 +46,9 @@
(org-fc-test-fixture "erts/card_init_double.erts")
(lambda ()
(org-fc-test-with-overwrites
(org-fc-test-overwrite-fun
org-fc-select-algo
(lambda () "sm2"))
(org-fc-test-overwrite-fun
time-to-seconds
(lambda () 0))
Expand Down

0 comments on commit e7dc402

Please sign in to comment.