From cee8aa43f8e1bc4dacec63630051bbc1d4c1d246 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 16:55:50 +0300 Subject: gnosis-select-by-tag: Use cl-assert --- gnosis.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gnosis.el b/gnosis.el index 48cc707..d29a16c 100644 --- a/gnosis.el +++ b/gnosis.el @@ -888,8 +888,7 @@ Optionally, add cusotm PROMPT." (defun gnosis-select-by-tag (input-tags) "Return note ID's for every note with INPUT-TAGS." - (unless (listp input-tags) - (error "`input-tags' need to be a list")) + (cl-assert (listp input-tags) t "Input tags must be a list") (cl-loop for (id tags) in (gnosis-select '[id tags] 'notes) when (and (cl-every (lambda (tag) (member tag tags)) input-tags) (not (gnosis-suspended-p id))) -- cgit v1.2.3 From fcc09a3efc652cdf58208487531243f911e64fd2 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 18:59:51 +0300 Subject: Add gnosis-get-deck-notes - Add gnosis-get-deck-notes - Replace old functions with gnosis-get-deck-notes --- gnosis.el | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/gnosis.el b/gnosis.el index d29a16c..bbc1acc 100644 --- a/gnosis.el +++ b/gnosis.el @@ -898,16 +898,17 @@ Optionally, add cusotm PROMPT." "Return t if note with ID is suspended." (= (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. +(defun gnosis-get-deck-notes (&optional deck-id due) + "Return notes for deck, with value of DECK-ID. -if DUE is t, return only due notes" - (let* ((deck (or deck-id (gnosis--get-deck-id))) - (notes (gnosis-select 'id 'notes `(= deck-id ,deck) t))) - (cl-loop for note in notes - when (and (not (gnosis-suspended-p note)) - (gnosis-review-is-due-p note)) - collect note))) +If DUE is t, return only due notes." + (let ((notes (gnosis-select 'id 'notes `(= deck-id ,(or deck-id (gnosis--get-deck-id))) t))) + (if (or due nil) + (cl-loop for note in notes + when (and (not (gnosis-suspended-p note)) + (gnosis-review-is-due-p note)) + collect note) + notes))) (defun gnosis-past-or-present-p (date) "Compare the input DATE with the current date. @@ -1433,10 +1434,6 @@ SUSPEND: Suspend note, 0 for unsuspend, 1 for suspend" (gnosis-update 'notes `(= ,field ',value) `(= id ,id))) (t (gnosis-update 'notes `(= ,field ,value) `(= id ,id)))))) -(cl-defun gnosis-get-notes-for-deck (&optional (deck (gnosis--get-deck-id))) - "Return a list of ID vlaues for each note with value of deck-id DECK." - (gnosis-select 'id 'notes `(= deck-id ,deck) t)) - (defun gnosis-get-ef-increase (id) "Return ef-increase for note with value of id ID." (let ((ef-increase (gnosis-get 'ef-increase 'decks `(= id ,(gnosis-get 'deck-id 'notes `(= id ,id)))))) @@ -1514,7 +1511,7 @@ to improve readability." "All notes of tag(s)")))) (pcase review-type ("Due notes" (gnosis-review--session (gnosis-review-get-due-notes))) - ("Due notes of deck" (gnosis-review--session (gnosis-get-deck-due-notes))) + ("Due notes of deck" (gnosis-review--session (gnosis-get-deck-notes nil t))) ("Due notes of specified tag(s)" (gnosis-review--session (gnosis-select-by-tag (gnosis-tag-prompt :due t)))) ("All notes of tag(s)" (gnosis-review--session (gnosis-select-by-tag (gnosis-tag-prompt))))))) -- cgit v1.2.3 From 248ae9a69e1aa476546b152f22f4bef035403207 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:13:16 +0300 Subject: Add gnosis-collect-note-ids A command to simplify collecting note-ids --- gnosis.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gnosis.el b/gnosis.el index bbc1acc..303cfad 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1613,6 +1613,31 @@ to improve readability." ;; (gnosis-dashboard-output-notes) ;; (revert-buffer t t t))) (local-set-key (kbd "a") #'gnosis-add-note))) +(cl-defun gnosis-collect-note-ids (&key (tags nil) (due nil) (deck nil)) + "Return list of note ids based on TAGS, DUE, DECKS. + +TAGS: boolean value, t to specify tags. +DUE: boolean value, t to specify due notes. +DECK: boolean value, t to specify notes from deck." + (cl-assert (and (booleanp due) (booleanp tags) (booleanp deck)) nil "provide boolean value") + (cond ((and (null tags) (null due) (null deck)) + (gnosis-select 'id 'notes '1=1 t)) + ;; All due notes + ((and (null tags) due (null deck)) + (gnosis-review-get-due-notes)) + ;; All notes for tags + ((and tags (null due) (null deck)) + (gnosis-select-by-tag (gnosis-tag-prompt))) + ;; All due notes for tags + ((and tags due (null deck)) + (gnosis-select-by-tag (gnosis-tag-prompt :due t))) + ;; All notes for deck + ((and (null tags) (null due) deck) + (gnosis-get-deck-notes nil nil)) + ;; All due notes for deck + ((and (null tags) due deck) + (gnosis-get-deck-notes nil t)))) + (defun gnosis-dashboard-deck-note-count (id) "Return total note count for deck with ID." -- cgit v1.2.3 From da011501db25a83e6947f0e65119036a7f702f1b Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:14:29 +0300 Subject: gnosis-dashboard-output-notes: Adjust with note-ids as arg - =note-ids= is now an arg - Store =note-ids= on =gnosis-dashboard-note-ids= - Update local keybindings (needs rework) --- gnosis.el | 58 +++++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/gnosis.el b/gnosis.el index 303cfad..7cbf968 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1582,37 +1582,6 @@ to improve readability." else collect (prin1-to-string item))) -(defun gnosis-dashboard-output-notes () - "Return note contents for gnosis dashboard." - (let ((max-id (apply 'max (gnosis-select 'id 'notes '1=1 t)))) - (setq tabulated-list-format [("Main" 30 t) - ("Options" 20 t) - ("Answer" 25 t) - ("Tags" 25 t) - ("Type" 10 t) - ("Suspend" 2 t)]) - (tabulated-list-init-header) - (setf tabulated-list-entries - (cl-loop for id from 1 to max-id - for output = (gnosis-dashboard-output-note id) - when output - collect (list (number-to-string id) (vconcat output)))) - ;; Keybindings, for editing, suspending, deleting notes. - ;; We use `local-set-key' to bind keys to the buffer to avoid - ;; conflicts when using the dashboard for displaying either notes - ;; or decks. - (local-set-key (kbd "e") #'gnosis-dashboard-edit-note) - (local-set-key (kbd "s") #'(lambda () (interactive) - (gnosis-suspend-note - (string-to-number (tabulated-list-get-id))) - (gnosis-dashboard-output-notes) - (revert-buffer t t t))) - ;; (local-set-key (kbd "d") #'(lambda () (interactive) - ;; (gnosis-delete-note - ;; (string-to-number (tabulated-list-get-id))) - ;; (gnosis-dashboard-output-notes) - ;; (revert-buffer t t t))) - (local-set-key (kbd "a") #'gnosis-add-note))) (cl-defun gnosis-collect-note-ids (&key (tags nil) (due nil) (deck nil)) "Return list of note ids based on TAGS, DUE, DECKS. @@ -1638,6 +1607,33 @@ DECK: boolean value, t to specify notes from deck." ((and (null tags) due deck) (gnosis-get-deck-notes nil t)))) +(defun gnosis-dashboard-output-notes (note-ids) + "Return NOTE-IDS contents on gnosis dashboard." + (cl-assert (listp note-ids) t "`note-ids' must be a list of note ids.") + (setf tabulated-list-format [("Main" 30 t) + ("Options" 20 t) + ("Answer" 25 t) + ("Tags" 25 t) + ("Type" 10 t) + ("Suspend" 2 t)] + tabulated-list-entries (cl-loop for id in note-ids + for output = (gnosis-dashboard-output-note id) + when output + collect (list (number-to-string id) (vconcat output))) + gnosis-dashboard-note-ids note-ids) + (tabulated-list-init-header) + ;; Keybindings, for editing, suspending, deleting notes. + ;; We use `local-set-key' to bind keys to the buffer to avoid + ;; conflicts when using the dashboard for displaying either notes + ;; or decks. + (local-set-key (kbd "e") #'gnosis-dashboard-edit-note) + (local-set-key (kbd "s") #'(lambda () (interactive) + (gnosis-suspend-note + (string-to-number (tabulated-list-get-id))) + (gnosis-dashboard-output-notes) + (revert-buffer t t t))) + (local-set-key (kbd "a") #'gnosis-add-note) + (local-set-key (kbd "r") #'gnosis-dashboard)) (defun gnosis-dashboard-deck-note-count (id) "Return total note count for deck with ID." -- cgit v1.2.3 From a3a77db05280e5bd80cf7b28cf5a75eaacbfe729 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:18:25 +0300 Subject: Add gnosis-dashboard-note-ids Store value of note-ids for dashboard on a global variable. --- gnosis.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gnosis.el b/gnosis.el index 7cbf968..08523ba 100644 --- a/gnosis.el +++ b/gnosis.el @@ -119,6 +119,9 @@ When nil, the image will be displayed at its original size." (defvar gnosis-testing nil "When t, warn user he is in a testing environment.") +(defvar gnosis-dashboard-note-ids nil + "Store note ids for dashboard.") + (defconst gnosis-db-version 2 "Gnosis database version.") -- cgit v1.2.3 From 9e679fe36adda32978ae0aaf15e41afbca024be4 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:19:11 +0300 Subject: gnosis-dashboard-edit-note: Add dashboard as arg Specify as arg dashboard to return to after editing. --- gnosis.el | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/gnosis.el b/gnosis.el index 08523ba..28a7b20 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1680,17 +1680,15 @@ DECK: boolean value, t to specify notes from deck." (string-to-number (tabulated-list-get-id))) (gnosis-dashboard-output-decks) (revert-buffer t t t)))) -;; (local-set-key (kbd "d") #'(lambda () (interactive) -;; (gnosis-delete-deck -;; (string-to-number (tabulated-list-get-id))) -;; (gnosis-dashboard-output-decks) -;; (revert-buffer t t t)))) - -(defun gnosis-dashboard-edit-note () - "Get note id from tabulated list and edit it." + +(defun gnosis-dashboard-edit-note (&optional dashboard) + "Get note id from tabulated list and edit it. + +DASHBOARD: Dashboard to return to after editing." (interactive) - (let ((id (tabulated-list-get-id))) - (gnosis-edit-note (string-to-number id)) + (let ((id (tabulated-list-get-id)) + (dashboard (or dashboard "Notes"))) + (gnosis-edit-note (string-to-number id) nil dashboard) (message "Editing note with id: %s" id))) (defun gnosis-dashboard-edit-deck () -- cgit v1.2.3 From 9b079a48eeda16d29eb937e2dd4905a20ec0ec42 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:19:54 +0300 Subject: gnosis-dashboard: Add note-ids argument --- gnosis.el | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/gnosis.el b/gnosis.el index 28a7b20..3c627a8 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1709,22 +1709,26 @@ DASHBOARD: Dashboard to return to after editing." tabulated-list-sort-key nil)) ;;;###autoload -(cl-defun gnosis-dashboard (&optional dashboard-type) +(cl-defun gnosis-dashboard (&optional dashboard-type (note-ids nil)) "Display gnosis dashboard. +NOTE-IDS: List of note ids to display on dashboard. When nil, prompt +for dashboard type. + DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (interactive) - (let ((type (or dashboard-type - (cadr (read-multiple-choice - "Display dashboard for:" - '((?N "Notes") - (?D "Decks"))))))) - (pop-to-buffer "*gnosis-dashboard*") - (gnosis-dashboard-mode) - (pcase type - ("Notes" (gnosis-dashboard-output-notes)) - ("Decks" (gnosis-dashboard-output-decks))) - (tabulated-list-print t))) + (pop-to-buffer "*gnosis-dashboard*") + (gnosis-dashboard-mode) + (if note-ids (gnosis-dashboard-output-notes note-ids) + (pcase (or dashboard-type (cadr (read-multiple-choice + "Display dashboard for:" + '((?N "Notes") + (?D "Decks") + (?T "Tags"))))) + ("Notes" (gnosis-dashboard-output-notes (gnosis-collect-note-ids))) + ("Decks" (gnosis-dashboard-output-decks)) + ("Tags" (gnosis-dashboard-output-notes (gnosis-collect-note-ids :tags t))))) + (tabulated-list-print t)) (defun gnosis-db-init () "Create gnosis essential directories & database." -- cgit v1.2.3 From 40c5859332ac0a413ccaf3d074cf592148a034c4 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:27:01 +0300 Subject: gnosis-review: Use gnosis-collect-note-ids --- gnosis.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gnosis.el b/gnosis.el index 3c627a8..fed4b0e 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1513,11 +1513,10 @@ to improve readability." "Due notes of specified tag(s)" "All notes of tag(s)")))) (pcase review-type - ("Due notes" (gnosis-review--session (gnosis-review-get-due-notes))) - ("Due notes of deck" (gnosis-review--session (gnosis-get-deck-notes nil t))) - ("Due notes of specified tag(s)" (gnosis-review--session - (gnosis-select-by-tag (gnosis-tag-prompt :due t)))) - ("All notes of tag(s)" (gnosis-review--session (gnosis-select-by-tag (gnosis-tag-prompt))))))) + ("Due notes" (gnosis-review--session (gnosis-collect-note-ids :due t))) + ("Due notes of deck" (gnosis-review--session (gnosis-collect-note-ids :due t :deck t))) + ("Due notes of specified tag(s)" (gnosis-review--session (gnosis-collect-note-ids :due t :tags t))) + ("All notes of tag(s)" (gnosis-review--session (gnosis-collect-note-ids :tags t)))))) ;;; Database Schemas (defvar gnosis-db-schema-decks '([(id integer :primary-key :autoincrement) -- cgit v1.2.3 From 336bef91edcd233106c9922c9aca7c4ca27966f5 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:27:29 +0300 Subject: gnosis-tag-prompt: Use error for "No due notes" --- gnosis.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index fed4b0e..757be50 100644 --- a/gnosis.el +++ b/gnosis.el @@ -931,7 +931,7 @@ MATCH: Require match, t or nil value DUE: if t, return tags for due notes from `gnosis-due-tags'." (let ((tags '())) (cond ((and due (null (gnosis-review-get-due-notes))) - (message "No due notes.")) + (error "No due notes")) (t (cl-loop for tag = (completing-read (concat prompt (format " (%s) (q for quit): " (mapconcat #'identity tags " "))) (cons "q" (if due (gnosis-review-get-due-tags) -- cgit v1.2.3 From 379530d8603fa1811fbbc28af2fa221dab58fd40 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:28:04 +0300 Subject: gnosis-edit-note: Return to gnosis-dashboard-note-ids --- gnosis.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index 757be50..6c3ac3c 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1281,7 +1281,8 @@ changes." (local-unset-key (kbd "C-c C-c")) (local-set-key (kbd "C-c C-c") (lambda () (interactive) (if recursive-edit (gnosis-edit-save-exit 'exit-recursive-edit) - (gnosis-edit-save-exit 'gnosis-dashboard dashboard))))) + (gnosis-edit-save-exit 'gnosis-dashboard dashboard + gnosis-dashboard-note-ids))))) (defun gnosis-edit-deck--export (id) "Export deck with ID. -- cgit v1.2.3 From 3437ba1bbefda8fec367e419b48575b7b755584d Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:28:44 +0300 Subject: gnosis-dashboard-output-note: style --- gnosis.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index 6c3ac3c..fc229b1 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1581,7 +1581,7 @@ to improve readability." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) (gnosis-select 'suspend 'review-log `(= id ,id) t)) if (listp item) - collect (mapconcat #'identity item ", ") + collect (mapconcat #'identity item ",") else collect (prin1-to-string item))) -- cgit v1.2.3 From a04b52c46b1fea99464196db47fdbfd10cc056d3 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 19:29:03 +0300 Subject: gnosis-edit-note: Update docstring --- gnosis.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gnosis.el b/gnosis.el index fc229b1..e26532a 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1262,6 +1262,9 @@ RECURSIVE-EDIT: If t, exit `recursive-edit' after finishing editing. It should only be t when starting a recursive edit, when editing a note during a review session. +DASHBOARD: Dashboard to return after editing. Default value is +Notes. + The buffer automatically indents the expressions for readability. After finishing editing, evaluate the entire expression to apply the changes." -- cgit v1.2.3 From fb5c9178619cc6f33ac2dee3c5be8bef611a9106 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 3 Apr 2024 07:58:39 +0300 Subject: Update TODOs --- TODO.org | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/TODO.org b/TODO.org index 79c2324..65bb50a 100644 --- a/TODO.org +++ b/TODO.org @@ -4,7 +4,9 @@ * Notes -** TODO Add export deck +** TODO Add export deck :priorityLow: +** TODO Add support for org-mode +Create gnosis notes using =org-mode= * Dashboard ** DONE Add Dashboard CLOSED: [2024-02-20 Tue 13:33] @@ -14,36 +16,28 @@ CLOSED: [2024-02-20 Tue 13:33] + emacsql is quite fast, but the current tabulated-list implementation can be quite slow when having >30K notes. This should be improved upon in the feature ** TODO Dashboard: Add filtering/search -Search by tags, deck or LIKE question. - -* Algorithm -** TODO Algorithm: changes for ef increase/decrease values :priorityHigh: -+ Create a =gnosis-algorithm-ef-increase=, which will be used to - increase ef increase value upon X consecutive successful reviews +- [x] Search using tags +- [] Search/Filter for main/answer * Misc -** TODO Add export deck :priorityHigh: ** DONE Refactor =completing-read= UI choices CLOSED: [2024-02-17 Sat 21:59] /DONE on version 0.1.7/ -=completing-read= is not an ideal solution as a UI. If user has not +=completing-read= is not an ideal solution as a UI. If user has not enabled a completion system, such as vertico, this would make gnosis unusable. One possible solution is to create defcustom =gnosis-completing-read-function= that has ido-completing-read by default if vertico/ivy/helm is not enabled - *** Notes Implemented =gnosis-completing-read-function= -** TODO Use vc instead to stage & commit :priorityLow: -** DONE Use vc instead git shell commands to push/pull -CLOSED: [2024-02-17 Sat 21:59] -/DONE on version 0.1.7/ +** TODO Use vc instead of shell commands :priorityLow: +- [x] Push & Pull commands /DONE on version 0.1.7/ +- [] stage & commit -Implemented =gnosis-git-*= functions to handle git commands. -- cgit v1.2.3 From 11b15d260b55603de73eb03f9a4d292dc2fc3ce2 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 3 Apr 2024 08:00:25 +0300 Subject: dashboard: Refactor user interaction - Use lowercase - Prompt for gnosis-dashboard-type before switching to buffer --- gnosis.el | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/gnosis.el b/gnosis.el index e26532a..5f3648b 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1247,7 +1247,7 @@ NOTES: List of note ids" (put-text-property (match-beginning 0) (match-end 0) 'read-only t))) (goto-char (point-min))) -(cl-defun gnosis-edit-note (id &optional (recursive-edit nil) (dashboard "Notes")) +(cl-defun gnosis-edit-note (id &optional (recursive-edit nil) (dashboard "notes")) "Edit the contents of a note with the given ID. This function creates an Emacs Lisp buffer named *gnosis-edit* on the @@ -1372,7 +1372,7 @@ INITIAL-INTERVAL: Initial interval for notes of deck" (gnosis-edit-read-only-values (format ":id %s" id) ":name" ":ef-increase" ":ef-decrease" ":ef-threshold" ":failure-factor") (local-unset-key (kbd "C-c C-c")) - (local-set-key (kbd "C-c C-c") (lambda () (interactive) (gnosis-edit-save-exit 'gnosis-dashboard "Decks"))))) + (local-set-key (kbd "C-c C-c") (lambda () (interactive) (gnosis-edit-save-exit 'gnosis-dashboard "decks"))))) (cl-defun gnosis-edit-save-exit (&optional exit-func &rest args) "Save edits and exit using EXIT-FUNC, with ARGS." @@ -1690,7 +1690,7 @@ DECK: boolean value, t to specify notes from deck." DASHBOARD: Dashboard to return to after editing." (interactive) (let ((id (tabulated-list-get-id)) - (dashboard (or dashboard "Notes"))) + (dashboard (or dashboard "notes"))) (gnosis-edit-note (string-to-number id) nil dashboard) (message "Editing note with id: %s" id))) @@ -1720,18 +1720,19 @@ for dashboard type. DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (interactive) - (pop-to-buffer "*gnosis-dashboard*") - (gnosis-dashboard-mode) - (if note-ids (gnosis-dashboard-output-notes note-ids) - (pcase (or dashboard-type (cadr (read-multiple-choice - "Display dashboard for:" - '((?N "Notes") - (?D "Decks") - (?T "Tags"))))) - ("Notes" (gnosis-dashboard-output-notes (gnosis-collect-note-ids))) - ("Decks" (gnosis-dashboard-output-decks)) - ("Tags" (gnosis-dashboard-output-notes (gnosis-collect-note-ids :tags t))))) - (tabulated-list-print t)) + (let ((dashboard-type (or dashboard-type (cadr (read-multiple-choice + "Display dashboard for:" + '((?n "notes") + (?d "decks") + (?t "tags"))))))) + (pop-to-buffer "*gnosis-dashboard*") + (gnosis-dashboard-mode) + (if note-ids (gnosis-dashboard-output-notes note-ids) + (pcase dashboard-type + ("notes" (gnosis-dashboard-output-notes (gnosis-collect-note-ids))) + ("decks" (gnosis-dashboard-output-decks)) + ("tags" (gnosis-dashboard-output-notes (gnosis-collect-note-ids :tags t))))) + (tabulated-list-print t))) (defun gnosis-db-init () "Create gnosis essential directories & database." -- cgit v1.2.3 From 4afb569b3c328b7b445a8eb50fce71c8d4833ed0 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 10 Apr 2024 23:16:44 +0300 Subject: [fix] gnosis-display-image: Adjust for empty strings --- gnosis.el | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/gnosis.el b/gnosis.el index 5f3648b..5a3bb0c 100644 --- a/gnosis.el +++ b/gnosis.el @@ -373,19 +373,18 @@ If FALSE t, use gnosis-face-false face" "Display image for note ID. IMAGE is the image type to display, usually should be either `images' -or `extra-image'. Instead of using `extra-image' on review use -`gnosis-display-extra' +or `extra-image'. Instead of using `extra-image' post review, prefer +`gnosis-display-extra' which displays the `extra-image' as well. -`images' is the image to display before user-input, while -`extra-image' is the image to display after user-input. - -Refer to `gnosis-db-schema-extras' for more." +Refer to `gnosis-db-schema-extras' for informations on images stored." (let* ((img (gnosis-get image 'extras `(= id ,id))) (path-to-image (expand-file-name (or img "") (file-name-as-directory gnosis-images-dir))) (image (create-image path-to-image 'png nil :width gnosis-image-width :height gnosis-image-height))) - (when img - (insert "\n\n") - (insert-image image)))) + (cond ((and img (file-exists-p path-to-image)) + (insert "\n\n") + (insert-image image)) + ((or (not img) (string-empty-p img)) + (insert "\n\n"))))) (defun gnosis-display-extra (id) "Display extra information & extra-image for note ID." -- cgit v1.2.3 From 34bf6748f05551430352a712c05cf74980febc8a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 10 Apr 2024 23:22:09 +0300 Subject: [Feature] Add override - Override review result - gnosis-review--update will be used only on gnosis-review--sesion. - gnosis-review-TYPE functions should return t or nil, for success or failure of review. --- gnosis.el | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/gnosis.el b/gnosis.el index 5a3bb0c..e08e93a 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1220,20 +1220,23 @@ NOTES: List of note ids" (message "No notes for review.") (when (y-or-n-p (format "You have %s total notes for review, start session?" (length notes))) (cl-loop for note in notes - do (gnosis-review-note note) - (setf note-count (1+ note-count)) - (pcase (car (read-multiple-choice - "Note actions" - '((?n "next") - (?s "suspend") - (?e "edit") - (?q "quit")))) - (?n nil) - (?s (gnosis-suspend-note note)) - (?e (gnosis-edit-note note t) - (recursive-edit)) - (?q (gnosis-review-commit note-count) - (cl-return))) + do (let ((success (gnosis-review-note note))) + (setf note-count (1+ note-count)) + (pcase (car (read-multiple-choice + "Note actions" + '((?n "next") + (?o "override") + (?s "suspend") + (?e "edit") + (?q "quit")))) + (?n (gnosis-review--update note success) (sit-for 10)) + (?o (gnosis-review--update note (if success nil t))) + (?s (gnosis-suspend-note note)) + (?e (gnosis-review--update note success) + (gnosis-edit-note note t) + (recursive-edit)) + (?q (gnosis-review-commit note-count) + (cl-return)))) finally (gnosis-review-commit note-count)))))) -- cgit v1.2.3 From 5040245c0069f400dcfe54bbcfd2a72550bed760 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 10 Apr 2024 23:34:39 +0300 Subject: gnosis-display-next-review: Get value using gnosis-algorithm Since we will be displaying next date before we use gnosis-review--update, we will have to calculate the next date before we update note value in db. --- gnosis.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnosis.el b/gnosis.el index e08e93a..6564ba7 100644 --- a/gnosis.el +++ b/gnosis.el @@ -416,9 +416,9 @@ Also see `gnosis-string-edit'." (recursive-edit) string) -(defun gnosis-display-next-review (id) - "Display next interval for note ID." - (let ((interval (gnosis-get 'next-rev 'review-log `(= id ,id)))) +(defun gnosis-display-next-review (id success) + "Display next interval of note ID for SUCCESS." + (let ((interval (car (gnosis-review-algorithm id success)))) (goto-char (point-max)) (insert "\n\n" (propertize "Next review:" 'face 'gnosis-face-directions) -- cgit v1.2.3 From a2e4893a5c78a4c49db0b967f73c678cadf08369 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 10 Apr 2024 23:35:56 +0300 Subject: review: All review functions return success value - Review functions return a boolean value for success. This way it can be overriden. --- gnosis.el | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/gnosis.el b/gnosis.el index 6564ba7..a29ca1f 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1078,16 +1078,12 @@ SUCCESS is a boolean value, t for success, nil for failure." (gnosis-display-mcq-options id)) (let* ((choices (gnosis-get 'options 'notes `(= id ,id))) (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 t) - (message "Correct!")) - (gnosis-review--update id nil) - (message "False")) + (user-choice (gnosis-mcq-answer id)) + (success (string= answer user-choice))) (gnosis-display-correct-answer-mcq answer user-choice) (gnosis-display-extra id) - (gnosis-display-next-review id))) + (gnosis-display-next-review id success) + success)) (defun gnosis-review-basic (id) "Review basic type note for ID." @@ -1099,8 +1095,8 @@ SUCCESS is a boolean value, t for success, nil for failure." (success (gnosis-compare-strings answer user-input))) (gnosis-display-basic-answer answer success user-input) (gnosis-display-extra id) - (gnosis-review--update id success) - (gnosis-display-next-review id))) + (gnosis-display-next-review id success) + success)) (defun gnosis-review-y-or-n (id) "Review y-or-n type note for ID." @@ -1112,8 +1108,8 @@ SUCCESS is a boolean value, t for success, nil for failure." (success (equal answer user-input))) (gnosis-display-y-or-n-answer :answer answer :success success) (gnosis-display-extra id) - (gnosis-review--update id success) - (gnosis-display-next-review id))) + (gnosis-display-next-review id success) + success)) (defun gnosis-review-cloze--input (cloze) "Prompt for user input during cloze review. @@ -1134,7 +1130,8 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." (let* ((main (gnosis-get 'main 'notes `(= id ,id))) (clozes (gnosis-get 'answer 'notes `(= id ,id))) (num 1) ;; Number of clozes revealed - (hint (gnosis-get 'options 'notes `(= id ,id)))) + (hint (gnosis-get 'options 'notes `(= id ,id))) + (success nil)) (gnosis-display-cloze-sentence main clozes) (gnosis-display-image id) (gnosis-display-hint hint) @@ -1149,12 +1146,13 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." (gnosis-display-cloze-user-answer (cdr input)) ;; Reveal all clozes left with `gnosis-face-cloze-unanswered' face (gnosis-review-cloze-reveal-unaswered (nthcdr num clozes)) - (gnosis-review--update id nil) + (setf success nil) (cl-return))) ;; Update note after all clozes are revealed successfully - finally (gnosis-review--update id t))) - (gnosis-display-extra id) - (gnosis-display-next-review id)) + finally (setf success t)) + (gnosis-display-extra id) + (gnosis-display-next-review id success) + success)) (defun gnosis-review-note (id) "Start review for note with value of id ID, if note is unsuspended." @@ -1229,7 +1227,7 @@ NOTES: List of note ids" (?s "suspend") (?e "edit") (?q "quit")))) - (?n (gnosis-review--update note success) (sit-for 10)) + (?n (gnosis-review--update note success)) (?o (gnosis-review--update note (if success nil t))) (?s (gnosis-suspend-note note)) (?e (gnosis-review--update note success) -- cgit v1.2.3 From 2486661ba86dd02d3abe4dc7f92ab68b84602c86 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 11 Apr 2024 09:47:58 +0300 Subject: gnosis-display-next-review: Adjust for overrides --- gnosis.el | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gnosis.el b/gnosis.el index a29ca1f..3890ac5 100644 --- a/gnosis.el +++ b/gnosis.el @@ -418,12 +418,19 @@ Also see `gnosis-string-edit'." (defun gnosis-display-next-review (id success) "Display next interval of note ID for SUCCESS." - (let ((interval (car (gnosis-review-algorithm id success)))) - (goto-char (point-max)) - (insert "\n\n" - (propertize "Next review:" 'face 'gnosis-face-directions) - " " - (propertize (format "%s" interval) 'face 'gnosis-face-next-review)))) + (let* ((interval (car (gnosis-review-algorithm id success))) + (next-review-msg (format "\n\n%s %s" + (propertize "Next review:" 'face 'gnosis-face-directions) + (propertize (format "%s" interval) 'face 'gnosis-face-next-review)))) + (if (search-backward "Next review" nil t) + ;; Delete previous result, and override with new this should + ;; occur only when used with `gnosis-review-override' + (progn (delete-region (point) (progn (end-of-line) (point))) + (insert (propertize (replace-regexp-in-string "\n" "" next-review-msg) + 'face (if success 'gnosis-face-correct 'gnosis-face-false)))) + ;; Default behaviour + (goto-char (point-max)) + (insert next-review-msg)))) (cl-defun gnosis--prompt (prompt &optional (downcase nil) (split nil)) "PROMPT user for input until `q' is given. -- cgit v1.2.3 From 1340536669753f9a4953f738de0cfc1d190238bf Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 11 Apr 2024 09:48:19 +0300 Subject: Add gnosis-review-override Reverses the result of review --- gnosis.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index 3890ac5..1f3a7ae 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1216,6 +1216,16 @@ NOTE-NUM: The number of notes reviewed in the session." (gnosis-vc-push)) (message "Review session finished. %d notes reviewed." note-num))) +(defun gnosis-review-override (id success) + "Override review result of note ID. + +Reverse the result of review SUCCESS." + (let ((success-new (if success nil t))) + (gnosis-display-next-review id success-new) + (if (y-or-n-p (format "Override review result as %s?" (if success-new "`SUCCESS'" "`FAILURE'"))) + (gnosis-review--update id success-new) + (gnosis-review-override id success-new)))) + (defun gnosis-review--session (notes) "Start review session for NOTES. @@ -1235,7 +1245,7 @@ NOTES: List of note ids" (?e "edit") (?q "quit")))) (?n (gnosis-review--update note success)) - (?o (gnosis-review--update note (if success nil t))) + (?o (gnosis-review-override note success)) (?s (gnosis-suspend-note note)) (?e (gnosis-review--update note success) (gnosis-edit-note note t) -- cgit v1.2.3 From 30cdfb69884b002c8523b0ae0025b53fbd41752f Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 11 Apr 2024 10:27:20 +0300 Subject: dashboard: Adjust for output buffer - gnosis-dashboard-output-decks & notes functions are the ones that should pop to a new buffer. - gnosis-dashboard should only handle note-id collection --- gnosis.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gnosis.el b/gnosis.el index 1f3a7ae..ad85899 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1633,6 +1633,8 @@ DECK: boolean value, t to specify notes from deck." (defun gnosis-dashboard-output-notes (note-ids) "Return NOTE-IDS contents on gnosis dashboard." (cl-assert (listp note-ids) t "`note-ids' must be a list of note ids.") + (pop-to-buffer "*gnosis-dashboard*") + (gnosis-dashboard-mode) (setf tabulated-list-format [("Main" 30 t) ("Options" 20 t) ("Answer" 25 t) @@ -1676,6 +1678,8 @@ DECK: boolean value, t to specify notes from deck." (defun gnosis-dashboard-output-decks () "Return deck contents for gnosis dashboard." + (pop-to-buffer "*gnosis-dashboard*") + (gnosis-dashboard-mode) (setq tabulated-list-format [("Name" 15 t) ("failure-factor" 15 t) ("ef-increase" 15 t) @@ -1742,8 +1746,6 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." '((?n "notes") (?d "decks") (?t "tags"))))))) - (pop-to-buffer "*gnosis-dashboard*") - (gnosis-dashboard-mode) (if note-ids (gnosis-dashboard-output-notes note-ids) (pcase dashboard-type ("notes" (gnosis-dashboard-output-notes (gnosis-collect-note-ids))) -- cgit v1.2.3 From 5fc8ba333ff08f3c4903e881e08288d87d7eb61e Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 11 Apr 2024 16:33:00 +0300 Subject: version bump: 0.2.2 --- gnosis.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnosis.el b/gnosis.el index ad85899..61b198a 100644 --- a/gnosis.el +++ b/gnosis.el @@ -5,7 +5,7 @@ ;; Author: Thanos Apollo ;; Keywords: extensions ;; URL: https://thanosapollo.org/projects/gnosis -;; Version: 0.2.1 +;; Version: 0.2.2 ;; Package-Requires: ((emacs "27.2") (emacsql "20240124") (compat "29.1.4.2")) -- cgit v1.2.3