;;; init-appt.el --- Initialize appt.el -*- lexical-binding: t -*-

;;; Commentary:

;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Appointments.html
;; https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/lisp/calendar/appt.el
;;
;; I use appt.el to display notifications for Org tasks. I learned that this was
;; possible from Igor Melo:
;;
;; https://igormelo.org/you_don_t_need_org_alert.html
;; https://redd.it/1gdjtcf

;;; Code:

(require 'notifications)

;; Display notifications using the function `notifications-notify'.
(setopt appt-disp-window-function
        (lambda (minutes-until _current-time text)
          (notifications-notify :title (format "%s minutes until:" minutes-until)
                                :body text)))

;; Display a notification 5 minutes before each appointment.
(setopt appt-message-warning-time 5)

;; Prevent multiple notifications from being displayed per appointment.
(setopt appt-display-interval 99)

;; Don't display notifications in the mode line.
(setopt appt-display-mode-line nil)

;; Display notifications for Org tasks.
(advice-add 'appt-check :before (lambda (&rest _args)
                                  (let ((inhibit-message t))
                                    (org-agenda-to-appt t))))

(appt-activate 1)

(provide 'init-appt)

;;; init-appt.el ends here
