From 6cb373a2c1d60fadfd4589b247ca324148ca105b Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Fri, 14 Jun 2024 16:32:53 -0700 Subject: Consolidate Recreating Dashboard --- elchemy-dashboard.el | 106 +++------------------------------------------------ elchemy-user.el | 4 +- 2 files changed, 8 insertions(+), 102 deletions(-) diff --git a/elchemy-dashboard.el b/elchemy-dashboard.el index 0768483..6e8b0ae 100644 --- a/elchemy-dashboard.el +++ b/elchemy-dashboard.el @@ -1,9 +1,11 @@ -(defun elchemy/create-dashboard () +(defun elchemy/create-dashboard (&optional RECREATE) "Create the user dashboard" (interactive) (let ((buffer (get-buffer-create "*Dashboard*"))) (switch-to-buffer buffer) - (unless buffer-read-only + (unless (and buffer-read-only (not RECREATE)) + (read-only-mode -1) + (erase-buffer) (when (file-exists-p (concat elchemy/elchemy-root elchemy/dashboard-splash)) (insert-image (create-image (concat elchemy/elchemy-root elchemy/dashboard-splash) nil nil :scale 0.25)) (insert "\n")) @@ -90,104 +92,8 @@ (read-only-mode +1)))) (defun elchemy/recreate-dashboard () - "Create the user dashboard" + "Recreate the dashboard" (interactive) - (let ((buffer (get-buffer-create "*Dashboard*"))) - (switch-to-buffer buffer) - (read-only-mode -1) - (erase-buffer) - (when (file-exists-p (concat elchemy/elchemy-root elchemy/dashboard-splash)) - (insert-image (create-image (concat elchemy/elchemy-root elchemy/dashboard-splash) nil nil :scale 0.25)) - (insert "\n")) - (let ((start (point))) - (insert "Elchemy Dashboard") - (add-text-properties start (point) - '(face (:height 4.0)))) - (insert "\n\n") - (dotimes (i (length elchemy/dashboard/heading-buttons)) - (let* ((button (nth i elchemy/dashboard/heading-buttons)) - (title (car button)) - (callback (cdr button))) - (insert (buttonize title callback)) - (if (eq (% (+ i 1) elchemy/dashboard/heading-columns) 0) - (insert "\n") - (insert (format (concat "%-" (format "%d" (+ (- elchemy/dashboard/heading-max-length (length title)) elchemy/dashboard/heading-padding)) "s") " "))))) - (unless (eq (% (length elchemy/dashboard/heading-buttons) elchemy/dashboard/heading-columns) 0) - (insert "\n")) - (insert "\n\n") - (when (file-exists-p (concat elchemy/elchemy-root elchemy/elchemy-projects-file)) - (let ((start (point))) - (insert "Projects") - (add-text-properties start (point) - '(face (:height 1.5)))) - (insert "\n") - (mapcar #'(lambda (x) (let ((name (car x)) - (path (cdr x))) - (insert (buttonize name (lambda (y) (elchemy/find-file y)) path) "\n"))) - (elchemy/read-alist-file (concat elchemy/elchemy-root elchemy/elchemy-projects-file))) - (insert "\n")) - (let ((start (point))) - (insert "Agenda") - (add-text-properties start (point) - '(face (:height 1.5)))) - (insert "\n") - (setq agenda-items (mapcar #'(lambda (x) (elchemy/get-agenda-items x 3)) elchemy/dashboard-agenda-titles) - agenda-max-count (apply 'max (mapcar #'(lambda (x) (length x)) agenda-items)) - agenda-max-length (apply 'max (mapcar #'(lambda (x) (apply 'max (mapcar #'(lambda (y) (length y)) x))) agenda-items))) - (insert (apply 'format (concat "%-" (format "%d" (+ agenda-max-length elchemy/dashboard-agenda-padding)) "s" "%-" (format "%d" (+ agenda-max-length elchemy/dashboard-agenda-padding)) "s" "%s\n") elchemy/dashboard-agenda-titles)) - (dotimes (i agenda-max-count) - (insert (format - (concat "%-" (format "%d" (+ agenda-max-length elchemy/dashboard-agenda-padding)) "s") - (elchemy/replace-nil (nth i (nth 0 agenda-items))))) - (insert (format - (concat "%-" (format "%d" (+ agenda-max-length elchemy/dashboard-agenda-padding)) "s") - (elchemy/replace-nil (nth i (nth 1 agenda-items))))) - (insert (format - "%s" - (elchemy/replace-nil (nth i (nth 2 agenda-items))))) - (insert "\n") - ) - (insert "\n") - (let ((start (point))) - (insert "Overdue") - (add-text-properties start (point) - '(face (:height 1.5)))) - (insert "\n") - (insert (elchemy/format-processed-agenda (mapcar 'elchemy/process-agenda-heading (org-ql-select (org-agenda-files) `(and (todo "STRT" "WAIT" "TODO" "CYCL") (ts :from ,(- elchemy/schedule-lookahead) :to today)) :sort '(todo priority date))))) - (insert "\n") - (let ((start (point))) - (insert "Upcoming") - (add-text-properties start (point) - '(face (:height 1.5)))) - (insert "\n") - (insert (elchemy/format-processed-agenda (mapcar 'elchemy/process-agenda-heading (org-ql-select (org-agenda-files) `(and (todo "STRT" "WAIT" "TODO" "CYCL") (ts :from today :to ,elchemy/schedule-lookahead)) :sort '(todo priority date))))) - (insert "\n") - (let ((start (point))) - (insert "Command Reference") - (add-text-properties start (point) - '(face (:height 1.5)))) - (insert "\n") - (insert "C-/ ~ Undo\n") - (insert "C-x n n ~ Narrow\n") - (insert "C-x n w ~ Widen\n") - (insert "M-% ~ Query Replace\n") - (insert "C-M-s ~ Regex Search\n") - (insert "F3 ~ Record Macro\n") - (insert "F4 ~ Play Macro\n") - (insert "M-0 F4 ~ Play Macro until failure\n") - (insert "M-l ~ Lowercase following word\n") - (insert "M-u ~ Uppercase following word\n") - (insert "M-c ~ Capitalize following word\n") - (insert "M-g w ~ Jump to word\n") - (insert "M-g l ~ Jump to line\n") - (insert "C-x C-l ~ Lowercase Region\n") - (insert "C-x C-u ~ Uppercase Region\n") - (insert "C-M-n ~ Move forward one balanced expression\n") - (insert "C-M-p ~ Move forward one balanced expression\n") - (insert "\n") - (insert (buttonize "Refresh" '(lambda (x) (elchemy/recreate-dashboard)))) - (insert "\n") - (button-mode +1) - (read-only-mode +1))) + (elchemy/create-dashboard t)) (provide 'elchemy-dashboard) diff --git a/elchemy-user.el b/elchemy-user.el index ef472d9..dee91b6 100644 --- a/elchemy-user.el +++ b/elchemy-user.el @@ -19,7 +19,8 @@ ("Testing File" . (lambda (x) (elchemy/find-file "/ssh:onid:test.el"))) ) elchemy/dashboard/heading-max-length (apply #'max (mapcar #'(lambda (x) (length (car x))) elchemy/dashboard/heading-buttons)) - elchemy/dashboard/heading-padding 2) + elchemy/dashboard/heading-padding 2 + elchemy/dashboard-agenda-padding 2) ;; General Settings (setq default-directory "~/" @@ -42,7 +43,6 @@ elchemy/dashboard-agenda-titles '(#("TODO" 0 4 (fontify t face (:foreground "red"))) #("STRT" 0 4 (fontify t face (:foreground "dark cyan"))) #("WAIT" 0 4 (fontify t face (:foreground "orange")))) - elchemy/dashboard-agenda-padding 2 elchemy/schedule-lookahead 7) ;; Modeline -- cgit v1.2.1