From 2b920002cf8776891074f18fabc683667c7b4319 Mon Sep 17 00:00:00 2001 From: Mountain Man <43313373+MountainMan1312@users.noreply.github.com> Date: Fri, 10 Nov 2023 03:18:52 -0500 Subject: Make org-agenda time-grid look more consistent When using different types of logged entries, the time-grid shows them in different formats. For example, with CLOCK: entries it shows a (-) before the timestamp, and with :LOGBOOK: State changes it shows the state. None of them are aligned, and the time-grid stops being a "grid". It doesn't make sense and my ADHD can't handle it and I hate it. --- init.el | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 122 insertions(+), 2 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index 318e58d..4575df6 100644 --- a/init.el +++ b/init.el @@ -1222,8 +1222,8 @@ ;; Custom Agenda views (use-package org-agenda :config - (setq org-agenda-prefix-format '((agenda . " %-11s %-13:t %-12:c ") - (todo . " %-11s %-13:t %-12:c ")) + (setq org-agenda-prefix-format '((agenda . " %-27s %-13:t %-12:c ") ;" %-11s %-13:t %-12:c " + (todo . " %-27s %-13:t %-12:c ")) org-agenda-custom-commands '(("o" "Agenda Overview" ((agenda "" ((org-agenda-span 'day) @@ -1249,6 +1249,126 @@ :todo "NEXT") (:discard (:anything t))))))))))) +;; Make all time-grid entries, including ones from :LOGBOOK:, look the same +(defun org-agenda-get-progress () + "Return the logged TODO entries for agenda display." + (with-no-warnings (defvar date)) + (let* ((props (list 'mouse-face 'highlight + 'org-not-done-regexp org-not-done-regexp + 'org-todo-regexp org-todo-regexp + 'org-complex-heading-regexp org-complex-heading-regexp + 'help-echo + (format "mouse-2 or RET jump to org file %s" + (abbreviate-file-name buffer-file-name)))) + (items (if (consp org-agenda-show-log-scoped) + org-agenda-show-log-scoped + (if (eq org-agenda-show-log-scoped 'clockcheck) + '(clock) + org-agenda-log-mode-items))) + (parts + (delq nil + (list + (when (memq 'closed items) (concat "\\<" org-closed-string)) + (when (memq 'clock items) (concat "\\<" org-clock-string)) + (when (memq 'state items) + (format "- +State \"%s\".*?" org-todo-regexp))))) + (parts-re (if parts (mapconcat #'identity parts "\\|") + (error "`org-agenda-log-mode-items' is empty"))) + (regexp (concat + "\\(" parts-re "\\)" + " *\\[" + (regexp-quote + (substring + (format-time-string + (org-time-stamp-format) + (org-encode-time ; DATE bound by calendar + 0 0 0 (nth 1 date) (car date) (nth 2 date))) + 1 11)))) + (org-agenda-search-headline-for-time nil) + marker hdmarker priority category level tags closedp type + statep clockp state ee txt extra timestr rest clocked inherited-tags + effort effort-minutes) + (goto-char (point-min)) + (while (re-search-forward regexp nil t) + (catch :skip + (org-agenda-skip) + (setq marker (org-agenda-new-marker (match-beginning 0)) + closedp (equal (match-string 1) org-closed-string) + statep (equal (string-to-char (match-string 1)) ?-) + clockp (not (or closedp statep)) + state (and statep (match-string 2)) + category (org-get-category (match-beginning 0)) + timestr (buffer-substring (match-beginning 0) (line-end-position)) + effort (save-match-data (or (get-text-property (point) 'effort) + (org-entry-get (point) org-effort-property)))) + (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))) + (when (string-match "\\]" timestr) + ;; substring should only run to end of time stamp + (setq rest (substring timestr (match-end 0)) + timestr (substring timestr 0 (match-end 0))) + (if (and (not closedp) (not statep) + (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" + rest)) + (progn (setq timestr (concat (substring timestr 0 -1) + "-" (match-string 1 rest) "]")) + (setq clocked (match-string 2 rest))) + ;; THIS IS CHANGED from a single dash "-" to "CLOCKED" + (setq clocked "CLOCKED"))) + (save-excursion + (setq extra + (cond + ((not org-agenda-log-mode-add-notes) nil) + (statep + (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$") + (match-string 1))) + (clockp + (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$") + (match-string 1))))) + (if (not (re-search-backward org-outline-regexp-bol nil t)) + (throw :skip nil) + (goto-char (match-beginning 0)) + (setq hdmarker (org-agenda-new-marker) + inherited-tags + (or (eq org-agenda-show-inherited-tags 'always) + (and (listp org-agenda-show-inherited-tags) + (memq 'todo org-agenda-show-inherited-tags)) + (and (eq org-agenda-show-inherited-tags t) + (or (eq org-agenda-use-tag-inheritance t) + (memq 'todo org-agenda-use-tag-inheritance)))) + tags (org-get-tags nil (not inherited-tags)) + level (make-string (org-reduced-level (org-outline-level)) ? )) + (looking-at "\\*+[ \t]+\\([^\r\n]+\\)") + (setq txt (match-string 1)) + ;; MAYBE DELETE NEXT 5 LINES + (when extra + (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt) + (setq txt (concat (substring txt 0 (match-beginning 1)) + " - " extra " " (match-string 2 txt))) + (setq txt (concat txt " - " extra)))) + (setq txt (org-agenda-format-item + (cond + ;; CHANGES ARE HERE + (closedp (concat "Closed: " (spaces-string 12))) + (statep (concat "State: " state (spaces-string (- 12 (length state))))) + (t (concat "Clocked: " clocked (spaces-string (- 12 (length clocked)))))) + ;; END CHANGES + (org-add-props txt nil + 'effort effort + 'effort-minutes effort-minutes) + level category tags timestr))) + (setq type (cond (closedp "closed") + (statep "state") + (t "clock"))) + (setq priority 100000) + (org-add-props txt props + 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done + 'urgency priority 'priority priority 'level level + 'effort effort 'effort-minutes effort-minutes + 'type type 'date date + 'undone-face 'org-warning 'done-face 'org-agenda-done) + (push txt ee)) + (goto-char (line-end-position)))) + (nreverse ee))) ;; Update agenda periodically every `mm/refresh-agenda-time-seconds' seconds. ;; This was taken from https://emacs.stackexchange.com/a/68767/38877 -- cgit v1.2.3