diff options
author | Thanos Apollo <[email protected]> | 2024-07-16 14:05:51 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-07-16 14:05:51 +0300 |
commit | f8e2dd8198319498a94d146ddc9f1ba76e150c3b (patch) | |
tree | 33bb56b287859395d0414b4b31850c1ebf0f7cd5 | |
parent | c4497af9171f932c8aad29f9020009089e046a10 (diff) |
cloze: Add gnosis-display-cloze-string
* Display cloze string appropriately during note review.
-rw-r--r-- | gnosis.el | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -503,6 +503,20 @@ First item of answers will be marked as false, while the rest unanswered." 'underline)) (setq final (or str-with-false str))) final)) + +(defun gnosis-display-cloze-string (str clozes hints correct false) + "Display STR with CLOZES and HINTS. + +Applies highlighting for CORRECT & FALSE." + (let* ((cloze-str (gnosis-cloze-create str clozes)) + (str-with-hints (gnosis-cloze-add-hints cloze-str hints)) + (str-with-c-answers (gnosis-cloze-mark-answers str-with-hints correct 'gnosis-face-correct)) + (final (gnosis-cloze-mark-false str-with-c-answers false))) + (erase-buffer) + (insert "\n" (gnosis-center-string final)) + (gnosis-insert-separator) + (gnosis-apply-syntax-overlay))) + (defun gnosis-display-basic-answer (answer success user-input) "Display ANSWER. @@ -1480,21 +1494,18 @@ If user-input is equal to CLOZE, return t." (hints (gnosis-get 'options 'notes `(= id ,id))) (success nil)) ;; Initially display the sentence with no reveals - (message "reviewing %d" id) - ;; (when (or (stringp hints) - ;; (null hints)) - ;; (setq hints nil)) - ;; quick fix for old versions of gnosis cloze. - (message "Using deprecated cloze hints.") - (gnosis-display-cloze-sentence main clozes hints 0) + (gnosis-display-cloze-string main clozes hints nil nil) (cl-loop for cloze in clozes do (let ((input (gnosis-review-cloze--input cloze))) (if (equal (car input) t) ;; Correct answer -> reveal the current cloze - (progn (setq num (1+ num)) - (gnosis-display-cloze-sentence main clozes hints num)) - ;; Incorrect answer -> display current state with failure mode - (gnosis-display-cloze-sentence main clozes hints num t) + (progn (cl-incf num) + (gnosis-display-cloze-string main (nthcdr num clozes) + (nthcdr num hints) + (cl-subseq clozes 0 num) + nil)) + ;; Incorrect answer + (gnosis-display-cloze-string main nil nil (cl-subseq clozes 0 num) (member cloze clozes)) (gnosis-display-cloze-user-answer (cdr input)) (setq success nil) (cl-return))) |