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 Jul 11, 2020
1 parent dd0d104 commit d68dcfd
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 124 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ These selectors take one argument alone, or multiple arguments in a list.
+ =:tag= :: Group items that match any of the given tags. Argument may be a string or list of strings.
+ =:time-grid= :: Group items that appear on the time grid.
+ =:todo= :: Group items that match any of the given TODO keywords. Argument may be a string or list of strings, or ~t~ to match any keyword, or ~nil~ to match only non-todo items.
+ =:timestamp= :: Select items whose body contains an active timestamp. Argument is either ~future~ or ~any~. The former will only match headlines with a timestamp at a future date, the latter will match any active timestamp.

** Tips

Expand Down
25 changes: 25 additions & 0 deletions org-super-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,31 @@ section name for this group."
(cl-loop for regexp in args
thereis (string-match-p regexp heading)))))

(org-super-agenda--defgroup timestamp
"Group items whose bodies contain an active timestamp.
Argument is either `future' or `any'. The former will only match headlines
with a timestamp at a future date, the latter will match any active timestamp."
:section-name (pcase-exhaustive args
(`(any) "Active timestamps: ")
(`(future) "Active future timestamps: "))
:test (org-super-agenda--when-with-marker-buffer (org-super-agenda--get-marker item)
(let* ((now (ts-now))
(now-year (ts-year now))
(now-day (ts-doy now))
(limit (org-entry-end-position))
(test (pcase-exhaustive args
(`(any)
(lambda (_) t))
(`(future)
(lambda (it) (and it (>= (ts-year it) now-year) (>= (ts-doy it) now-day))))))
(next-ts))
(cl-macrolet ((next-timestamp ()
`(when (re-search-forward org-element--timestamp-regexp limit :no-error)
(ts-parse-org (match-string 1)))))
(cl-loop for next-ts = (next-timestamp)
while next-ts
thereis (funcall test next-ts))))))

(org-super-agenda--defgroup pred
"Group items that match a predicate.
Argument can be one or a list of functions, to match items that
Expand Down
Loading

0 comments on commit d68dcfd

Please sign in to comment.