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 12, 2020
1 parent dd0d104 commit a23d9cb
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 125 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,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
41 changes: 40 additions & 1 deletion org-super-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,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 @@ -459,7 +460,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 @@ -493,6 +494,44 @@ 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* ((now (ts-now))
(target-date (pcase (car args)
((or 'before 'on 'after)
(make-ts :internal (org-time-string-to-absolute (cadr args))))))
(test (pcase-exhaustive (car args)
('t (lambda (_) t))
('future (lambda (it) (ts>= it now)))
('past (lambda (it) (ts<= it now)))
('before (lambda (it) (ts<= it target-date)))
('after (lambda (it) (ts>= it target-date)))
('on (lambda (it) (and (= (ts-year it) (ts-year target-date))
(= (ts-month it) (ts-month target-date))
(= (ts-day it) (ts-day target-date))))))))
: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)
(ts-parse-org (match-string 1)))))
(cl-loop for next-ts = (next-timestamp)
while next-ts
thereis (funcall test next-ts))))))

(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',
Expand Down
Loading

0 comments on commit a23d9cb

Please sign in to comment.