alphapapa / org-super-agenda

Supercharge your Org daily/weekly agenda by grouping items

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal to include time ranges in :scheduled and :deadline selectors

Alexander-Miller opened this issue · comments

I have 2 use-cases that I think cannot be accurately modeled with the currently available selectors:

  • An "Important" group for items whose deadlines will be due soon (for some definition of "soon").
  • A "Soon" group for items scheduled for the near future.

Currently it is only possible to match either a specific date, or anything with a future deadline/scheduled property. For me that means my Soon group will even include habits that are scheduled for the middle of next year.

So my proposal is to expand these selectors to be able to include items scheduled/deadlined no further away than x days in the future.

I built a small MVP yesterday, the implementation is simple, as usual most effort will need to go into documentation and testing.

Specifically there's 2 things I would like to get your opinion on before working on a proper PR:

  • Just how detailed does this need to be? is it sufficient to match items at most x days away, or should we go all-in and and also implement matching for hours/weeks and items in the past?
  • What should the syntax look like? Currently it's (:name "Soon" :scheduled (closer-than 7)), but it is a bit awkward with adding the currently useless "days" so it reads (closer-than 7 days).

Currently it is only possible to match either a specific date, or anything with a future deadline/scheduled property. For me that means my Soon group will even include habits that are scheduled for the middle of next year.

Did you see this sentence in the documentation under :deadline and :scheduled?

Argument may also be given like before DATE or after DATE where DATE is a date string that org-time-string-to-absolute can process.

Did you see this sentence in the documentation under :deadline and :scheduled?

I did, and I didn't think a static date would work for a long running session. But your prompting did make me take a second look and those values are re-evaluated every time the agenda is rebuilt, so dynamic values are possible. So there's no need for expanding the selectors after all. (Good thing I asked first, that saved several hours worth of effort)

With that out of the way I wonder what would be the idiomatic way to pass a date to something like "1 week in the future"? So far I have come up with (before ,(ts-format "%F %T" (ts-inc 'day 7 (ts-now)))) which is still a bit unwieldy. It's is easily abstracted of course, but I do notice that my knowledge of elisp's date and time api is lacking and you know this stuff a lot better than I do.

With that out of the way I wonder what would be the idiomatic way to pass a date to something like "1 week in the future"? So far I have come up with (before ,(ts-format "%F %T" (ts-inc 'day 7 (ts-now)))) which is still a bit unwieldy.

Yes, I think this is where the API may be improved. It should probably be similar to org-ql's API, in that the DATE argument should also accept an integer value, which would be interpreted as a number of days relative to the current date.

I've scoured the documentation, but I could not determine if the date I specify would be re-evaluated in a long running session. I know @Alexander-Miller mentions that they are re-evaluated when the agenda is rebuilt, but does that mean both org-agenda command as well as pressing org-agenda-redo? My elisp knowledge is failing me and I'm not confident in my guess to an answer.

(:name "Due soon" :deadline (before ,(org-read-date nil nil "+14d")))

I'd be more than happy to submit a PR to clarify the documentation for :deadline and :scheduled. In addition, I, too, had the same inquiry as @Alexander-Miller about how to specify my definition of soon, so I'd be happy to submit an example to the examples as well.

@pkazmier The issue you're asking about appears to be a matter of your setting a variable's value and of splicing into a backquoted list (although you didn't show a backquote in your code). Maybe this demonstration will clarify:

(setq org-super-agenda-groups `((:name "Due soon" :deadline (before ,(org-read-date nil nil "+14d")))))
;;=> ((:name "Due soon" :deadline (before "2020-12-20")))

org-super-agenda-groups
;;=> ((:name "Due soon" :deadline (before "2020-12-20")))

As you can see, the value of the variable org-super-agenda-groups now includes that date string. If you want that date string changed, it's up to you to set the variable's value accordingly.

Although this kind of question comes up not infrequently, I'm reluctant to attempt to teach Lisp (especially matters of variables, values, and backquoting/splicing) in this package's documentation. It's properly out of the package's scope. Some basic Elisp knowledge is necessary in order to construct lists for org-super-agenda-groups. However, I wouldn't mind adding a pointer to the relevant sections of the Elisp manual and/or tutorial.

Sorry, I should have been more clear. I know how to use backquote and splicing. I just didn't paste the full example with the initial backquote. I was really asking what is the proper way to group events in categories such as "Due in a week" vs just any task with a deadline in the 'future. I was being boneheaded and forgot that what I attempted to do above just sets a variable once and thus would not do what I wanted. I was hoping there was a built-in mechanism to provide some means of narrowing the scope of 'future as I think it is probably a common use case. In order to dynamically do this, I think I'll just use the :pred selector. I'll try it tomorrow and if I get it working, I'll submit an example for the "how do I group items due in N days" if it makes sense.

I was thinking about this a bit more, with a very small change, I believe dates in the form of "+12d" or "+2m" could be supported in the :before and :after args to the :deadline and :scheduled selectors. Only two lines would need to be changed:

Before (Line 453 and 490):

(org-time-string-to-absolute (cadr args))))))

After:

(org-time-string-to-absolute (org-read-date nil nil (cadr args)))))))

I'm not near my computer, so I have not tested, but will try tomorrow. Would you be willing to accept a PR if this works? I think this would enhance the usability of the two selectors immensely. Thoughts?

Seems like a good idea, probably one I should have thought of myself.

Apparently, I’m not the only one to think of using org-read-date. After I created PR #180 last night, today I stumbled across PR #149 with the same solution. Doh! I’ve closed my PR.

Did you see this sentence in the documentation under :deadline and :scheduled?

I did, and I didn't think a static date would work for a long running session. But your prompting did make me take a second look and those values are re-evaluated every time the agenda is rebuilt, so dynamic values are possible. So there's no need for expanding the selectors after all. (Good thing I asked first, that saved several hours worth of effort)

With that out of the way I wonder what would be the idiomatic way to pass a date to something like "1 week in the future"? So far I have come up with (before ,(ts-format "%F %T" (ts-inc 'day 7 (ts-now)))) which is still a bit unwieldy. It's is easily abstracted of course, but I do notice that my knowledge of elisp's date and time api is lacking and you know this stuff a lot better than I do.

I tried this solution but couldn't make it work:
org-read-date-analyze: Wrong type argument: stringp, (\, (ts-format "%F %T" (ts-inc 'day 7 (ts-now))))
Could you describe more for a novince like me? Thanks.

Hi,

I get the same thing (wrong type argument: stringp, ...) even when I try the version mentioned in this comment. #169 (comment)

If you managed to solve it I would love to hear about how.