aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-04-24 00:12:28 +0300
committerThanos Apollo <[email protected]>2024-04-24 00:12:28 +0300
commit5b53be7658bdb7f800e6b36b9b154c9a4fd55f63 (patch)
tree8e3274d34a5dcf68143dbdc6e78c9b6bd8ca7d9e
parentab94733012781cd9863a1b45d4fc86eed9a918cd (diff)
Refactor gnosis-prompt-mcq-input
- Use recursion when incorrect formatting is used - Separate the process of input to a different function
-rw-r--r--gnosis.el32
1 files changed, 14 insertions, 18 deletions
diff --git a/gnosis.el b/gnosis.el
index f614e84..fe128b8 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -989,24 +989,20 @@ default value."
(setf gnosis-previous-note-hint hint)
hint))
-(defun gnosis-prompt-mcq-input ()
- "Prompt for MCQ content.
-
-Return a list of the form ((QUESTION CHOICES) CORRECT-CHOICE-INDEX)."
- (let ((user-input (gnosis-read-string-from-buffer (or (car gnosis-mcq-guidance) "")
- (or (cdr gnosis-mcq-guidance) ""))))
- (unless (string-match-p gnosis-mcq-separator user-input)
- (error "Separator %s not found" gnosis-mcq-separator))
- (let* ((input-seperated (split-string user-input gnosis-mcq-separator t "[\s\n]"))
- (stem (car input-seperated))
- (input (split-string
- (mapconcat 'identity (cdr input-seperated) "\n")
- gnosis-mcq-option-separator t "[\s\n]"))
- (correct-choice-index
- (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-mcq-input (&optional prompt string)
+ "PROMPT for MCQ note content.
+
+STRING: Guidance string."
+ (let ((user-input (gnosis-read-string-from-buffer (or prompt (car gnosis-mcq-guidance) "")
+ (or string (cdr gnosis-mcq-guidance) ""))))
+ (cond ((not (string-match-p gnosis-mcq-separator user-input))
+ (gnosis-prompt-mcq-input (format "`gnosis-mcq-separator': %s not found!" gnosis-mcq-separator)
+ user-input))
+ ((not (string-match "{.*}" user-input))
+ (gnosis-prompt-mcq-input (format "Please wrap the right option with {}")
+ user-input))
+ (t (gnosis-mcq-process-input user-input)))))
+
(defun gnosis-prompt-tags--split (&optional previous-note-tags)
"Prompt user for tags, split string by space.