From a9e5f06b03ffb9cc28ac2537ce98dc17bf08f66a Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Thu, 13 Jun 2024 16:28:55 -0700 Subject: Agenda in Dashboard Display the agenda in the dashboard: 1. Breakdown of tasks in their categories 2. Overdue Tasks 3. Upcoming Tasks --- elchemy-functions.el | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'elchemy-functions.el') diff --git a/elchemy-functions.el b/elchemy-functions.el index a5919d7..0c36ad8 100644 --- a/elchemy-functions.el +++ b/elchemy-functions.el @@ -56,4 +56,42 @@ (other-window 1) (term TERM)) +(defun elchemy/replace-nil (STRING &optional REPLACEMENT) + "Replace a nil value with an empty string" + (unless REPLACEMENT + (setq REPLACEMENT " ")) + (if STRING + STRING + REPLACEMENT)) + +(defun elchemy/get-agenda-items (TODO LEVEL) + "Get Agenda Items" + (let* ((agenda-items-raw (org-ql-select + (org-agenda-files) + `(todo ,TODO) + :sort '(date todo priority))) + (agenda-items-plist (mapcar #'(lambda (x) (cl--plist-to-alist (car (cdr x)))) agenda-items-raw)) + (agenda-items-filtered (seq-filter (lambda (x) (eq (cdr (assoc :level x)) LEVEL)) agenda-items-plist))) + (mapcar #'(lambda (x) (cdr (assoc :raw-value x))) agenda-items-filtered))) + +(defun elchemy/process-agenda-heading (heading) + "Process agenda headings + +Returns '((:raw-value . ) (:level ) (:priority . ) (:todo-keyword . ) (:scheduled . ))" + (let ((heading-alist (cl--plist-to-alist (car (cdr heading))))) + `(,(assoc :raw-value heading-alist) ,(assoc :level heading-alist) ,(assoc :priority heading-alist) (:todo-keyword . ,(substring-no-properties (cdr (assoc :todo-keyword heading-alist)))) (:scheduled . ,(cdr (assoc :raw-value (cl--plist-to-alist (nth 2 (assoc :scheduled heading-alist))))))))) + +(defun elchemy/format-priority (priority) + "Format a priority to the letter or '-' if no priority" + (if priority + priority + 45)) + +(defun elchemy/format-processed-agenda (agenda-list) + "Format a processed agenda to a string: +[PRIORITY] TODO-KEYWORD: HEADING ~ SCHEDULED" + (apply #'concat (mapcar #'(lambda (x) + (concat (format "[%c] " (elchemy/format-priority (cdr (assoc :priority x)))) (cdr (assoc :todo-keyword x)) ": " (cdr (assoc :raw-value x)) " ~ " (cdr (assoc :scheduled x)) "\n")) + agenda-list))) + (provide 'elchemy-functions) -- cgit v1.2.1