summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-01-19 00:49:44 +0200
committerThanos Apollo <[email protected]>2024-01-19 00:49:44 +0200
commit5359697d5e8ee44567fba710e11ad73845fcc953 (patch)
tree014f3e9b9b6937db78dcd48868450f0cae36f822 /gnosis.el
parentfd42525da74189c7c6d1eddd17fa15cfcc643cbd (diff)
parentb79a2331f253f180ee74df2fd6ff6385a96193a0 (diff)
Merge branch '#emacs-devel-suggestions' into testing
Changes suggested by Philip Kaludercic via the emacs-devel mailing list <https://lists.gnu.org/archive/html/emacs-devel/2024-01/msg00682.html> Philip pointed out that gnosis relies heavily on completing-read for user interactions, but for users that do not use completion packages such as vertico it's inconvenient to say the least. This should be addressed. Another important change was making gnosis-add-note more extensible. Adding your own custom note types should be easier now as well as the maintainability. Many of the changes made here are not tested properly. Merging into testing branch for further review and refactoring.
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el70
1 files changed, 35 insertions, 35 deletions
diff --git a/gnosis.el b/gnosis.el
index 7ddeb30..08e803c 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
@@ -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."
@@ -758,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.
@@ -788,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))
@@ -816,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.
@@ -867,7 +861,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."
@@ -875,9 +869,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))
@@ -917,8 +911,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)
@@ -1039,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))))))
@@ -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
@@ -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)
@@ -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)))