From fad9f62ed903b8c272042c8c18e4265718fea602 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Mon, 22 Jul 2024 09:30:56 +0300 Subject: New module: Add gnosis-dashboard. * Encapsulate functionality of gnosis-dashboard into is own module. --- gnosis-dashboard.el | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 gnosis-dashboard.el (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el new file mode 100644 index 0000000..f03aa88 --- /dev/null +++ b/gnosis-dashboard.el @@ -0,0 +1,194 @@ +;;; gnosis-dashboard.el --- Spaced Repetition Algorithm for Gnosis -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Thanos Apollo + +;; Author: Thanos Apollo +;; Keywords: extensions +;; URL: https://git.thanosapollo.org/gnosis +;; Version: 0.0.1 + +;; Package-Requires: ((emacs "27.2") (compat "29.1.4.2")) + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; This an extension of gnosis.el + +;;; Code: +(require 'cl-lib) + +(declare-function gnosis-select "gnosis.el") +(declare-function gnosis-delete-note "gnosis.el") +(declare-function gnosis-suspend-note "gnosis.el") +(declare-function gnosis-collect-note-ids "gnosis.el") +(declare-function gnosis-edit-deck "gnosis.el") +(declare-function gnosis-edit-note "gnosis.el") +(declare-function gnosis-delete-deck "gnosis.el") +(declare-function gnosis-suspend-deck "gnosis.el") +(declare-function gnosis-add-deck "gnosis.el") +(declare-function gnosis-add-note "gnosis.el") + +(defvar gnosis-dashboard-note-ids nil + "Store note ids for dashboard.") + +(defun gnosis-dashboard-output-note (id) + "Output contents for note with ID, formatted for gnosis dashboard." + (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 ",") + else + collect (replace-regexp-in-string "\n" " " (format "%s" item)))) + +(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" ,(/ (window-width) 4) t) + ("Options" ,(/ (window-width) 6) t) + ("Answer" ,(/ (window-width) 6) t) + ("Tags" ,(/ (window-width) 5) t) + ("Type" ,(/ (window-width) 10) T) + ("Suspend" ,(/ (window-width) 6) 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 gnosis-dashboard-note-ids) + (revert-buffer t t t))) + (local-set-key (kbd "a") #'gnosis-add-note) + (local-set-key (kbd "r") #'gnosis-dashboard) + (local-set-key (kbd "d") #'(lambda () (interactive) + (gnosis-delete-note (string-to-number (tabulated-list-get-id))) + (gnosis-dashboard-output-notes gnosis-dashboard-note-ids) + (revert-buffer t t t))) + (local-unset-key (kbd "RET"))) + +(defun gnosis-dashboard-deck-note-count (id) + "Return total note count for deck with ID." + (let ((note-count (length (gnosis-select 'id 'notes `(= deck-id ,id) t)))) + (when (gnosis-select 'id 'decks `(= id ,id)) + (list (number-to-string note-count))))) + +(defun gnosis-dashboard-output-deck (id) + "Output contents from deck with ID, formatted for gnosis dashboard." + (cl-loop for item in (append (gnosis-select + '[name failure-factor ef-increase ef-decrease ef-threshold initial-interval] + 'decks `(= id ,id) t) + (mapcar 'string-to-number (gnosis-dashboard-deck-note-count id))) + when (listp item) + do (cl-remove-if (lambda (x) (and (vectorp x) (zerop (length x)))) item) + collect (format "%s" item))) + +(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) + ("ef-decrease" 15 t) + ("ef-threshold" 15 t) + ("Initial Interval" 20 t) + ("Total Notes" 10 t)]) + (tabulated-list-init-header) + (setq tabulated-list-entries + (cl-loop for id in (gnosis-select 'id 'decks '1=1 t) + for output = (gnosis-dashboard-output-deck id) + when output + collect (list (number-to-string id) (vconcat output)))) + (local-set-key (kbd "e") #'gnosis-dashboard-edit-deck) + (local-set-key (kbd "a") #'(lambda () "Add deck & refresh" (interactive) + (gnosis-add-deck (read-string "Deck name: ")) + (gnosis-dashboard-output-decks) + (revert-buffer t t t))) + (local-set-key (kbd "s") #'(lambda () "Suspend notes" (interactive) + (gnosis-suspend-deck + (string-to-number (tabulated-list-get-id))) + (gnosis-dashboard-output-decks) + (revert-buffer t t t))) + (local-set-key (kbd "d") #'(lambda () "Delete deck" (interactive) + (gnosis-delete-deck (string-to-number (tabulated-list-get-id))) + (gnosis-dashboard-output-decks) + (revert-buffer t t t))) + (local-set-key (kbd "RET") #'(lambda () "View notes of deck" (interactive) + (gnosis-dashboard "notes" + (gnosis-collect-note-ids + :deck (string-to-number (tabulated-list-get-id))))))) + +(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)) + (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 () + "Get deck id from tabulated list and edit it." + (interactive) + (let ((id (tabulated-list-get-id))) + (gnosis-edit-deck (string-to-number id)))) + +(defvar-keymap gnosis-dashboard-mode-map + :doc "gnosis-dashboard keymap" + "q" #'quit-window) + +(define-derived-mode gnosis-dashboard-mode tabulated-list-mode "Gnosis Dashboard" + "Major mode for displaying Gnosis dashboard." + :keymap gnosis-dashboard-mode-map + (setq tabulated-list-padding 2 + tabulated-list-sort-key nil)) + +;;;###autoload +(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 ((dashboard-type (or dashboard-type + (cadr (read-multiple-choice + "Display dashboard for:" + '((?n "notes") + (?d "decks") + (?t "tags") + (?s "search"))))))) + (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))) + ("search" (gnosis-dashboard-output-notes + (gnosis-collect-note-ids :query (read-string "Search for note: ")))))) + (tabulated-list-print t))) + + +(provide 'gnosis-dashboard) +;;; gnosis-dashboard.el ends here -- cgit v1.2.3 From 3394bcd0ea04e2655084c339269828e04ca008d8 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 16:58:56 +0300 Subject: dashboard: Update requirments & declarations. --- gnosis-dashboard.el | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index f03aa88..3e8c12e 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -28,6 +28,7 @@ ;;; Code: (require 'cl-lib) +(require 'calendar) (declare-function gnosis-select "gnosis.el") (declare-function gnosis-delete-note "gnosis.el") @@ -39,6 +40,11 @@ (declare-function gnosis-suspend-deck "gnosis.el") (declare-function gnosis-add-deck "gnosis.el") (declare-function gnosis-add-note "gnosis.el") +(declare-function gnosis-insert-separator "gnosis.el") +(declare-function gnosis-get-date-total-notes "gnosis.el") +(declare-function gnosis-center-string "gnosis.el") +(declare-function gnosis-get-date-new-notes "gnosis.el") +(declare-function gnosis-review-get-due-notes "gnosis.el") (defvar gnosis-dashboard-note-ids nil "Store note ids for dashboard.") -- cgit v1.2.3 From a017fc1b6e83d6585e8be0d60d7b1bc8189a1fd8 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 16:59:14 +0300 Subject: New variable: Add dashboard-search-value. * Hold query value for searching notes. --- gnosis-dashboard.el | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 3e8c12e..c88f919 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -49,6 +49,9 @@ (defvar gnosis-dashboard-note-ids nil "Store note ids for dashboard.") +(defvar gnosis-dashboard-search-value nil + "Store search value.") + (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) -- cgit v1.2.3 From c65a2b3fda5e3bf5b67f28c188e425e004c394f7 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 17:00:03 +0300 Subject: New variable: dashboard-header-face * Add face for dashboard header. --- gnosis-dashboard.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index c88f919..d1eb8fb 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -52,6 +52,10 @@ (defvar gnosis-dashboard-search-value nil "Store search value.") +(defface gnosis-dashboard-header-face + '((t :inherit (outline-1) :weight bold)) + "Face for the dashboard header.." + :group 'gnosis) (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) -- cgit v1.2.3 From feb8a4496b93b412c9f3d6197499127cdbc945fe Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 17:01:03 +0300 Subject: New function: dashboard-generate-dates. * Generate all possible dates for YEAR. --- gnosis-dashboard.el | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index d1eb8fb..c2279c2 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -56,6 +56,17 @@ '((t :inherit (outline-1) :weight bold)) "Face for the dashboard header.." :group 'gnosis) + +(defun gnosis-dashboard-generate-dates (&optional year) + "Return a list of all dates (year month day) for YEAR." + (let* ((current-year (or (decoded-time-year (decode-time)) year)) + (result '())) + (dotimes (month 12) + (let ((days-in-month (calendar-last-day-of-month (+ month 1) current-year))) + (dotimes (day days-in-month) + (push (list current-year (+ month 1) (+ day 1)) result)))) + (nreverse result))) + (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) -- cgit v1.2.3 From a6d7ef539ae3a289ab83c61cba5d1ff7c307b928 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 17:45:20 +0300 Subject: New function: dashboard-year-stats. * Return YEAR review stats. --- gnosis-dashboard.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index c2279c2..5089fd5 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -67,6 +67,37 @@ (push (list current-year (+ month 1) (+ day 1)) result)))) (nreverse result))) +(defun gnosis-dashboard-year-stats (&optional year) + "Return YEAR review stats." + (let ((notes nil)) + (cl-loop for date in (gnosis-dashboard-generate-dates (and year)) + do (setq notes (append notes (list (gnosis-get-date-total-notes date))))) + notes)) + +(defun gnosis-dashboard-month-reviews (month) + "Return reviewes for MONTH in current year." + (cl-assert (and (integerp month) + (< month 12)) + nil "Month must be an integer, lower than 12.") + (let* ((month-dates (cl-loop for date in (gnosis-dashboard-generate-dates) + if (and (= (nth 1 date) month) + (= (nth 0 date) (decoded-time-year (decode-time)))) + collect date)) + (month-reviews (cl-loop for date in month-dates + collect (gnosis-get-date-total-notes date)))) + month-reviews)) + +;; TODO: Optionally, add dates where no review was made. +(defun gnosis-dashboard-output-average-rev () + "Output the average daily notes reviewed for current year. + +Skips days where no note was reviewed." + (let ((total 0) + (entries (gnosis-dashboard-year-stats))) + (cl-loop for entry in entries + do (setq total (+ total entry))) + (/ total (length (remove 0 entries))))) + (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) -- cgit v1.2.3 From 09b600b75ad94b82bedc73262797fa88efac4be0 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 17:57:36 +0300 Subject: New function: gnosis-dashboard--graph-propertize. * Propertize STRING depending on the NUM of reviews. --- gnosis-dashboard.el | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 5089fd5..35dbdfe 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -98,6 +98,13 @@ Skips days where no note was reviewed." do (setq total (+ total entry))) (/ total (length (remove 0 entries))))) +;; TODO: Add more conds & faces +(defun gnosis-dashboard--graph-propertize (string num) + "Propertize STRING depending on the NUM of reviews." + (cond ((= num 0) + (propertize string 'face 'shadow)) + ((> num 0) + (propertize string 'face 'font-lock-constant-face)))) (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) -- cgit v1.2.3 From 2afc62757d40b3420bf3ff0cda34d7fc9324c35e Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 17:58:16 +0300 Subject: New function: dashboard-reviews-graph * Create a github-like heatmap for month DATES. This is still under review! --- gnosis-dashboard.el | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 35dbdfe..d42b759 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -105,6 +105,29 @@ Skips days where no note was reviewed." (propertize string 'face 'shadow)) ((> num 0) (propertize string 'face 'font-lock-constant-face)))) + +(defun gnosis-dashboard-reviews-graph (dates &optional remove-spaces) + "Insert graph for month DATES. + +Optionally, use REMOVE-SPACES when using multiple months." + (let ((count 0) + (insert-column (current-column))) + (cl-loop for day in dates + when (= count 0) + do (let ((current-column (current-column))) + (and (< (move-to-column insert-column) insert-column) + ;; TODO: Rewrite this! + (insert (make-string (- (- insert-column current-column) remove-spaces) ?\s)))) + (insert " ") + do (end-of-line) + (insert (gnosis-dashboard--graph-propertize (format "[%s] " (if (= day 0) "-" "x")) day)) + (cl-incf count) + when (= count 7) + do (setq count 0) + (end-of-line) + (when (and (/= (forward-line 1) 0) (eobp)) + (insert "\n") + (forward-line 0))))) (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) -- cgit v1.2.3 From 383fef6289d74ad819976b4ba18ce820bcf71ce7 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 17:59:26 +0300 Subject: New function: dashboard-month-overview. * Add 3 month overview. This is currently used for testing purposes. --- gnosis-dashboard.el | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index d42b759..4569ac7 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -128,6 +128,17 @@ Optionally, use REMOVE-SPACES when using multiple months." (when (and (/= (forward-line 1) 0) (eobp)) (insert "\n") (forward-line 0))))) +;; TODO: Refactor this! +(defun gnosis-dashboard-month-overview () + "Insert the 3 month overview." + (let ((point (point))) + (gnosis-dashboard-reviews-graph (gnosis-dashboard-month-reviews 7) 0) + (goto-char point) + (end-of-line) + (gnosis-dashboard-reviews-graph (gnosis-dashboard-month-reviews 8) 15) + (goto-char point) + (end-of-line) + (gnosis-dashboard-reviews-graph (gnosis-dashboard-month-reviews 9) 46))) (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) -- cgit v1.2.3 From 2f90fc6d6471697ed3750ed3f1941e7c2607e06e Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 18:00:37 +0300 Subject: New function: dashboard-test. * This function is meant to replace the current dashboard implementation, combined with a transient buffer. --- gnosis-dashboard.el | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 4569ac7..b664e6d 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -139,6 +139,48 @@ Optionally, use REMOVE-SPACES when using multiple months." (goto-char point) (end-of-line) (gnosis-dashboard-reviews-graph (gnosis-dashboard-month-reviews 9) 46))) + +;; TODO: Create a dashboard utilizing widgets +(defun gnosis-dashboard-test () + "Test function to create an editable field and a search button." + (interactive) + (let ((buffer-name "*Gnosis Dashboard*")) + (when (get-buffer buffer-name) + (kill-buffer buffer-name)) ;; Kill the existing buffer if it exists + (let ((buffer (get-buffer-create buffer-name))) + (with-current-buffer buffer + (widget-insert "\n" + (gnosis-center-string + (format "%s" (propertize "Gnosis Dashboard" 'face 'gnosis-dashboard-header-face)))) + (gnosis-insert-separator) + (widget-insert (gnosis-center-string (propertize "Stats:" 'face 'outline-3)) "\n") + (widget-insert (gnosis-center-string + (format "Reviewed today: %s | New: %s" + (propertize + (number-to-string (gnosis-get-date-total-notes)) + 'face + 'font-lock-variable-use-face) + (propertize + (number-to-string (gnosis-get-date-new-notes)) + 'face + 'font-lock-keyword-face)))) + (insert "\n") + (widget-insert (gnosis-center-string + (format "Daily Average: %s" + (propertize (number-to-string (gnosis-dashboard-output-average-rev)) + 'face 'font-lock-type-face)))) + (insert "\n") + (widget-insert (gnosis-center-string + (format "Due notes: %s" + (propertize + (number-to-string (length (gnosis-review-get-due-notes))) + 'face 'error)))) + (insert "\n\n") + (gnosis-dashboard-month-overview) + (use-local-map widget-keymap) + (widget-setup)) + (pop-to-buffer-same-window buffer)))) + (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) -- cgit v1.2.3 From 28ca5681a5ef0ac0c6e3453672461450ba758043 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 23 Jul 2024 18:01:14 +0300 Subject: dashboard: Create buffer on the same window. * Create dashboard on the same window instead of popping to a new one. "Popping" to a new window would mess up centering of strings on the main dashboard buffer. --- gnosis-dashboard.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index b664e6d..c89f4ea 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -193,7 +193,7 @@ Optionally, use REMOVE-SPACES when using multiple months." (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*") + (pop-to-buffer-same-window "*gnosis-dashboard*") (gnosis-dashboard-mode) (setf tabulated-list-format `[("Main" ,(/ (window-width) 4) t) ("Options" ,(/ (window-width) 6) t) @@ -242,7 +242,7 @@ Optionally, use REMOVE-SPACES when using multiple months." (defun gnosis-dashboard-output-decks () "Return deck contents for gnosis dashboard." - (pop-to-buffer "*gnosis-dashboard*") + (pop-to-buffer-same-window "*gnosis-dashboard*") (gnosis-dashboard-mode) (setq tabulated-list-format [("Name" 15 t) ("failure-factor" 15 t) -- cgit v1.2.3 From 0448bf120425c5f4822da46c27f446b475fd1bf1 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 24 Jul 2024 09:37:34 +0300 Subject: New variable: dashboard-months. * Number of additional months to display on dashboard. --- gnosis-dashboard.el | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index c89f4ea..103d36b 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -46,6 +46,11 @@ (declare-function gnosis-get-date-new-notes "gnosis.el") (declare-function gnosis-review-get-due-notes "gnosis.el") +(defcustom gnosis-dashboard-months 2 + "Number of additional months to display on dashboard." + :type 'integer + :group 'gnosis) + (defvar gnosis-dashboard-note-ids nil "Store note ids for dashboard.") -- cgit v1.2.3 From e44a7a4cf9d55779b80b4f9d5d0e15466d9fa2fd Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 24 Jul 2024 09:38:37 +0300 Subject: New function: dashboard--add-padding * Add padding for str-length. This is meant to be used with displaying month graphs --- gnosis-dashboard.el | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 103d36b..a25fe81 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -112,6 +112,12 @@ Skips days where no note was reviewed." (propertize string 'face 'font-lock-constant-face)))) (defun gnosis-dashboard-reviews-graph (dates &optional remove-spaces) +(defun gnosis-dashboard--add-padding (str-length) + "Add padding for STR-LENGTH." + (let ((padding (/ (- (window-width) str-length) 2))) + (make-string padding ?\s))) + +(defun gnosis-dashboard-reviews-graph (dates &optional ) "Insert graph for month DATES. Optionally, use REMOVE-SPACES when using multiple months." -- cgit v1.2.3 From af0b66f969da463dfd2b72c7393266f33b4c74c9 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 24 Jul 2024 09:39:18 +0300 Subject: Rewrite dashbaord month graphs --- gnosis-dashboard.el | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index a25fe81..06f345d 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -111,7 +111,6 @@ Skips days where no note was reviewed." ((> num 0) (propertize string 'face 'font-lock-constant-face)))) -(defun gnosis-dashboard-reviews-graph (dates &optional remove-spaces) (defun gnosis-dashboard--add-padding (str-length) "Add padding for STR-LENGTH." (let ((padding (/ (- (window-width) str-length) 2))) @@ -120,36 +119,46 @@ Skips days where no note was reviewed." (defun gnosis-dashboard-reviews-graph (dates &optional ) "Insert graph for month DATES. -Optionally, use REMOVE-SPACES when using multiple months." +Optionally, use when using multiple months." (let ((count 0) - (insert-column (current-column))) + (row 0) + (start-column (current-column)) + (end-column nil)) (cl-loop for day in dates when (= count 0) do (let ((current-column (current-column))) - (and (< (move-to-column insert-column) insert-column) - ;; TODO: Rewrite this! - (insert (make-string (- (- insert-column current-column) remove-spaces) ?\s)))) - (insert " ") + (and (< (move-to-column start-column) start-column) + ;; Add spaces to reach start-column. + (insert (make-string (- start-column current-column) ?\s)))) + (insert " |") do (end-of-line) (insert (gnosis-dashboard--graph-propertize (format "[%s] " (if (= day 0) "-" "x")) day)) (cl-incf count) when (= count 7) - do (setq count 0) + do + (setq end-column (current-column)) + (setq count 0) + (insert "|") + (cl-incf row) (end-of-line) (when (and (/= (forward-line 1) 0) (eobp)) (insert "\n") - (forward-line 0))))) + (forward-line 0))) + (insert (make-string (- end-column (current-column)) ?\s)) + (insert "|"))) ;; TODO: Refactor this! -(defun gnosis-dashboard-month-overview () - "Insert the 3 month overview." - (let ((point (point))) - (gnosis-dashboard-reviews-graph (gnosis-dashboard-month-reviews 7) 0) - (goto-char point) - (end-of-line) - (gnosis-dashboard-reviews-graph (gnosis-dashboard-month-reviews 8) 15) - (goto-char point) - (end-of-line) - (gnosis-dashboard-reviews-graph (gnosis-dashboard-month-reviews 9) 46))) +(defun gnosis-dashboard-month-overview (&optional num) + "Insert review graph for MONTHS." + (gnosis-insert-separator) + (let* ((point (point)) + (month (car (calendar-current-date)))) + (insert (gnosis-dashboard--add-padding (min (* (max num 1) 50) (window-width)))) + (while (<= month (+ (car (calendar-current-date)) num)) + ;; (insert (format "%d" month)) + (gnosis-dashboard-reviews-graph (gnosis-dashboard-month-reviews month)) + (goto-char point) + (end-of-line) + (cl-incf month)))) ;; TODO: Create a dashboard utilizing widgets (defun gnosis-dashboard-test () @@ -187,10 +196,11 @@ Optionally, use REMOVE-SPACES when using multiple months." (number-to-string (length (gnosis-review-get-due-notes))) 'face 'error)))) (insert "\n\n") - (gnosis-dashboard-month-overview) + (gnosis-dashboard-month-overview (or gnosis-dashboard-months 0)) (use-local-map widget-keymap) (widget-setup)) - (pop-to-buffer-same-window buffer)))) + (pop-to-buffer-same-window buffer) + (goto-char (point-min))))) (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." -- cgit v1.2.3 From 90294708f33a3ef08f67f43ed0d8cc7950dea07a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 24 Jul 2024 14:20:53 +0300 Subject: dashboard-reviews-graph: Remove separators. * Using | as separators is not aesthetically pleaseing. --- gnosis-dashboard.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 06f345d..d0bb93c 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -130,7 +130,7 @@ Optionally, use when using multiple months." (and (< (move-to-column start-column) start-column) ;; Add spaces to reach start-column. (insert (make-string (- start-column current-column) ?\s)))) - (insert " |") + (insert " ") do (end-of-line) (insert (gnosis-dashboard--graph-propertize (format "[%s] " (if (= day 0) "-" "x")) day)) (cl-incf count) @@ -138,14 +138,14 @@ Optionally, use when using multiple months." do (setq end-column (current-column)) (setq count 0) - (insert "|") + (insert " ") (cl-incf row) (end-of-line) (when (and (/= (forward-line 1) 0) (eobp)) (insert "\n") (forward-line 0))) (insert (make-string (- end-column (current-column)) ?\s)) - (insert "|"))) + (insert " "))) ;; TODO: Refactor this! (defun gnosis-dashboard-month-overview (&optional num) "Insert review graph for MONTHS." -- cgit v1.2.3 From 3a0323e91d9e720e3802c9bf864f0ac6f57c6e1f Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 24 Jul 2024 14:23:17 +0300 Subject: dashboard: Rewrite & add transient. * Rewrite gnosis-dashboard as to be an actual dashboard. * Add transient for interactions. --- gnosis-dashboard.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index d0bb93c..96d4ffe 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -161,7 +161,7 @@ Optionally, use when using multiple months." (cl-incf month)))) ;; TODO: Create a dashboard utilizing widgets -(defun gnosis-dashboard-test () +(defun gnosis-dashboard () "Test function to create an editable field and a search button." (interactive) (let ((buffer-name "*Gnosis Dashboard*")) @@ -200,7 +200,8 @@ Optionally, use when using multiple months." (use-local-map widget-keymap) (widget-setup)) (pop-to-buffer-same-window buffer) - (goto-char (point-min))))) + (goto-char (point-min)) + (gnosis-dashboard-transient)))) (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." @@ -324,7 +325,7 @@ DASHBOARD: Dashboard to return to after editing." tabulated-list-sort-key nil)) ;;;###autoload -(cl-defun gnosis-dashboard (&optional dashboard-type (note-ids nil)) +(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 @@ -349,5 +350,10 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (tabulated-list-print t))) +(transient-define-prefix gnosis-dashboard-transient () + "Transient buffer for gnosis dashboard interactions." + [["Actions" ("r" "Start Review" gnosis-review)] + ["Dashboard" ("d" "Dashboard" gnosis--dashboard)]]) + (provide 'gnosis-dashboard) ;;; gnosis-dashboard.el ends here -- cgit v1.2.3 From 5ee7502983a4f8d93b0d4c13630580edb9f73177 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Jul 2024 17:59:50 +0300 Subject: packaging: Add transient 0.7.2. * Require transient. --- gnosis-dashboard.el | 3 ++- gnosis.el | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 96d4ffe..c89fd20 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -7,7 +7,7 @@ ;; URL: https://git.thanosapollo.org/gnosis ;; Version: 0.0.1 -;; Package-Requires: ((emacs "27.2") (compat "29.1.4.2")) +;; Package-Requires: ((emacs "27.2") (compat "29.1.4.2") (transient "0.7.2")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ ;;; Code: (require 'cl-lib) (require 'calendar) +(require 'transient) (declare-function gnosis-select "gnosis.el") (declare-function gnosis-delete-note "gnosis.el") diff --git a/gnosis.el b/gnosis.el index bbb1826..ac4c0f5 100644 --- a/gnosis.el +++ b/gnosis.el @@ -7,7 +7,7 @@ ;; URL: https://thanosapollo.org/projects/gnosis ;; Version: 0.3.2 -;; Package-Requires: ((emacs "27.2") (emacsql "20240124") (compat "29.1.4.2")) +;; Package-Requires: ((emacs "27.2") (emacsql "20240124") (compat "29.1.4.2") (transient "0.7.2")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -- cgit v1.2.3 From 26a13d2b4f32bd3ecb0b2e93c91162cb619d2f00 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Jul 2024 18:00:53 +0300 Subject: dashboard-header-face: Use a Tyrian Purple variant. * Tyrian purple is a high-chroma pigment and cannot be displayed properly on RGB screens. This variant should suffice for both dark and light backgrounds. * Using outline causes isssues with centering string, since many themes use custom :height, increasing the font size. --- gnosis-dashboard.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index c89fd20..fb7d49a 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -59,9 +59,8 @@ "Store search value.") (defface gnosis-dashboard-header-face - '((t :inherit (outline-1) :weight bold)) - "Face for the dashboard header.." - :group 'gnosis) + '((t :foreground "#ff0a6a" :weight bold)) + "My custom face for both light and dark backgrounds.") (defun gnosis-dashboard-generate-dates (&optional year) "Return a list of all dates (year month day) for YEAR." -- cgit v1.2.3 From 3f2771eed6528a2a431ce995e40f57599041629f Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Jul 2024 18:02:41 +0300 Subject: dashboard: Use algorithm-date. --- gnosis-dashboard.el | 1 + 1 file changed, 1 insertion(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index fb7d49a..26550bf 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -46,6 +46,7 @@ (declare-function gnosis-center-string "gnosis.el") (declare-function gnosis-get-date-new-notes "gnosis.el") (declare-function gnosis-review-get-due-notes "gnosis.el") +(declare-function gnosis-algorithm-date "gnosis-algorithm.el") (defcustom gnosis-dashboard-months 2 "Number of additional months to display on dashboard." -- cgit v1.2.3 From 889a1aa87a5ed46639aa9f1fdb513821c8f68c8f Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Jul 2024 18:03:19 +0300 Subject: dashboard-output-average-rev: Don't include days with 0 reviews. * Output includes only days with >0 reviews. --- gnosis-dashboard.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 26550bf..7b17239 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -101,8 +101,9 @@ Skips days where no note was reviewed." (let ((total 0) (entries (gnosis-dashboard-year-stats))) (cl-loop for entry in entries + when (not (= entry 0)) do (setq total (+ total entry))) - (/ total (length (remove 0 entries))))) + (/ total (max (length (remove 0 entries)) 1)))) ;; TODO: Add more conds & faces (defun gnosis-dashboard--graph-propertize (string num) -- cgit v1.2.3 From 988b24dd10d5bdb60be76a794a558020f3158ac9 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Jul 2024 18:04:23 +0300 Subject: New function: Add dashboard--streak * Return consecutive review streak. --- gnosis-dashboard.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 7b17239..d317ad3 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -80,6 +80,18 @@ do (setq notes (append notes (list (gnosis-get-date-total-notes date))))) notes)) +(defun gnosis-dashboard--streak (dates &optional num date) + "Return current review streak. + +DATES: Dates in the activity log. +NUM: Streak number. +DATE: Integer, used with `gnosis-algorithm-date' to get previous dates." + (let ((num (or num 0)) + (date (or date 0))) + (if (member (gnosis-algorithm-date date) dates) + (gnosis-dashboard--streak dates (cl-incf num) (- date 1)) + num))) + (defun gnosis-dashboard-month-reviews (month) "Return reviewes for MONTH in current year." (cl-assert (and (integerp month) -- cgit v1.2.3 From 4318b35583481fb3fdbdbc332499607eb6fede12 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Jul 2024 18:05:17 +0300 Subject: dashboard: Move at the bottom, with minor aesthetic changes. * Move dashboard at the bottom, making it easier to find with imenu. * Minor aesthetic changes. --- gnosis-dashboard.el | 95 +++++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 43 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index d317ad3..8ac407b 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -174,49 +174,6 @@ Optionally, use when using multiple months." (end-of-line) (cl-incf month)))) -;; TODO: Create a dashboard utilizing widgets -(defun gnosis-dashboard () - "Test function to create an editable field and a search button." - (interactive) - (let ((buffer-name "*Gnosis Dashboard*")) - (when (get-buffer buffer-name) - (kill-buffer buffer-name)) ;; Kill the existing buffer if it exists - (let ((buffer (get-buffer-create buffer-name))) - (with-current-buffer buffer - (widget-insert "\n" - (gnosis-center-string - (format "%s" (propertize "Gnosis Dashboard" 'face 'gnosis-dashboard-header-face)))) - (gnosis-insert-separator) - (widget-insert (gnosis-center-string (propertize "Stats:" 'face 'outline-3)) "\n") - (widget-insert (gnosis-center-string - (format "Reviewed today: %s | New: %s" - (propertize - (number-to-string (gnosis-get-date-total-notes)) - 'face - 'font-lock-variable-use-face) - (propertize - (number-to-string (gnosis-get-date-new-notes)) - 'face - 'font-lock-keyword-face)))) - (insert "\n") - (widget-insert (gnosis-center-string - (format "Daily Average: %s" - (propertize (number-to-string (gnosis-dashboard-output-average-rev)) - 'face 'font-lock-type-face)))) - (insert "\n") - (widget-insert (gnosis-center-string - (format "Due notes: %s" - (propertize - (number-to-string (length (gnosis-review-get-due-notes))) - 'face 'error)))) - (insert "\n\n") - (gnosis-dashboard-month-overview (or gnosis-dashboard-months 0)) - (use-local-map widget-keymap) - (widget-setup)) - (pop-to-buffer-same-window buffer) - (goto-char (point-min)) - (gnosis-dashboard-transient)))) - (defun gnosis-dashboard-output-note (id) "Output contents for note with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select '[main options answer tags type] 'notes `(= id ,id) t) @@ -368,6 +325,58 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." "Transient buffer for gnosis dashboard interactions." [["Actions" ("r" "Start Review" gnosis-review)] ["Dashboard" ("d" "Dashboard" gnosis--dashboard)]]) +;; TODO: Create a dashboard utilizing widgets +;;;###autoload +(defun gnosis-dashboard () + "Test function to create an editable field and a search button." + (interactive) + (delete-other-windows) + (let ((buffer-name "*Gnosis Dashboard*")) + (when (get-buffer buffer-name) + (kill-buffer buffer-name)) ;; Kill the existing buffer if it exists + (let ((buffer (get-buffer-create buffer-name))) + (with-current-buffer buffer + (widget-insert "\n" + (gnosis-center-string + (format "%s" (propertize "Gnosis Dashboard" 'face 'gnosis-dashboard-header-face)))) + (gnosis-insert-separator) + ;; (widget-insert (gnosis-center-string (propertize "Stats:" 'face 'underline)) "\n\n") + (widget-insert (gnosis-center-string + (format "Reviewed today: %s | New: %s" + (propertize + (number-to-string (gnosis-get-date-total-notes)) + 'face + 'font-lock-variable-use-face) + (propertize + (number-to-string (gnosis-get-date-new-notes)) + 'face + 'font-lock-keyword-face)))) + (insert "\n") + (widget-insert (gnosis-center-string + (format "Daily Average: %s" + (propertize (number-to-string (gnosis-dashboard-output-average-rev)) + 'face 'font-lock-type-face)))) + (insert "\n") + (widget-insert (gnosis-center-string + (format "Due notes: %s" + (propertize + (number-to-string (length (gnosis-review-get-due-notes))) + 'face 'error)))) + (insert "\n\n") + (widget-insert (gnosis-center-string + (format "Current streak: %s days" + (propertize + (number-to-string + (gnosis-dashboard--streak + (gnosis-select 'date 'activity-log '1=1 t))) + 'face 'success)))) + (insert "\n\n") + ;; (gnosis-dashboard-month-overview (or gnosis-dashboard-months 0)) + (use-local-map widget-keymap) + (widget-setup)) + (pop-to-buffer-same-window buffer) + (goto-char (point-min)) + (gnosis-dashboard-transient)))) (provide 'gnosis-dashboard) ;;; gnosis-dashboard.el ends here -- cgit v1.2.3 From e670c16cfe25393c62f985e302eb35a73a6fb85d Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Jul 2024 18:06:34 +0300 Subject: Rename gnosis--dashboard -> gnosis-dashboard--search. --- gnosis-dashboard.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 8ac407b..f031787 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -265,9 +265,9 @@ Optionally, use when using multiple months." (gnosis-dashboard-output-decks) (revert-buffer t t t))) (local-set-key (kbd "RET") #'(lambda () "View notes of deck" (interactive) - (gnosis-dashboard "notes" - (gnosis-collect-note-ids - :deck (string-to-number (tabulated-list-get-id))))))) + (gnosis-dashboard--search "notes" + (gnosis-collect-note-ids + :deck (string-to-number (tabulated-list-get-id))))))) (defun gnosis-dashboard-edit-note (&optional dashboard) "Get note id from tabulated list and edit it. @@ -295,8 +295,7 @@ DASHBOARD: Dashboard to return to after editing." (setq tabulated-list-padding 2 tabulated-list-sort-key nil)) -;;;###autoload -(cl-defun gnosis--dashboard (&optional dashboard-type (note-ids nil)) +(cl-defun gnosis-dashboard--search (&optional dashboard-type (note-ids nil)) "Display gnosis dashboard. NOTE-IDS: List of note ids to display on dashboard. When nil, prompt -- cgit v1.2.3 From ffa563e6594889d58b67b29b2827530d71e4e969 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Jul 2024 18:08:16 +0300 Subject: Add dashboard-menu using transient. * Transient buffer menu. --- gnosis-dashboard.el | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index f031787..757c46e 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -320,10 +320,13 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (tabulated-list-print t))) -(transient-define-prefix gnosis-dashboard-transient () +(transient-define-prefix gnosis-dashboard-menu () "Transient buffer for gnosis dashboard interactions." - [["Actions" ("r" "Start Review" gnosis-review)] - ["Dashboard" ("d" "Dashboard" gnosis--dashboard)]]) + [["Actions" + ("r" "Review" gnosis-review) + ("a" "Add note" gnosis-add-note)] + ["Dashboard" ("s" "Search" gnosis-dashboard--search)]]) + ;; TODO: Create a dashboard utilizing widgets ;;;###autoload (defun gnosis-dashboard () @@ -375,7 +378,7 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (widget-setup)) (pop-to-buffer-same-window buffer) (goto-char (point-min)) - (gnosis-dashboard-transient)))) + (gnosis-dashboard-menu)))) (provide 'gnosis-dashboard) ;;; gnosis-dashboard.el ends here -- cgit v1.2.3 From bcfc148fa9308d4f3df89cd17fbb9ae45989c2b3 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:44:00 +0300 Subject: New variable: dashboard--current * Track values to refresh dashboard. --- gnosis-dashboard.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 757c46e..9b7f4c8 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -59,6 +59,10 @@ (defvar gnosis-dashboard-search-value nil "Store search value.") +(defvar gnosis-dashboard--current + '(:type nil :ids nil) + "Current values to return after edits.") + (defface gnosis-dashboard-header-face '((t :foreground "#ff0a6a" :weight bold)) "My custom face for both light and dark backgrounds.") -- cgit v1.2.3 From cd8f3d5a382e1c7b72f51255408a1a4d32dcf907 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:45:36 +0300 Subject: New function: Add dashboard-return. * Returns to dashboard, refreshing for current values. --- gnosis-dashboard.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 9b7f4c8..528c570 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -67,6 +67,19 @@ '((t :foreground "#ff0a6a" :weight bold)) "My custom face for both light and dark backgrounds.") +(defun gnosis-dashboard-return (&optional current-values) + "Return to dashboard for CURRENT-VALUES." + (interactive) + (let* ((current-values (or current-values gnosis-dashboard--current)) + (type (plist-get current-values :type)) + (ids (plist-get current-values :ids))) + (cond ((eq type 'notes) + (gnosis-dashboard-output-notes ids)) + ((eq type 'decks ) + (gnosis-dashboard-output-decks)) + ((eq type 'tags ) + (gnosis-dashboard-output-tags))))) + (defun gnosis-dashboard-generate-dates (&optional year) "Return a list of all dates (year month day) for YEAR." (let* ((current-year (or (decoded-time-year (decode-time)) year)) -- cgit v1.2.3 From e5cd26d3020b3b8ca1957137f2fd4d3de1565703 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:46:53 +0300 Subject: New function: Add dashboard-edit-note. * Edit note at point inside dashbaord tabulated list. --- gnosis-dashboard.el | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 528c570..a2ec5ce 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -200,6 +200,12 @@ Optionally, use when using multiple months." else collect (replace-regexp-in-string "\n" " " (format "%s" item)))) +(defun gnosis-dashboard-edit-note (&optional id) + "Edit note with ID." + (interactive) + (let ((id (or id (string-to-number (tabulated-list-get-id))))) + (gnosis-edit-note id))) + (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.") -- cgit v1.2.3 From 98e0fd1247eba8ce65eae2da64511227a47f4f27 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:47:31 +0300 Subject: New function: dashboard-suspend-note. * Suspend either selected-ids or note at point, depending on the value of selected-ids. --- gnosis-dashboard.el | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index a2ec5ce..8aa4a25 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -206,6 +206,15 @@ Optionally, use when using multiple months." (let ((id (or id (string-to-number (tabulated-list-get-id))))) (gnosis-edit-note id))) +(defun gnosis-dashboard-suspend-note () + "Suspend note." + (interactive) + (if gnosis-dashboard--selected-ids + (gnosis-dashboard-marked-suspend) + (gnosis-suspend-note (string-to-number (tabulated-list-get-id))) + (gnosis-dashboard-output-notes gnosis-dashboard-note-ids) + (revert-buffer t t 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.") -- cgit v1.2.3 From d641ce4b86bba8cd3c9113690a5ad46f4d8bd5dc Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:48:36 +0300 Subject: New function: dashboard-delete. * Delete note at point. --- gnosis-dashboard.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 8aa4a25..1503a67 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -215,6 +215,14 @@ Optionally, use when using multiple months." (gnosis-dashboard-output-notes gnosis-dashboard-note-ids) (revert-buffer t t t))) +(defun gnosis-dashboard-delete () + "Delete note." + (interactive) + (if gnosis-dashboard--selected-ids + (gnosis-dashboard-marked-delete) + (gnosis-delete-note (string-to-number (tabulated-list-get-id))) + (gnosis-dashboard-output-notes gnosis-dashboard-note-ids) + (revert-buffer t t 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.") -- cgit v1.2.3 From 13d3810925ed5a32ba4e63ecd0cda1acef488d46 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:49:09 +0300 Subject: Add dashboard-notes-mode & it's map. * Instead of using local-set-key, we will be using a minor mode for each dashboard-output. --- gnosis-dashboard.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 1503a67..06bb481 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -223,6 +223,22 @@ Optionally, use when using multiple months." (gnosis-delete-note (string-to-number (tabulated-list-get-id))) (gnosis-dashboard-output-notes gnosis-dashboard-note-ids) (revert-buffer t t t))) + +(defvar-keymap gnosis-dashboard-notes-mode-map + :doc "Keymap for notes dashboard." + "e" #'gnosis-dashboard-edit-note + "s" #'gnosis-dashboard-suspend-note + "a" #'gnosis-add-note + "r" #'gnosis-dashboard-return + "g" #'gnosis-dashboard-return + "d" #'gnosis-dashboard-delete + "m" #'gnosis-dashboard-mark-toggle + "u" #'gnosis-dashboard-mark-toggle) + +(define-minor-mode gnosis-dashboard-notes-mode + "Minor mode for gnosis dashboard notes output." + :keymap gnosis-dashboard-notes-mode-map) + (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.") -- cgit v1.2.3 From 515a7009c535346a12ecf3ec823f4d0963bc0c61 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:50:27 +0300 Subject: Refactor dashboard-output-notes * Replace local-set-key with dashboard-notes-mode. * Update dashboard--current-values --- gnosis-dashboard.el | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 06bb481..a4d22a4 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -244,6 +244,7 @@ Optionally, use when using multiple months." (cl-assert (listp note-ids) t "`note-ids' must be a list of note ids.") (pop-to-buffer-same-window "*gnosis-dashboard*") (gnosis-dashboard-mode) + (gnosis-dashboard-notes-mode) (setf tabulated-list-format `[("Main" ,(/ (window-width) 4) t) ("Options" ,(/ (window-width) 6) t) ("Answer" ,(/ (window-width) 6) t) @@ -256,22 +257,8 @@ Optionally, use when using multiple months." 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 gnosis-dashboard-note-ids) - (revert-buffer t t t))) - (local-set-key (kbd "a") #'gnosis-add-note) - (local-set-key (kbd "r") #'gnosis-dashboard) - (local-set-key (kbd "d") #'(lambda () (interactive) - (gnosis-delete-note (string-to-number (tabulated-list-get-id))) - (gnosis-dashboard-output-notes gnosis-dashboard-note-ids) - (revert-buffer t t t))) - (local-unset-key (kbd "RET"))) + (tabulated-list-print t) + (setf gnosis-dashboard--current `(:type notes :ids ,note-ids))) (defun gnosis-dashboard-deck-note-count (id) "Return total note count for deck with ID." -- cgit v1.2.3 From 56640df45c10dd285bbcafd1c7331c44c434df12 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:53:19 +0300 Subject: New function: dashboard-output-tag. * Output tag name and total notes for tag. --- gnosis-dashboard.el | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index a4d22a4..6f4a7ca 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -266,6 +266,11 @@ Optionally, use when using multiple months." (when (gnosis-select 'id 'decks `(= id ,id)) (list (number-to-string note-count))))) +(defun gnosis-dashboard-output-tag (tag) + "Output TAG name and total notes." + (let ((notes (gnosis-get-tag-notes tag))) + `(,tag ,(number-to-string (length notes))))) + (defun gnosis-dashboard-output-deck (id) "Output contents from deck with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select -- cgit v1.2.3 From 14c5059d751a9ba5e39064dcd71f4172431c98ca Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:53:45 +0300 Subject: New function: dashboard-sort-total-notes. * Function to be used to sort tag dashboard for total notes. --- gnosis-dashboard.el | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 6f4a7ca..f70142d 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -271,6 +271,12 @@ Optionally, use when using multiple months." (let ((notes (gnosis-get-tag-notes tag))) `(,tag ,(number-to-string (length notes))))) +(defun gnosis-dashboard-sort-total-notes (entry1 entry2) + "Sort function for the total notes column, for ENTRY1 and ENTRY2." + (let ((total1 (string-to-number (elt (cadr entry1) 1))) + (total2 (string-to-number (elt (cadr entry2) 1)))) + (< total1 total2))) + (defun gnosis-dashboard-output-deck (id) "Output contents from deck with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select -- cgit v1.2.3 From 5d6c8d996d1e700c4f2476f96b726a80de7421b8 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:54:10 +0300 Subject: New function: dashboard-rename-tag. * Rename TAG to NEW-TAG for all notes under TAG. --- gnosis-dashboard.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index f70142d..cab77a1 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -277,6 +277,16 @@ Optionally, use when using multiple months." (total2 (string-to-number (elt (cadr entry2) 1)))) (< total1 total2))) +(defun gnosis-dashboard-rename-tag (&optional tag new-tag ) + "Rename TAG to NEW-TAG." + (interactive) + (let ((new-tag (or new-tag (read-string "News tag name: "))) + (tag (or tag (tabulated-list-get-id)))) + (cl-loop for note in (gnosis-get-tag-notes tag) + do (let* ((tags (car (gnosis-select '[tags] 'notes `(= id ,note) t))) + (new-tags (cl-substitute new-tag tag tags :test #'string-equal))) + (gnosis-update 'notes `(= tags ',new-tags) `(= id ,note)))))) + (defun gnosis-dashboard-output-deck (id) "Output contents from deck with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select -- cgit v1.2.3 From 2b58101fdac47d879a0dd7650739169063cbc744 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:58:22 +0300 Subject: New function: Add dashboard-tag-view-notes. * Output all notes for tag in dashboard. --- gnosis-dashboard.el | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index cab77a1..5b9469e 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -287,6 +287,12 @@ Optionally, use when using multiple months." (new-tags (cl-substitute new-tag tag tags :test #'string-equal))) (gnosis-update 'notes `(= tags ',new-tags) `(= id ,note)))))) +(defun gnosis-dashboard-tag-view-notes (&optional tag) + "View notes for TAG." + (interactive) + (let ((tag (or tag (tabulated-list-get-id)))) + (gnosis-dashboard-output-notes (gnosis-get-tag-notes tag)))) + (defun gnosis-dashboard-output-deck (id) "Output contents from deck with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select -- cgit v1.2.3 From 2146a0286abf2b6434bfc25cac5707617a27f677 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 18:59:38 +0300 Subject: Add dashboard-tags-mode with custom map. --- gnosis-dashboard.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 5b9469e..bb86dd0 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -293,6 +293,16 @@ Optionally, use when using multiple months." (let ((tag (or tag (tabulated-list-get-id)))) (gnosis-dashboard-output-notes (gnosis-get-tag-notes tag)))) +(defvar-keymap gnosis-dashboard-tags-mode-map + "RET" #'gnosis-dashboard-tag-view-notes + "e" #'gnosis-dashboard-rename-tag + "r" #'gnosis-dashboard-rename-tag + "g" #'gnosis-dashboard-return) + +(define-minor-mode gnosis-dashboard-tags-mode + "Mode for dashboard output of tags." + :keymap gnosis-dashboard-tags-mode-map) + (defun gnosis-dashboard-output-deck (id) "Output contents from deck with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select -- cgit v1.2.3 From cd0608d19e61d33e39379ca68512b57798a4bec3 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:00:27 +0300 Subject: New function: dashboard-decks-suspend-deck. * Suspend currently selected deck notes. --- gnosis-dashboard.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index bb86dd0..c3dd1d1 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -365,6 +365,16 @@ DASHBOARD: Dashboard to return to after editing." (let ((id (tabulated-list-get-id))) (gnosis-edit-deck (string-to-number id)))) +(defun gnosis-dashboard-decks-suspend-deck (&optional deck-id) + "Suspend notes for DECK-ID. + +When called with called with a prefix, unsuspend all notes of deck." + (interactive) + (let ((deck-id (or deck-id (string-to-number (tabulated-list-get-id))))) + (gnosis-suspend-deck deck-id) + (gnosis-dashboard-output-decks) + (revert-buffer t t t))) + (defvar-keymap gnosis-dashboard-mode-map :doc "gnosis-dashboard keymap" "q" #'quit-window) -- cgit v1.2.3 From fb52e080855f1533907fcd831a5d22803773dd63 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:01:07 +0300 Subject: New function: Add dashboard-decks-delete. * Delete deck at point. --- gnosis-dashboard.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index c3dd1d1..331e19f 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -375,6 +375,14 @@ When called with called with a prefix, unsuspend all notes of deck." (gnosis-dashboard-output-decks) (revert-buffer t t t))) +(defun gnosis-dashboard-decks-delete (&optional deck-id) + "Delete DECK-ID." + (interactive) + (let ((deck-id (or deck-id (string-to-number (tabulated-list-get-id))))) + (gnosis-delete-deck deck-id) + (gnosis-dashboard-output-decks) + (revert-buffer t t t))) + (defvar-keymap gnosis-dashboard-mode-map :doc "gnosis-dashboard keymap" "q" #'quit-window) -- cgit v1.2.3 From 41b5157be52772dadfecd9bbc660e0af2efa4581 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:01:36 +0300 Subject: New function: dashboard-decks-view-deck. * View deck notes for DECK-ID. --- gnosis-dashboard.el | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 331e19f..dee5273 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -383,6 +383,12 @@ When called with called with a prefix, unsuspend all notes of deck." (gnosis-dashboard-output-decks) (revert-buffer t t t))) +(defun gnosis-dashboard-decks-view-deck (&optional deck-id) + "View notes of DECK-ID." + (interactive) + (let ((deck-id (or deck-id (string-to-number (tabulated-list-get-id))))) + (gnosis-dashboard-output-notes (gnosis-collect-note-ids :deck deck-id)))) + (defvar-keymap gnosis-dashboard-mode-map :doc "gnosis-dashboard keymap" "q" #'quit-window) -- cgit v1.2.3 From 4aa4546b7dc3a22d5d7e26d714a2bad01a9cc43e Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:02:24 +0300 Subject: dashboard-mode-map: Add dashboard-menu binding. * Add transient buffer binding at h. --- gnosis-dashboard.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index dee5273..ccd4219 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -391,7 +391,8 @@ When called with called with a prefix, unsuspend all notes of deck." (defvar-keymap gnosis-dashboard-mode-map :doc "gnosis-dashboard keymap" - "q" #'quit-window) + "q" #'quit-window + "h" #'gnosis-dashboard-menu) (define-derived-mode gnosis-dashboard-mode tabulated-list-mode "Gnosis Dashboard" "Major mode for displaying Gnosis dashboard." -- cgit v1.2.3 From f13137a789e57117ef4e72b77e8ba1c5adfe8bfb Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:03:01 +0300 Subject: New variable: dashboard--selected-ids. * Currently marked ids. --- gnosis-dashboard.el | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index ccd4219..ad5d821 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -67,6 +67,9 @@ '((t :foreground "#ff0a6a" :weight bold)) "My custom face for both light and dark backgrounds.") +(defvar gnosis-dashboard--selected-ids nil + "Selected ids from the tabulated list.") + (defun gnosis-dashboard-return (&optional current-values) "Return to dashboard for CURRENT-VALUES." (interactive) -- cgit v1.2.3 From cafca38b4dd5fc2150f6f326aa31f5feec224107 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:03:29 +0300 Subject: New function: Add dashboard-output-tags. * Output all tags with total notes. --- gnosis-dashboard.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index ad5d821..89692b6 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -306,6 +306,22 @@ Optionally, use when using multiple months." "Mode for dashboard output of tags." :keymap gnosis-dashboard-tags-mode-map) +(defun gnosis-dashboard-output-tags (&optional tags) + "Format gnosis dashboard with output of TAGS." + (let ((tags (or tags (gnosis-get-tags--unique)))) + (pop-to-buffer-same-window "*gnosis-dashboard*") + (gnosis-dashboard-mode) + (gnosis-dashboard-tags-mode) + (setf gnosis-dashboard--current '(:type 'tags)) + (setq tabulated-list-format [("Name" 35 t) + ("Total Notes" 10 gnosis-dashboard-sort-total-notes)]) + (tabulated-list-init-header) + (setq tabulated-list-entries + (cl-loop for tag in tags + collect (list (car (gnosis-dashboard-output-tag tag)) + (vconcat (gnosis-dashboard-output-tag tag))))) + (tabulated-list-print t))) + (defun gnosis-dashboard-output-deck (id) "Output contents from deck with ID, formatted for gnosis dashboard." (cl-loop for item in (append (gnosis-select -- cgit v1.2.3 From 8374f9b081fac7477194d92974bdf47c9cc4ba94 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:07:02 +0300 Subject: dashboard-output-deck: Remove deprecated values. * Failure-factor, ef values etc. are deprecated. --- gnosis-dashboard.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 89692b6..e1fc1c3 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -324,8 +324,7 @@ Optionally, use when using multiple months." (defun gnosis-dashboard-output-deck (id) "Output contents from deck with ID, formatted for gnosis dashboard." - (cl-loop for item in (append (gnosis-select - '[name failure-factor ef-increase ef-decrease ef-threshold initial-interval] + (cl-loop for item in (append (gnosis-select 'name 'decks `(= id ,id) t) (mapcar 'string-to-number (gnosis-dashboard-deck-note-count id))) when (listp item) -- cgit v1.2.3 From dda4e42b49dc44c8aeef2bdfcc33698d71fd4434 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:07:41 +0300 Subject: Add gnosis-dashboard-decks-mode with custom map. --- gnosis-dashboard.el | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index e1fc1c3..2813cc2 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -331,6 +331,17 @@ Optionally, use when using multiple months." do (cl-remove-if (lambda (x) (and (vectorp x) (zerop (length x)))) item) collect (format "%s" item))) +(defvar-keymap gnosis-dashboard-decks-mode-map + "e" #'gnosis-dashboard-edit-deck + "a" #'gnosis-dashboard-decks-add + "s" #'gnosis-dashboard-decks-suspend-deck + "d" #'gnosis-dashboard-decks-delete + "RET" #'gnosis-dashboard-decks-view-deck) + +(define-minor-mode gnosis-dashboard-decks-mode + "Minor mode for deck output." + :keymap gnosis-dashboard-decks-mode-map) + (defun gnosis-dashboard-output-decks () "Return deck contents for gnosis dashboard." (pop-to-buffer-same-window "*gnosis-dashboard*") -- cgit v1.2.3 From 3bde664fe2ac12dad1f2e4ba9e34e26ff66fadc6 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:08:17 +0300 Subject: Rewrite dashboard-output-decks. * Remove deprecated values. * Replace local-set-key for gnosis-dashboard-decks-mode. --- gnosis-dashboard.el | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 2813cc2..acd3b01 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -346,42 +346,18 @@ Optionally, use when using multiple months." "Return deck contents for gnosis dashboard." (pop-to-buffer-same-window "*gnosis-dashboard*") (gnosis-dashboard-mode) + (gnosis-dashboard-decks-mode) (setq tabulated-list-format [("Name" 15 t) - ("failure-factor" 15 t) - ("ef-increase" 15 t) - ("ef-decrease" 15 t) - ("ef-threshold" 15 t) - ("Initial Interval" 20 t) - ("Total Notes" 10 t)]) + ("Total Notes" 10 gnosis-dashboard-sort-total-notes)]) (tabulated-list-init-header) (setq tabulated-list-entries (cl-loop for id in (gnosis-select 'id 'decks '1=1 t) for output = (gnosis-dashboard-output-deck id) when output collect (list (number-to-string id) (vconcat output)))) - (local-set-key (kbd "e") #'gnosis-dashboard-edit-deck) - (local-set-key (kbd "a") #'(lambda () "Add deck & refresh" (interactive) - (gnosis-add-deck (read-string "Deck name: ")) - (gnosis-dashboard-output-decks) - (revert-buffer t t t))) - (local-set-key (kbd "s") #'(lambda () "Suspend notes" (interactive) - (gnosis-suspend-deck - (string-to-number (tabulated-list-get-id))) - (gnosis-dashboard-output-decks) - (revert-buffer t t t))) - (local-set-key (kbd "d") #'(lambda () "Delete deck" (interactive) - (gnosis-delete-deck (string-to-number (tabulated-list-get-id))) - (gnosis-dashboard-output-decks) - (revert-buffer t t t))) - (local-set-key (kbd "RET") #'(lambda () "View notes of deck" (interactive) - (gnosis-dashboard--search "notes" - (gnosis-collect-note-ids - :deck (string-to-number (tabulated-list-get-id))))))) - -(defun gnosis-dashboard-edit-note (&optional dashboard) - "Get note id from tabulated list and edit it. - -DASHBOARD: Dashboard to return to after editing." + (tabulated-list-print t) + (setf gnosis-dashboard--current `(:type decks :ids ,(gnosis-select 'id 'decks '1=1 t)))) + (interactive) (let ((id (tabulated-list-get-id)) (dashboard (or dashboard "notes"))) -- cgit v1.2.3 From 3b1ecd789d3d712b08c0555f2181096b482242af Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:09:23 +0300 Subject: New function: dashboard-deck-add. * Create a new deck. --- gnosis-dashboard.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index acd3b01..64a4783 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -358,11 +358,12 @@ Optionally, use when using multiple months." (tabulated-list-print t) (setf gnosis-dashboard--current `(:type decks :ids ,(gnosis-select 'id 'decks '1=1 t)))) +(defun gnosis-dashboard-decks-add () + "Add deck & refresh." (interactive) - (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))) + (gnosis-add-deck (read-string "Deck name: ")) + (gnosis-dashboard-output-decks) + (revert-buffer t t t)) (defun gnosis-dashboard-edit-deck () "Get deck id from tabulated list and edit it." -- cgit v1.2.3 From fdde698749edcae9e87a17f93f42aebd7d2afe3a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:10:18 +0300 Subject: dashboard-mode: Reset values for selected-ids. --- gnosis-dashboard.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 64a4783..af22ac7 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -404,7 +404,9 @@ When called with called with a prefix, unsuspend all notes of deck." "Major mode for displaying Gnosis dashboard." :keymap gnosis-dashboard-mode-map (setq tabulated-list-padding 2 - tabulated-list-sort-key nil)) + tabulated-list-sort-key nil + gnosis-dashboard--selected-ids nil) + (display-line-numbers-mode 0)) (cl-defun gnosis-dashboard--search (&optional dashboard-type (note-ids nil)) "Display gnosis dashboard. -- cgit v1.2.3 From 05b2916cb9824134a9ce89d9b19c4d010aa73307 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:11:18 +0300 Subject: New function: Add dashboard-mark-toggle. * Mark current note at point, it's value is being stored at selected-ids. --- gnosis-dashboard.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index af22ac7..848f37f 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -432,6 +432,32 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (gnosis-collect-note-ids :query (read-string "Search for note: ")))))) (tabulated-list-print t))) +(defun gnosis-dashboard-mark-toggle () + "Toggle mark on the current item in the tabulated-list." + (interactive) + (let ((inhibit-read-only t) + (entry (tabulated-list-get-entry)) + (id (tabulated-list-get-id))) + (if (derived-mode-p 'tabulated-list-mode) + (if entry + (let ((beg (line-beginning-position)) + (end (line-end-position)) + (overlays (overlays-in (line-beginning-position) (line-end-position)))) + (if (cl-some (lambda (ov) (overlay-get ov 'gnosis-mark)) overlays) + (progn + (remove-overlays beg end 'gnosis-mark t) + (setq gnosis-dashboard--selected-ids (remove id gnosis-dashboard--selected-ids)) + ;; (message "Unmarked: %s" (aref entry 0)) + ) + (let ((ov (make-overlay beg end))) + (setf gnosis-dashboard--selected-ids + (append gnosis-dashboard--selected-ids (list id))) + (overlay-put ov 'face 'highlight) + (overlay-put ov 'gnosis-mark t) + ;; (message "Marked: %s" (aref entry 0)) + ))) + (message "No entry at point")) + (message "Not in a tabulated-list-mode")))) (transient-define-prefix gnosis-dashboard-menu () "Transient buffer for gnosis dashboard interactions." -- cgit v1.2.3 From 3a156f80a897408a72e3e291e9262c3b2adaf844 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:11:48 +0300 Subject: New function: dashboard-unmark-all. * Unmark all selected notes. --- gnosis-dashboard.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 848f37f..3b1a17e 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -459,6 +459,14 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (message "No entry at point")) (message "Not in a tabulated-list-mode")))) +(defun gnosis-dashboard-unmark-all () + "Unmark all items in the tabulated-list." + (interactive) + (let ((inhibit-read-only t)) + (setq gnosis-dashboard--selected-ids nil) + (remove-overlays nil nil 'gnosis-mark t) + (message "All items unmarked"))) + (transient-define-prefix gnosis-dashboard-menu () "Transient buffer for gnosis dashboard interactions." [["Actions" -- cgit v1.2.3 From f97cb3bc80d08e0c39bd768091974e5cb3a28e2d Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:12:05 +0300 Subject: New function: dashboard-marked-delete. * Delete all selected note ids. --- gnosis-dashboard.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 3b1a17e..9b6b04b 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -467,6 +467,14 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (remove-overlays nil nil 'gnosis-mark t) (message "All items unmarked"))) +(defun gnosis-dashboard-marked-delete () + "Delete marked note entries." + (interactive) + (when (y-or-n-p "Delete selected notes?") + (cl-loop for note in gnosis-dashboard--selected-ids + do (gnosis-delete-note (string-to-number note) t)) + (gnosis-dashboard-return))) + (transient-define-prefix gnosis-dashboard-menu () "Transient buffer for gnosis dashboard interactions." [["Actions" -- cgit v1.2.3 From eb62e5a0c5a360e4181feddaaf3def177089e8d7 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:12:33 +0300 Subject: New function: Add dashboard-marked-suspend. * Suspend all selected notes. --- gnosis-dashboard.el | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 9b6b04b..7d72abb 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -475,6 +475,13 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." do (gnosis-delete-note (string-to-number note) t)) (gnosis-dashboard-return))) +(defun gnosis-dashboard-marked-suspend () + "Suspend marked note entries." + (interactive) + (when (y-or-n-p "Toggle SUSPEND on selected notes?") + (cl-loop for note in gnosis-dashboard--selected-ids + do (gnosis-suspend-note (string-to-number note) t)) + (gnosis-dashboard-return))) (transient-define-prefix gnosis-dashboard-menu () "Transient buffer for gnosis dashboard interactions." [["Actions" -- cgit v1.2.3 From e13fecc617970115bbc4059e7aee05687e6871fb Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:13:02 +0300 Subject: New function: dashboard-suffix-query. * Search for note content for QUERY. --- gnosis-dashboard.el | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 7d72abb..87e08fe 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -482,6 +482,11 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (cl-loop for note in gnosis-dashboard--selected-ids do (gnosis-suspend-note (string-to-number note) t)) (gnosis-dashboard-return))) + +(transient-define-suffix gnosis-dashboard-suffix-query (query) + "Search for note content for QUERY." + (interactive "sSearch for note content: ") + (gnosis-dashboard-output-notes (gnosis-collect-note-ids :query query))) (transient-define-prefix gnosis-dashboard-menu () "Transient buffer for gnosis dashboard interactions." [["Actions" -- cgit v1.2.3 From 38ed71aedcfca88a3adbe08c7b686292aacf2c39 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:14:19 +0300 Subject: New function: dashboard-suffix-decks. * Output decks for dashboard. --- gnosis-dashboard.el | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 87e08fe..2eeb0a2 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -487,6 +487,11 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." "Search for note content for QUERY." (interactive "sSearch for note content: ") (gnosis-dashboard-output-notes (gnosis-collect-note-ids :query query))) + +(transient-define-suffix gnosis-dashboard-suffix-decks () + (interactive) + (gnosis-dashboard-output-decks)) + (transient-define-prefix gnosis-dashboard-menu () "Transient buffer for gnosis dashboard interactions." [["Actions" -- cgit v1.2.3 From 0349a8d9321b6a9a2981557991e06b463546a8f0 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:14:54 +0300 Subject: Rewrite gnosis-dashboard-menu. * Add new values and create a 2 column layout. --- gnosis-dashboard.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 2eeb0a2..e13809a 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -496,8 +496,13 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." "Transient buffer for gnosis dashboard interactions." [["Actions" ("r" "Review" gnosis-review) - ("a" "Add note" gnosis-add-note)] - ["Dashboard" ("s" "Search" gnosis-dashboard--search)]]) + ("a" "Add note" gnosis-add-note) + ("q" "Quit" quit-window)] + ["Notes" + ("s" "Search" gnosis-dashboard-suffix-query) + ("n" "Notes" (lambda () (interactive) (gnosis-dashboard-output-notes (gnosis-collect-note-ids)))) + ("d" "Decks" gnosis-dashboard-suffix-decks) + ("t" "Tags" (lambda () (interactive) (gnosis-dashboard-output-tags)))]]) ;; TODO: Create a dashboard utilizing widgets ;;;###autoload -- cgit v1.2.3 From 3e2db28295a7603f54f273a518cd2b43f0b9f25e Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:15:50 +0300 Subject: dashboard-mode: enable gnosis-dashboard-mode. --- gnosis-dashboard.el | 1 + 1 file changed, 1 insertion(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index e13809a..5893748 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -555,6 +555,7 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (widget-setup)) (pop-to-buffer-same-window buffer) (goto-char (point-min)) + (gnosis-dashboard-mode) (gnosis-dashboard-menu)))) (provide 'gnosis-dashboard) -- cgit v1.2.3 From f56faf26bada1cf89da94fa140adb99c2d02bac0 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 3 Aug 2024 19:16:51 +0300 Subject: dashboard: Update declared functions. --- gnosis-dashboard.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 5893748..473238b 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -47,6 +47,10 @@ (declare-function gnosis-get-date-new-notes "gnosis.el") (declare-function gnosis-review-get-due-notes "gnosis.el") (declare-function gnosis-algorithm-date "gnosis-algorithm.el") +(declare-function gnosis-get-tags--unique "gnosis.el") +(declare-function gnosis-get-tag-notes "gnosis.el") +(declare-function gnosis-edit-update "gnosis.el") +(declare-function gnosis-update "gnosis.el") (defcustom gnosis-dashboard-months 2 "Number of additional months to display on dashboard." -- cgit v1.2.3 From e24fd3159c0b1ec8b796554c96d300cb3935dbb2 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 4 Aug 2024 08:27:39 +0300 Subject: New function: dashboard-suspend-tag. * Toggle suspend for all notes of tag. * Bind it to "s" under dashboard-tags-mode-map. --- gnosis-dashboard.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gnosis-dashboard.el') diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el index 473238b..1dcf9fb 100644 --- a/gnosis-dashboard.el +++ b/gnosis-dashboard.el @@ -294,6 +294,15 @@ Optionally, use when using multiple months." (new-tags (cl-substitute new-tag tag tags :test #'string-equal))) (gnosis-update 'notes `(= tags ',new-tags) `(= id ,note)))))) +(defun gnosis-dashboard-suspend-tag (&optional tag) + "Suspend notes of TAG." + (interactive) + (let* ((tag (or tag (tabulated-list-get-id))) + (notes (gnosis-get-tag-notes tag))) + (when (y-or-n-p "Toggle SUSPEND for tagged notes?") + (cl-loop for note in notes + do (gnosis-suspend-note note t))))) + (defun gnosis-dashboard-tag-view-notes (&optional tag) "View notes for TAG." (interactive) @@ -303,6 +312,7 @@ Optionally, use when using multiple months." (defvar-keymap gnosis-dashboard-tags-mode-map "RET" #'gnosis-dashboard-tag-view-notes "e" #'gnosis-dashboard-rename-tag + "s" #'gnosis-dashboard-suspend-tag "r" #'gnosis-dashboard-rename-tag "g" #'gnosis-dashboard-return) -- cgit v1.2.3