diff --git a/org-alert.el b/org-alert.el index 33eac39..840eb00 100644 --- a/org-alert.el +++ b/org-alert.el @@ -67,16 +67,8 @@ If nil, never stop sending notifications." :group 'org-alert :type 'string) -(defcustom org-alert-match-string - "SCHEDULED>=\"\"+SCHEDULED<\"\"|DEADLINE>=\"\"+DEADLINE<\"\"" - "property/todo/tags match string to be passed to `org-map-entries'." - :group 'org-alert - :type '(choice (regexp :tag "Match Regexp") - (const :tag "Match All" nil) - (const :tag "Use org-ql to match active time" org-ql))) - (defcustom org-alert-time-match-string - "\\(?:SCHEDULED\\|DEADLINE\\):.*<.*\\([0-9]\\{2\\}:[0-9]\\{2\\}\\).*>" + "<.*?\\([0-9]\\{2\\}:[0-9]\\{2\\}\\).*>" "regex to find times in an org subtree. The first capture group is used to extract the time" :group 'org-alert @@ -185,28 +177,29 @@ heading, the scheduled/deadline time, and the cutoff to apply" (alert head :title org-alert-notification-title :category org-alert-notification-category)))))) -(defun org-alert--check-using-org-ql () +(defun org-alert--get-after-event-cutoff-time () + "Get the time to how early we want to get the events." + (when org-alert-notify-after-event-cutoff + (ts-format "%F %T" + (ts-adjust 'minute (- org-alert-notify-after-event-cutoff) + (ts-now))))) + +(defun org-alert-check () "Check for active, due deadlines and initiate notifications using `org-ql'. This will match org heading with active timestamp, from now, until the next `org-alert-notify-cutoff' minutes." (interactive) (org-ql-select (org-agenda-files) - `(ts-active :with-time t - :from ,(ts-format "%F %T") - :to ,(ts-format "%F %T" (ts-adjust 'minute org-alert-notify-cutoff (ts-now)))) + `(or (ts-active :with-time t + :from ,(org-alert--get-after-event-cutoff-time) + :to ,(ts-format "%F %T" (ts-adjust 'minute org-alert-notify-cutoff (ts-now)))) + (and (property ,org-alert-cutoff-prop) + (ts-active :with-time t + :from ,(org-alert--get-after-event-cutoff-time)))) :action #'org-alert--dispatch) t) -(defun org-alert-check () - "Check for active, due deadlines and initiate notifications." - (interactive) - (if (eq org-alert-match-string 'org-ql) - (org-alert--check-using-org-ql) - (org-map-entries 'org-alert--dispatch org-alert-match-string 'agenda - '(org-agenda-skip-entry-if 'todo - org-done-keywords-for-agenda))) - t) - +;;;###autoload (defun org-alert-enable () "Enable the notification timer. Cancels existing timer if running." (interactive)