From fed9709dde69e2a5c7d5b9f8f9efe7b7eb596d6c Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:29:56 +0200 Subject: 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 --- gnosis.el | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'gnosis.el') 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." -- cgit v1.2.3