summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-12-13 22:36:11 +0200
committerThanos Apollo <[email protected]>2023-12-13 22:36:11 +0200
commite9f1c48395f19a1988bcf3d16ca8b292a76313e0 (patch)
tree04b062b62d0fd5bd2e7b4ac6ebda039cd5d14716
parent65bc308d10bcd7108cebda780ed09b36c542fa15 (diff)
Add gnosis-get
Use gnosis-get as front-end of gnosis--select to get desired value
-rw-r--r--gnosis.el20
1 files changed, 12 insertions, 8 deletions
diff --git a/gnosis.el b/gnosis.el
index 008ab20..6fbaf5b 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -59,6 +59,9 @@
"Insert VALUES to TABLE."
(emacsql gnosis-db `[:insert :into ,table :values ,values]))
+(defun gnosis-get (value table &optional restrictions)
+ "Get VALUE from TABLE, optionally with where RESTRICTIONS."
+ (caar (gnosis--select value table restrictions)))
(defun gnosis--delete (table value)
"From TABLE use where to delete VALUE."
@@ -66,7 +69,7 @@
(defun gnosis--display-question (id)
"Display main row for question ID."
- (let ((question (caar (gnosis--select 'main 'notes `(= id ,id)))))
+ (let ((question (gnosis-get 'main 'notes `(= id ,id))))
;; Animate.el is used only for testing purposes.
(animate-string question 1)))
@@ -96,7 +99,7 @@ the returns the list of inputs in reverse order."
(defun gnosis--get-deck-id ()
"Select id for deck name."
(let ((deck (gnosis--get-deck-name)))
- (caar (gnosis--select 'id 'decks `(= name ,deck)))))
+ (gnosis-get 'id 'decks `(= name ,deck))))
(defun gnosis-delete-deck (id)
"Delete deck with id value of ID."
@@ -132,26 +135,27 @@ TAGS are used to organize questions."
(defun gnosis-mcq-answer (id)
"Choose the correct answer, from mcq choices for question ID."
- (let ((choices (gnosis--select 'options 'notes `(= id ,id)))
+ (let ((choices (gnosis-get 'options 'notes `(= id ,id)))
(history-add-new-input nil)) ;; Disable history
(completing-read "Answer: " choices)))
(defun gnosis-review-mcq-choices (id)
"Display multiple choice answers for question ID."
- (let ((canswer (gnosis--select 'answer 'notes `(= id ,id)))
- (choices (gnosis--select 'answer 'notes `(= id ,id)))
+ (let ((answer (gnosis-get 'answer 'notes `(= id ,id)))
+ (choices (gnosis-get 'options 'notes `(= id ,id)))
(user-choice (gnosis-mcq-answer id)))
- (if (equal (nth (- canswer 1) choices) user-choice)
+ (if (equal (nth (- answer 1) choices) user-choice)
(message "Correct!")
(message "False"))))
(defun gnosis-review (id)
"Start review for question ID."
- (let ((type (gnosis--get-id 'notes 'type id)))
+ (let ((type (gnosis-get 'type 'notes `(= id id))))
(pcase type
("mcq" (gnosis-review-mcq-choices id))
("basic" (message "Not Ready yet."))
- ("cloze" (message "Not Ready yet.")))))
+ ("cloze" (message "Not Ready yet."))
+ (_ (error "Malformed note type")))))
;; testing
(defun gnosis-test-buffer ()