0

I've been trying to get a agenda with two segments: Everything that is overdue and a view of the next 7 days.

For now my agenda looks like this:

 org-agenda-custom-commands
         '(("t" "Agenda + Overdue"
            (
             (agenda ""
                     ((org-agenda-overriding-header "Overdue")
                      (org-agenda-entry-types '(:deadline :scheduled))
                      ;; FIXME: if this is less than today, it makes
                      ;; org-agenda ignore overdue items if set to anything other than NIL
                      (org-agenda-start-day "-1d") ; skip due today, shown below
                      (org-scheduled-past-days 10000)
                      (org-deadline-past-days 10000)
                      (org-agenda-span 1)
                      (org-deadline-warning-days 0)
                      (org-agenda-time-grid nil)
                      (org-agenda-start-on-weekday nil)
                      (org-agenda-show-all-dates nil)
                      (org-agenda-format-date "")  ;; Skip the date
                      (org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
                      ;; (org-agenda-skip-function '(org-agenda-skip-entry-if )
                      ))

             (agenda ""
                     ((org-agenda-overriding-header "Next 7 Days")
                      (org-agenda-span 7)
                      (org-agenda-time-grid nil)
                      (org-agenda-start-on-weekday nil)
                      (org-agenda-show-all-dates t)
                      (org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
                      (org-agenda-entry-types '(:deadline :scheduled))
                      (org-scheduled-past-days 0)
                      (org-deadline-past-days 0)
                      (org-deadline-warning-days 3)))

             )
            ))

Example

For this org file (today is 29/01/2023) :

* Overdue
** TODO More than yesterday overdue
SCHEDULED: <2023-01-27 Fri>
** TODO Yesterday Overdue
SCHEDULED: <2023-01-28 Sat>
* Today
** Due Today
SCHEDULED: <2023-01-29 Sun>
* Future
** Due Tomorrow
SCHEDULED: <2023-01-30 Mon>
** Due the next day
SCHEDULED: <2023-01-31 Tue>

I see this:

Overdue

  file:       Scheduled:  TODO Yesterday Overdue

===============================================================
Next 7 Days
Sunday     29 January 2023
  file:       Scheduled:  Due Today
Monday     30 January 2023 W05
  file:       Scheduled:  Due Tomorrow
Tuesday    31 January 2023
  file:       Scheduled:  Due the next day
Wednesday   1 February 2023
Thursday    2 February 2023
Friday      3 February 2023
Saturday    4 February 2023

Instead of this (edited by hand to match desired output):

Overdue

  file:       Sched. 2x:  TODO More than yesterday overdue
  file:       Sched. 1x:  TODO Yesterday Overdue

=============================================================
Next 7 Days
Sunday     29 January 2023
  file:       Scheduled:  Due Today
Monday     30 January 2023 W05
  file:       Scheduled:  Due Tomorrow
Tuesday    31 January 2023
  file:       Scheduled:  Due the next day
Wednesday   1 February 2023
Thursday    2 February 2023
Friday      3 February 2023
Saturday    4 February 2023

Also when not setting org-agenda-start-day I get this:

Overdue

  file:       Sched. 2x:  TODO More than yesterday overdue
  file:       Sched. 1x:  TODO Yesterday Overdue
  file:       Scheduled:  Due Today

=================================================================
Next 7 Days
Sunday     29 January 2023
  file:       Scheduled:  Due Today
Monday     30 January 2023 W05
  file:       Scheduled:  Due Tomorrow
Tuesday    31 January 2023
  file:       Scheduled:  Due the next day
Wednesday   1 February 2023
Thursday    2 February 2023
Friday      3 February 2023
Saturday    4 February 2023

Which is not missing entries, but has them duplicated across today and overdue.

I can't get it not show TODO's due today on the Overdue section or be missing overdue items.

I've tried the option (org-agenda-start-day "-1d"), but it doesn't seem to work properly.

Is this a bug (I've poked around in org-agenda's code but couldn't pinpoint anything obvious) or is there some way to get the desired behavior?

General Info

I'm using spacemacs development, with org-mode 9.6 @ emacs 28.1

p.s.: using tags+todo instead of agenda is not viable because I have a CREATED property on most of my entries, and using SCHEDULED<"<+0d>" also selects them even if they aren't really scheduled.

2
  • 1
    Hi - could you edit your question with a sample org-mode file and a desired agenda output? You've explained mostly what you wanted, but there's so much flexibility and variables that what you asked for a is a bit ambiguous, still.
    – Trevoke
    Jan 29, 2023 at 17:16
  • @Trevoke Can you take a look? (forgot to tag you before)
    – Luctins
    Feb 3, 2023 at 13:24

1 Answer 1

1

Okay so this felt like a defect, but I think this is actually intended behavior somehow. Anyway, here's how I got working what I think is what you want. Basically it's a custom skip function that will only keep things that are overdue starting... Right before midnight, beginning of day today. Let me know if this does the trick for you.

(defun timestamp-midnight (timestamp)
  (let ((decoded (decode-time timestamp)))
    (setf (nth 0 decoded) 0)
    (setf (nth 1 decoded) 0)
    (setf (nth 2 decoded) 0)
    (apply #'encode-time decoded)))

(defun org-agenda-skip-if-scheduled-earlier ()
  "If this function returns nil, the current match should not be skipped.
Otherwise, the function must return a position from where the search
should be continued."
  (ignore-errors
    (let ((subtree-end (save-excursion (org-end-of-subtree t)))
          (scheduled-seconds (org-time-string-to-seconds (org-entry-get nil "SCHEDULED")))
          (now (time-to-seconds (timestamp-midnight (current-time)))))
      (and scheduled-seconds
           (>= scheduled-seconds now)
           subtree-end))))


(let ((org-agenda-files '("/tmp/test-agenda/"))
      (org-agenda-custom-commands
       '(("t" "Agenda + Overdue"
          ((agenda ""
                   ((org-agenda-overriding-header "Overdue")
                    (org-agenda-entry-types '(:deadline :scheduled))
                    (org-scheduled-past-days 10000)
                    (org-deadline-past-days 10000)
                    (org-agenda-span 1)
                    (org-agenda-start-on-weekday nil)
                    (org-agenda-show-all-dates nil)
                    (org-agenda-skip-function 'org-agenda-skip-if-scheduled-earlier)))          
           (agenda ""
                   ((org-agenda-overriding-header "Next 7 Days")
                    (org-agenda-span 7)
                    (org-agenda-time-grid nil)
                    (org-agenda-start-on-weekday nil)
                    (org-agenda-show-all-dates t)
                    (org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
                    (org-agenda-entry-types '(:deadline :scheduled))
                    (org-scheduled-past-days 0)
                    (org-deadline-past-days 0)
                    (org-deadline-warning-days 3))))))))
  (org-agenda nil "t"))
1
  • Thats it! I thought of using a custom skip function, but was at a loss on how to implement it.
    – Luctins
    Feb 5, 2023 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.