summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-12-27 06:41:51 +0200
committerThanos Apollo <[email protected]>2023-12-27 06:41:51 +0200
commit3a6cd769d7c24287bd33f7439c5e1d6de0d4a1dc (patch)
tree2b362455b9abd382930bc417ec74189c8963715c /gnosis.el
parentab26cb8c2c5d26b951fb6a407e4c7e45b4f55e3f (diff)
Add gnosis-cloze-extract-answers
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el16
1 files changed, 16 insertions, 0 deletions
diff --git a/gnosis.el b/gnosis.el
index ba46e59..61411b6 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -246,6 +246,22 @@ choice in the `CHOICES' list. Each note must correspond to one `DECK'.
(history-add-new-input nil)) ;; Disable history
(completing-read "Answer: " choices)))
+(defun gnosis-cloze-extract-answers (string)
+ "Extract items from a STRING, and group them based on the cx tag."
+ (let ((res '())
+ (pos 0))
+ (while (string-match "{\\{1,2\\}\\(c[0-9]+\\)::\\([^}]*\\)}\\{1,2\\}" string pos)
+ (let* ((tag (match-string 1 string))
+ (text (match-string 2 string))
+ (pair (assoc tag res)))
+ (if pair
+ (setcdr pair (append (cdr pair) (list text)))
+ (push (list tag text) res)))
+ (setf pos (match-end 0)))
+ ;; Reverse the final result and each sublist to maintain original order
+ ;; As our push/assoc approach prepends elements, not appends them
+ ;; (mapcar (lambda (x) (cons (car x) (cdr x))) (nreverse res)) ;; check for cl-rest
+ (mapcar (lambda (x) (cdr x)) (nreverse res))))
;; Review
(defun gnosis-review--algorithm (id success)
"Get next review date & ef for note with value of id ID.