diff options
author | Thanos Apollo <[email protected]> | 2024-05-27 06:06:38 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-05-27 06:06:38 +0300 |
commit | f55a1585fc21c34ab07fc1beaa836c553c0fa24d (patch) | |
tree | 0be302e64245454deb945012022cbfd90fdeb2f7 | |
parent | 2b5d60b1beb1b15c142213b1ba20a9c0dc871099 (diff) |
[feature] Add template for mc-cloze note type
-rw-r--r-- | gnosis.el | 45 |
1 files changed, 44 insertions, 1 deletions
@@ -125,7 +125,7 @@ When nil, the image will be displayed at its original size." (defconst gnosis-db-version 2 "Gnosis database version.") -(defvar gnosis-note-types '("MCQ" "Cloze" "Basic" "Double" "y-or-n") +(defvar gnosis-note-types '("MCQ" "MCC" "Cloze" "Basic" "Double" "y-or-n") "Gnosis available note types.") (defvar gnosis-previous-note-tags '() @@ -857,6 +857,23 @@ CHAR: separator for mcc, default to `gnosis-mcc-separator'" (when (string-match-p (regexp-quote char) s) (split-string s (regexp-quote char)))) (split-string str " ")))) + +(defun gnosis-add-note-mcc (deck) + "Add MCC note type to DECK. + +MCC (Multiple Choice Cloze) note type consists of a sentence with a +single cloze, for which user will be prompted to select the correct +answer." + (interactive) + (let* ((input (gnosis-read-string-from-buffer "prompt" "string")) + (question (gnosis-mcc-remove-separator input)) + (options (gnosis-mcc-extract-options input)) + (tags (gnosis-prompt-tags--split gnosis-previous-note-tags)) + (images (gnosis-select-images))) + (cl-loop for option in options + do (gnosis-add-note-fields deck "mcc" question option (car option) + "extra" tags 0 (car images) (cdr images))))) + ;;;###autoload (defun gnosis-add-note (&optional deck type) "Create note(s) as TYPE interactively. @@ -930,6 +947,12 @@ Valid cloze formats include: (mapcar (lambda (tag-group) (nreverse (cdr tag-group))) (nreverse result-alist)))) +(defun gnosis-mcc-remove-separator (string &optional separator) + "Remove SEPARATOR and all followed words from STRING." + (let* ((separator (or separator gnosis-mcc-separator)) + (result (replace-regexp-in-string (format "%s[^ ]*" separator) "" string))) + result)) + (defun gnosis-compare-strings (str1 str2) "Compare STR1 and STR2. @@ -1279,6 +1302,26 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." (gnosis-display-next-review id success) success)) +(defun gnosis-review-mcc (id) + "Review MCC note of ID." + (let ((main (gnosis-get 'main 'notes `(= id ,id))) + ;; Cloze needs to be a list, we take car as the answer + (cloze (list (gnosis-get 'answer 'notes `(= id ,id)))) + (user-choice nil) + (success nil)) + (gnosis-display-cloze-sentence main cloze) + (gnosis-display-image id) + (setf user-choice (gnosis-mcq-answer id) + success (string= user-choice (car cloze))) + (gnosis-display-cloze-reveal :replace (car cloze) + :success success) + ;; Display user answer only upon failure + (unless success + (gnosis-display-cloze-user-answer user-choice)) + (gnosis-display-extra id) + (gnosis-display-next-review id success) + success)) + (defun gnosis-review-note (id) "Start review for note with value of id ID, if note is unsuspended." (when (gnosis-suspended-p id) |