From 427fe5f7df2ec401cec1cb120d2a7a1516dc1ecf Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:13:35 +0200 Subject: Refactor directory and database naming conventions - Updated gnosis-dir to use `locate-user-emacs-file` for consistent file location - Updated gnosis-images-dir to use `expand-file-name` for consistent filepath - Updated gnosis-db to use `expand-file-name` for consistent filepath in emacsql-sqlite initialization --- gnosis.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnosis.el b/gnosis.el index 7ddeb30..3c38364 100644 --- a/gnosis.el +++ b/gnosis.el @@ -51,7 +51,7 @@ :group 'external :prefix "gnosis-") -(defcustom gnosis-dir (concat user-emacs-directory "gnosis") +(defcustom gnosis-dir (locate-user-emacs-file "gnosis") "Gnosis directory." :type 'directory :group 'gnosis) @@ -62,13 +62,13 @@ :group 'gnosis) -(defvar gnosis-images-dir (concat (file-name-as-directory gnosis-dir) "images") +(defvar gnosis-images-dir (expand-file-name "images" gnosis-dir) "Gnosis images directory.") (defconst gnosis-db (if (not (file-directory-p gnosis-dir)) (gnosis-db-init) - (emacsql-sqlite (concat (file-name-as-directory gnosis-dir) "gnosis.db"))) + (emacsql-sqlite (expand-file-name "gnosis.db" gnosis-dir))) "Gnosis database file.") (defvar gnosis-testing nil -- cgit v1.2.3 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(-) 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 From bd048cbd365fe24e4c67f6247b63b49e03a1661a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:32:00 +0200 Subject: gnsois-suspended-p: Redo without if statement --- gnosis.el | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gnosis.el b/gnosis.el index efc0321..b1230dd 100644 --- a/gnosis.el +++ b/gnosis.el @@ -756,9 +756,7 @@ Optionally, add cusotm PROMPT." (defun gnosis-suspended-p (id) "Return t if note with ID is suspended." - (if (= (gnosis-get 'suspend 'review-log `(= id ,id)) 1) - t - nil)) + (= (gnosis-get 'suspend 'review-log `(= id ,id)) 1)) (defun gnosis-get-deck-due-notes (&optional deck-id) "Return due notes for deck, with value of DECK-ID. -- cgit v1.2.3 From c8257934d341605a52848744b7dc15774b40d4b5 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:32:21 +0200 Subject: Fix typos & indentation --- gnosis.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gnosis.el b/gnosis.el index b1230dd..2a21252 100644 --- a/gnosis.el +++ b/gnosis.el @@ -784,7 +784,7 @@ DATE is a list of the form (year month day)." (cl-mapcan (lambda (note-id) (gnosis-get-note-tags note-id)) due-notes) - :test 'equal))) + :test #'equal))) (cl-defun gnosis-tag-prompt (&key (prompt "Selected tags") (match nil) (due nil)) @@ -863,7 +863,7 @@ Returns a list of the form ((yyyy mm dd) ef)." (cl-mapcan (lambda (note-id) (gnosis-get-note-tags note-id)) due-notes) - :test 'equal))) + :test #'equal))) (defun gnosis-review--get-offset (id) "Return offset for note with value of id ID." @@ -871,9 +871,9 @@ Returns a list of the form ((yyyy mm dd) ef)." (gnosis-algorithm-date-diff last-rev))) (defun gnosis-review-round (num) - "Round NUM to 1 decimal. + "Round NUM to 2 decimals. -This function is used to round floating point numbers to 1 decimal, +This function is used to round floating point numbers to 2 decimals, such as the easiness factor (ef)." (/ (round (* num 100.00)) 100.00)) @@ -913,8 +913,9 @@ SUCCESS is a binary value, 1 is for successful review." (answer (nth (- (gnosis-get 'answer 'notes `(= id ,id)) 1) choices)) (user-choice (gnosis-mcq-answer id))) (if (string= answer user-choice) - (progn (gnosis-review--update id 1) - (message "Correct!")) + (progn + (gnosis-review--update id 1) + (message "Correct!")) (gnosis-review--update id 0) (message "False")) (gnosis-display-correct-answer-mcq answer user-choice) -- cgit v1.2.3 From 1b16f3743946fa18127872a70ed31a04329bd135 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:33:45 +0200 Subject: gnosis-review-is-due-p: Redo without if statement --- gnosis.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gnosis.el b/gnosis.el index 2a21252..26e8cdd 100644 --- a/gnosis.el +++ b/gnosis.el @@ -812,10 +812,8 @@ Returns a list of unique tags." "Check if note with value of NOTE-ID for id is due for review. Check if it's suspended, and if it's due today." - (if (and (not (gnosis-suspended-p note-id)) - (gnosis-review-is-due-today-p note-id)) - t - nil)) + (and (not (gnosis-suspended-p note-id)) + (gnosis-review-is-due-today-p note-id))) (defun gnosis-review-is-due-today-p (id) "Return t if note with ID is due today. -- cgit v1.2.3 From c5c0320e24929309b17103cbea93e16acaefa894 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:34:03 +0200 Subject: gnosis-review--session: Refactor using read-multiple-choice --- gnosis.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gnosis.el b/gnosis.el index 26e8cdd..6662d1c 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1034,13 +1034,18 @@ NOTE-NUM: The number of notes reviewed in the session." (cl-loop for note in notes do (gnosis-review-note note) (setf note-count (1+ note-count)) - (pcase (read-char-choice "Note Action: [n]ext, [s]uspend, [e]dit, [q]uit: " '(?n ?s ?e ?q)) + (pcase (car (read-multiple-choice + "Note actions" + '((?n "next") + (?s "suspend") + (?e "edit") + (?q "quit")))) (?n nil) (?s (gnosis-suspend-note note)) - (?e (progn (gnosis-edit-note note) - (recursive-edit))) - (?q (progn (gnosis-review-commit note-count) - (cl-return)))) + (?e (gnosis-edit-note note) + (recursive-edit)) + (?q (gnosis-review-commit note-count) + (cl-return))) finally (gnosis-review-commit note-count)))))) -- cgit v1.2.3 From 980a29d48bbe12bdaae4dad18ca1dd12af5328fa Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:39:07 +0200 Subject: gnosis-edit-mode: Update lighter --- gnosis.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index 6662d1c..eb84bb9 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1149,7 +1149,7 @@ changes." (define-derived-mode gnosis-edit-mode emacs-lisp-mode "Gnosis EDIT" "Gnosis Edit Mode." :interactive t - :lighter " gnosis-edit-mode" + :lighter " Gnosis Edit" :keymap gnosis-edit-mode-map) -- cgit v1.2.3 From e57b48ba4e5ea9a0de16d35913f120742e79f594 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:40:04 +0200 Subject: gnosis-edit-note-contents: Use eq & null --- gnosis.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnosis.el b/gnosis.el index eb84bb9..3e8af94 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1119,7 +1119,7 @@ changes." (extra-notes ,extra-notes) (image ,image) (second-image ,second-image)) - do (cond ((equal field 'id) + do (cond ((eq field 'id) (insert (format (concat ":%s " (propertize "%s" 'read-only t) "\n") field value))) ((numberp value) (insert (format ":%s %s\n" field value))) @@ -1127,7 +1127,7 @@ changes." (not (equal value nil))) (insert (format ":%s '%s\n" field (format "%s" (cl-loop for item in value collect (format "\"%s\"" item)))))) - ((equal value nil) + ((null value) (insert (format ":%s %s\n" field 'nil))) (t (insert (format ":%s \"%s\"\n" field value))))) (delete-char -1) ;; delete extra line -- cgit v1.2.3 From b79a2331f253f180ee74df2fd6ff6385a96193a0 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 00:42:16 +0200 Subject: gnosis-edit-update-note: Use memq instead of member --- gnosis.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index 3e8af94..08e803c 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1175,7 +1175,7 @@ SECOND-IMAGE: Image to display after user-input" (image . ,image) (second-image . ,second-image)) when value - do (cond ((member field '(extra-notes image second-image)) + do (cond ((memq field '(extra-notes image second-image)) (gnosis-update 'extras `(= ,field ,value) `(= id ,id))) ((listp value) (gnosis-update 'notes `(= ,field ',value) `(= id ,id))) -- cgit v1.2.3