Skip to content

Commit

Permalink
remove org-map-entries searching method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky Anderson committed Dec 26, 2024
1 parent a485411 commit 4d7eb3f
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions org-alert.el
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,8 @@ If nil, never stop sending notifications."
:group 'org-alert
:type 'string)

(defcustom org-alert-match-string
"SCHEDULED>=\"<today>\"+SCHEDULED<\"<tomorrow>\"|DEADLINE>=\"<today>\"+DEADLINE<\"<tomorrow>\""
"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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4d7eb3f

Please sign in to comment.