Skip to content

Commit

Permalink
Add timestamp selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Miller committed Oct 3, 2021
1 parent f5e80e4 commit afae290
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ These selectors take one argument alone, or multiple arguments in a list.
+ =: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.
+ =: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.
+ =: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.
+ =: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.
+ =: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.
+ =: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.
+ ~:file-path~ :: Group items whose buffers' filename paths match any of the given regular expressions.
Expand Down
43 changes: 42 additions & 1 deletion org-super-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ returned by :SECTION-NAME as the first item, a list of items not
matching the :TEST as the second, and a list of items matching as
the third."
(declare (indent defun)
(doc-string 2)
(debug (&define symbolp stringp
&rest [&or [":section-name" [&or stringp def-form]]
[":test" def-form]
Expand Down Expand Up @@ -470,7 +471,7 @@ DATE', where DATE is a date string that
(org-super-agenda--defgroup scheduled
"Group items that are scheduled.
Argument can be `t' (to match items scheduled for any date),
`nil' (to match items that are not schedule), `past` (to match
`nil' (to match items that are not scheduled), `past' (to match
items scheduled for the past), `today' (to match items scheduled
for today), or `future' (to match items scheduled for the
future). Argument may also be given like `before DATE' or `after
Expand Down Expand Up @@ -504,10 +505,50 @@ DATE', where DATE is a date string that
((or 'before 'on 'after) target-date))))
(org-super-agenda--compare-dates comparison entry-time compare-date))))))))

(org-super-agenda--defgroup timestamp
"Group items whose bodies contain an active timestamp.
Argument can be `t' (to match items with any timestamps),
`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."
:section-name (pcase (car args)
('t "Active timestamps")
('today "Active timestamps for today")
('future "Future active timestamps")
('past "Past active timestamps")
('before (concat "Active timestamps before " (cadr args)))
('on (concat "Active timestamps on " (cadr args)))
('after (concat "Active timestamps after " (cadr args))))
:let* ((target-date (pcase (car args)
((or 'before 'on 'after)
(org-time-string-to-absolute (org-read-date nil nil (cadr args))))))
(comparison (car args))
(compare-date
(pcase comparison
((or 'future 'past 'today) (org-today))
((or 'before 'after 'on) target-date)
(other
(message "CMP = %s => nil" other)
nil))))
:test (org-super-agenda--when-with-marker-buffer (org-super-agenda--get-marker item)
(let ((limit (org-entry-end-position)))
(cl-macrolet
((next-timestamp
()
`(when (re-search-forward org-ts-regexp limit :no-error)
(org-time-string-to-absolute (org-read-date nil nil (match-string 1))))))
(cl-loop for next-ts = (next-timestamp)
while next-ts
thereis (or (eq comparison 't)
(org-super-agenda--compare-dates comparison next-ts compare-date)))))))

(defun org-super-agenda--compare-dates (comparison date-a date-b)
"Compare DATE-A and DATE-B according to COMPARISON.
COMPARISON should be a symbol, one of: `past' or `before',
`today' or `on', `future' or `after'."
(message "CMP %s vs %s" date-a date-b)
(pcase comparison
((or 'past 'before) (< date-a date-b))
((or 'today 'on) (= date-a date-b))
Expand Down

0 comments on commit afae290

Please sign in to comment.