From e9852b4532d9bd3a10b437e957eb6747c2592004 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 18 May 2024 02:12:31 +0300 Subject: Add gnosis-completing-read Call gnosis-completing-read-function, disable history input, shuffle seq order. This should make it easier to add new gnosis types --- gnosis.el | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/gnosis.el b/gnosis.el index d633e06..bb2422c 100644 --- a/gnosis.el +++ b/gnosis.el @@ -282,6 +282,14 @@ Example: (cl-rotatef (nth (1- i) seq) (nth j seq))) ; Swap elements. finally return seq)) +(defun gnosis-completing-read (prompt seq) + "Call `gnosis-completing-read-function' with shuffled SEQ. + +PROMPT: Prompt for `gnosis-completing-read-function' +History is disabled." + (let ((history-add-new-input nil)) + (gnosis-completing-read prompt (gnosis-shuffle seq)))) + (defun gnosis-replace-item-at-index (index new-item list) "Replace item at INDEX in LIST with NEW-ITEM." (cl-loop for i from 0 for item in list @@ -488,7 +496,7 @@ Set SPLIT to t to split all input given." (error "No decks found. Please create a deck first with `gnosis-add-deck'")) (if id (gnosis-get 'name 'decks `(= id ,id)) - (funcall gnosis-completing-read-function "Deck: " (gnosis-select 'name 'decks)))) + (gnosis-completing-read "Deck: " (gnosis-select 'name 'decks)))) (cl-defun gnosis--get-deck-id (&optional (deck (gnosis--get-deck-name))) "Return id for DECK name." @@ -552,7 +560,7 @@ When called with a prefix, unsuspends all notes for tag." (defun gnosis-suspend () "Suspend note(s) with specified values." (interactive) - (let ((item (funcall gnosis-completing-read-function "Suspend by: " '("Deck" "Tag")))) + (let ((item (gnosis-completing-read "Suspend by: " '("Deck" "Tag")))) (pcase item ("Deck" (gnosis-suspend-deck)) ("Tag" (gnosis-suspend-tag)) @@ -845,7 +853,7 @@ TYPE: Type of gnosis note, must be one of `gnosis-note-types'" (unless (y-or-n-p "You are using a testing environment! Continue?") (error "Aborted"))) (let* ((deck (or deck (gnosis--get-deck-name))) - (type (or type (funcall gnosis-completing-read-function "Type: " gnosis-note-types nil t))) + (type (or type (gnosis-completing-read "Type: " gnosis-note-types nil t))) (func-name (intern (format "gnosis-add-note-%s" (downcase type))))) (if (fboundp func-name) (progn (funcall func-name deck) @@ -863,7 +871,7 @@ TYPE: Type of gnosis note, must be one of `gnosis-note-types'" "Choose the correct answer, from mcq choices for question ID." (let ((choices (gnosis-get 'options 'notes `(= id ,id))) (history-add-new-input nil)) ;; Disable history - (funcall gnosis-completing-read-function "Answer: " choices))) + (gnosis-completing-read "Answer: " choices))) (defun gnosis-cloze-remove-tags (string) "Replace cx-tags in STRING. @@ -949,11 +957,11 @@ Optionally, add cusotm PROMPT." (if (y-or-n-p "Include images?") (let* ((prompt (or prompt "Select image: ")) (image (if (y-or-n-p "Add review image?") - (funcall gnosis-completing-read-function prompt + (gnosis-completing-read prompt (cons nil (gnosis-directory-files gnosis-images-dir))) nil)) (extra-image (if (y-or-n-p "Add post review image?") - (funcall gnosis-completing-read-function prompt + (gnosis-completing-read prompt (cons nil (gnosis-directory-files gnosis-images-dir)))))) (cons image extra-image)) nil)) @@ -1629,7 +1637,7 @@ to improve readability." (interactive) ;; Refresh modeline (setq gnosis-due-notes-total (length (gnosis-review-get-due-notes))) - (let ((review-type (funcall gnosis-completing-read-function "Review: " '("Due notes" + (let ((review-type (gnosis-completing-read "Review: " '("Due notes" "Due notes of deck" "Due notes of specified tag(s)" "All notes of tag(s)")))) -- cgit v1.2.3 From 9b8b9704b7ae1bf4aa15ae0121fe79fa9a743316 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Mon, 27 May 2024 06:01:42 +0300 Subject: [fix] gnosis-review-last-interval: Minimum value to return is 1 Returning 0 would break algorithm implementation --- gnosis.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index bb2422c..bf67962 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1127,7 +1127,7 @@ well." (let* ((where-id-clause `(= id ,id)) (last-rev (gnosis-get 'last-rev 'review-log where-id-clause)) (rev-date (gnosis-get 'next-rev 'review-log where-id-clause))) - (gnosis-algorithm-date-diff last-rev rev-date))) + (max (gnosis-algorithm-date-diff last-rev rev-date) 1))) (defun gnosis-review-algorithm (id success) "Return next review date & ef for note with value of id ID. -- cgit v1.2.3 From 0d66e03b1e4ad7c06e235eb199fa18cf4e7cb7fb Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Mon, 27 May 2024 06:02:48 +0300 Subject: [fix] gnosis-algorithm: Use notes total-ef --- gnosis-algorithm.el | 5 +---- gnosis.el | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/gnosis-algorithm.el b/gnosis-algorithm.el index 075e669..33e3232 100644 --- a/gnosis-algorithm.el +++ b/gnosis-algorithm.el @@ -182,10 +182,7 @@ reviews. Will be used to determine the next interval for the first 2 successful reviews." (cl-assert (< gnosis-algorithm-ff 1) "Value of `gnosis-algorithm-ff' must be lower than 1") ;; This should only occur in testing env or when the user has made breaking changes. - (cl-assert (> (nth 2 ef) 1) "Total ef value must be above 1") - (let* ((ef (nth 2 gnosis-algorithm-ef)) - ;; If last-interval is 0, use 1 instead. - (last-interval (if (<= last-interval 0) 1 last-interval)) + (let* ((last-interval (if (<= last-interval 0) 1 last-interval)) ;; If last-interval is 0, use 1 instead. (interval (cond ((and (= successful-reviews 0) success) (car initial-interval)) ((and (= successful-reviews 1) success) diff --git a/gnosis.el b/gnosis.el index bf67962..5480a4d 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1145,7 +1145,7 @@ Returns a list of the form ((yyyy mm dd) (ef-increase ef-decrease ef-total))." ;; (last-interval (max (gnosis-review--get-offset id) 1)) (last-interval (gnosis-review-last-interval id))) ;; last interval (list (gnosis-algorithm-next-interval :last-interval last-interval - :ef ef + :ef (nth 2 ef) ;; total ef is used for next interval :success success :successful-reviews t-success :failure-factor ff -- cgit v1.2.3 From 7bd22e9bd9e2ffdbf05bbefb9384f42305916f62 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 29 May 2024 17:34:46 +0300 Subject: [fix] Use funcall for completing-read-func --- gnosis.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index 5480a4d..6a10b1e 100644 --- a/gnosis.el +++ b/gnosis.el @@ -288,7 +288,7 @@ Example: PROMPT: Prompt for `gnosis-completing-read-function' History is disabled." (let ((history-add-new-input nil)) - (gnosis-completing-read prompt (gnosis-shuffle seq)))) + (funcall gnosis-completing-read-function prompt (gnosis-shuffle seq)))) (defun gnosis-replace-item-at-index (index new-item list) "Replace item at INDEX in LIST with NEW-ITEM." -- cgit v1.2.3 From 9960c893190e3ce462568f987bad0dde9fc9b07c Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 29 May 2024 17:37:35 +0300 Subject: Add gnosis-review-result & fix completing-read calls gnosis-review-result will be used to update notes on the review-log and notes left to review --- gnosis.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gnosis.el b/gnosis.el index 6a10b1e..0d815d9 100644 --- a/gnosis.el +++ b/gnosis.el @@ -853,7 +853,7 @@ TYPE: Type of gnosis note, must be one of `gnosis-note-types'" (unless (y-or-n-p "You are using a testing environment! Continue?") (error "Aborted"))) (let* ((deck (or deck (gnosis--get-deck-name))) - (type (or type (gnosis-completing-read "Type: " gnosis-note-types nil t))) + (type (or type (funcall gnosis-completing-read-function "Type: " gnosis-note-types nil t))) (func-name (intern (format "gnosis-add-note-%s" (downcase type))))) (if (fboundp func-name) (progn (funcall func-name deck) @@ -1180,6 +1180,11 @@ SUCCESS is a boolean value, t for success, nil for failure." (gnosis-update 'review-log `(= t-fails ,(1+ (gnosis-get 't-fails 'review-log `(= id ,id)))) `(= id ,id)) (gnosis-update 'review-log `(= c-success 0) `(= id ,id))))) +(defun gnosis-review-result (id success) + "Update review note ID results for SUCCESS." + (gnosis-review--update id success) + (setf gnosis-due-notes-total (length (gnosis-review-get-due-notes)))) + (defun gnosis-review-mcq (id) "Display multiple choice answers for question ID." (gnosis-display-question id) @@ -1332,7 +1337,7 @@ NOTE-COUNT: Total notes reviewed" (?s "suspend") (?e "edit") (?q "quit")))) - (?n (gnosis-review--update note success)) + (?n (gnosis-review-result note success)) (?o (setf success (if success nil t)) (gnosis-display-next-review note success) (gnosis-review-actions success note note-count)) @@ -1340,7 +1345,7 @@ NOTE-COUNT: Total notes reviewed" (?e (gnosis-edit-note note t) (recursive-edit) (gnosis-review-actions success note note-count)) - (?q (gnosis-review--update note success) + (?q (gnosis-review-result note success) (gnosis-review-commit note-count) ;; Break the loop of `gnosis-review-session' (throw 'stop-loop t)))) @@ -1357,8 +1362,7 @@ NOTES: List of note ids" (cl-loop for note in notes do (let ((success (gnosis-review-note note))) (setf note-count (1+ note-count)) - (gnosis-review-actions success note note-count) - (setf gnosis-due-notes-total (length (gnosis-review-get-due-notes)))) + (gnosis-review-actions success note note-count)) finally (gnosis-review-commit note-count))))))) ;; Editing notes @@ -1637,7 +1641,7 @@ to improve readability." (interactive) ;; Refresh modeline (setq gnosis-due-notes-total (length (gnosis-review-get-due-notes))) - (let ((review-type (gnosis-completing-read "Review: " '("Due notes" + (let ((review-type (funcall gnosis-completing-read-function "Review: " '("Due notes" "Due notes of deck" "Due notes of specified tag(s)" "All notes of tag(s)")))) -- cgit v1.2.3