Skip to content

Commit afae290

Browse files
Add timestamp selector.
1 parent f5e80e4 commit afae290

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

README.org

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ These selectors take one argument alone, or multiple arguments in a list.
192192
+ =:children= :: Select any item that has child entries. Argument may be ~t~ to match if it has any children, ~nil~ to match if it has no children, ~todo~ to match if it has children with any to-do keywords, or a string to match if it has children with certain to-do keywords. You might use this to select items that are project top-level headings. Be aware that this may be very slow in non-daily/weekly agenda views because of its recursive nature.
193193
+ =:date= :: Group items that have a date associated. Argument can be =t= to match items with any date, =nil= to match items without a date, or =today= to match items with today’s date. The =ts-date= text-property is matched against.
194194
+ =:deadline= :: Group items that have a deadline. Argument can be ~t~ (to match items with any deadline), ~nil~ (to match items that have no deadline), ~past~ (to match items with a deadline in the past), ~today~ (to match items whose deadline is today), or ~future~ (to match items with a deadline in the future). 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.
195+
+ =:timestamp= :: Group items whose bodies contain an active timestamp. Argument can be ~t~ (to match items with any timestamp), ~past~ (to match items with timestamps in the past), ~today~ (to match items with timestamps set to today), or ~future~ (to match items with timestamps in the future). 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.
195196
+ =:effort<= :: Group items that are less than (or equal to) the given effort. Argument is a time-duration string, like ~5~ or ~0:05~ for 5 minutes.
196197
+ =:effort>= :: Group items that are higher than (or equal to) the given effort. Argument is a time-duration string, like ~5~ or ~0:05~ for 5 minutes.
197198
+ ~:file-path~ :: Group items whose buffers' filename paths match any of the given regular expressions.

org-super-agenda.el

+42-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ returned by :SECTION-NAME as the first item, a list of items not
368368
matching the :TEST as the second, and a list of items matching as
369369
the third."
370370
(declare (indent defun)
371+
(doc-string 2)
371372
(debug (&define symbolp stringp
372373
&rest [&or [":section-name" [&or stringp def-form]]
373374
[":test" def-form]
@@ -470,7 +471,7 @@ DATE', where DATE is a date string that
470471
(org-super-agenda--defgroup scheduled
471472
"Group items that are scheduled.
472473
Argument can be `t' (to match items scheduled for any date),
473-
`nil' (to match items that are not schedule), `past` (to match
474+
`nil' (to match items that are not scheduled), `past' (to match
474475
items scheduled for the past), `today' (to match items scheduled
475476
for today), or `future' (to match items scheduled for the
476477
future). Argument may also be given like `before DATE' or `after
@@ -504,10 +505,50 @@ DATE', where DATE is a date string that
504505
((or 'before 'on 'after) target-date))))
505506
(org-super-agenda--compare-dates comparison entry-time compare-date))))))))
506507

508+
(org-super-agenda--defgroup timestamp
509+
"Group items whose bodies contain an active timestamp.
510+
Argument can be `t' (to match items with any timestamps),
511+
`past' (to match items with timestamps in the past), `today' (to
512+
match items with timestamps set to today), or `future' (to match
513+
items with timestamps in the future). Argument may also be given
514+
like `before DATE' or `after DATE', where DATE is a date string
515+
that `org-time-string-to-absolute' can process."
516+
:section-name (pcase (car args)
517+
('t "Active timestamps")
518+
('today "Active timestamps for today")
519+
('future "Future active timestamps")
520+
('past "Past active timestamps")
521+
('before (concat "Active timestamps before " (cadr args)))
522+
('on (concat "Active timestamps on " (cadr args)))
523+
('after (concat "Active timestamps after " (cadr args))))
524+
:let* ((target-date (pcase (car args)
525+
((or 'before 'on 'after)
526+
(org-time-string-to-absolute (org-read-date nil nil (cadr args))))))
527+
(comparison (car args))
528+
(compare-date
529+
(pcase comparison
530+
((or 'future 'past 'today) (org-today))
531+
((or 'before 'after 'on) target-date)
532+
(other
533+
(message "CMP = %s => nil" other)
534+
nil))))
535+
:test (org-super-agenda--when-with-marker-buffer (org-super-agenda--get-marker item)
536+
(let ((limit (org-entry-end-position)))
537+
(cl-macrolet
538+
((next-timestamp
539+
()
540+
`(when (re-search-forward org-ts-regexp limit :no-error)
541+
(org-time-string-to-absolute (org-read-date nil nil (match-string 1))))))
542+
(cl-loop for next-ts = (next-timestamp)
543+
while next-ts
544+
thereis (or (eq comparison 't)
545+
(org-super-agenda--compare-dates comparison next-ts compare-date)))))))
546+
507547
(defun org-super-agenda--compare-dates (comparison date-a date-b)
508548
"Compare DATE-A and DATE-B according to COMPARISON.
509549
COMPARISON should be a symbol, one of: `past' or `before',
510550
`today' or `on', `future' or `after'."
551+
(message "CMP %s vs %s" date-a date-b)
511552
(pcase comparison
512553
((or 'past 'before) (< date-a date-b))
513554
((or 'today 'on) (= date-a date-b))

0 commit comments

Comments
 (0)