summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-04-24 00:15:19 +0300
committerThanos Apollo <[email protected]>2024-04-24 00:15:19 +0300
commita2b59188dfcebc7c666f8f75a60035638a65c798 (patch)
tree60f8d1058067e49689fb4a12656ec7fc3d46f1a8 /gnosis.el
parent5b53be7658bdb7f800e6b36b9b154c9a4fd55f63 (diff)
Add gnosis-mcq-process-input
- Process input given from gnosis-mcq-prompt
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/gnosis.el b/gnosis.el
index fe128b8..9cd3d3c 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -1003,6 +1003,26 @@ STRING: Guidance string."
user-input))
(t (gnosis-mcq-process-input user-input)))))
+(defun gnosis-mcq-process-input (user-input &optional stem-separator option-separator)
+ "Process USER-INPUT for MCQ note.
+
+STEM-SEPARATOR: Separator of question stem & options
+OPTION-SEPARATOR: Separator of each option
+
+Return ((QUESTION CHOICES) CORRECT-CHOICE-INDEX)"
+ (let* ((stem-separator (or stem-separator gnosis-mcq-separator))
+ (option-separator (or option-separator gnosis-mcq-option-separator))
+ (input-separated (split-string user-input stem-separator t "[\s\n]"))
+ (stem (car input-separated))
+ (input (split-string
+ (mapconcat 'identity (cdr input-separated) "\n")
+ option-separator t "[\s\n]"))
+ (correct-choice-index
+ ;; Make sure correct choice is given
+ (or (cl-position-if (lambda (string) (string-match "{.*}" string)) input)
+ (error "Correct choice not found. Use {} to indicate the correct option")))
+ (choices (mapcar (lambda (string) (replace-regexp-in-string "{\\|}" "" string)) input)))
+ (list (cons stem choices) (+ correct-choice-index 1))))
(defun gnosis-prompt-tags--split (&optional previous-note-tags)
"Prompt user for tags, split string by space.