summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-01-19 00:29:56 +0200
committerThanos Apollo <[email protected]>2024-01-19 00:29:56 +0200
commitfed9709dde69e2a5c7d5b9f8f9efe7b7eb596d6c (patch)
treeac1d7c8141c18add4a1d70d113e849350e6b8a4e /gnosis.el
parent427fe5f7df2ec401cec1cb120d2a7a1516dc1ecf (diff)
Refactor note creation
- Added `gnosis-note-types` variable to store available note types (MCQ, Cloze, Basic, Double, y-or-n) - Updated `gnosis-add-note` function to dynamically call corresponding note creation functions based on selected type - Updated interactive prompt in `gnosis-add-note` to display available note types This commit enhances the flexibility & extensibility of note creation
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el18
1 files changed, 8 insertions, 10 deletions
diff --git a/gnosis.el b/gnosis.el
index 3c38364..efc0321 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -77,6 +77,9 @@
(defconst gnosis-db-version 1
"Gnosis database version.")
+(defvar gnosis-note-types '(MCQ Cloze Basic Double y-or-n)
+ "Gnosis available note types.")
+
;;; Faces
(defgroup gnosis-faces nil
@@ -136,8 +139,6 @@
"Face for next review."
:group 'gnosis-face)
-
-
(cl-defun gnosis-select (value table &optional (restrictions '1=1))
"Select VALUE from TABLE, optionally with RESTRICTIONS.
@@ -647,17 +648,14 @@ See `gnosis-add-note--cloze' for more reference."
;;;###autoload
(defun gnosis-add-note (type)
"Create note(s) as TYPE interactively."
- (interactive (list (completing-read "Type: " '(MCQ Cloze Basic Double y-or-n) nil t)))
+ (interactive (list (completing-read "Type: " gnosis-note-types nil t)))
(when gnosis-testing
(unless (y-or-n-p "You are using a testing environment! Continue?")
(error "Aborted")))
- (pcase type
- ("MCQ" (gnosis-add-note-mcq))
- ("Cloze" (gnosis-add-note-cloze))
- ("Basic" (gnosis-add-note-basic))
- ("Double" (gnosis-add-note-double))
- ("y-or-n" (gnosis-add-note-y-or-n))
- (_ (message "No such type."))))
+ (let ((func-name (intern (format "gnosis-add-note-%s" (downcase type)))))
+ (if (fboundp func-name)
+ (funcall func-name)
+ (message "No such type."))))
(defun gnosis-mcq-answer (id)
"Choose the correct answer, from mcq choices for question ID."