summaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/site-lisp/appt-init.el
blob: d516af2db25dafab082d951c6b9107b2add16184 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;; appt-init.el --- Initialization for appt         -*- lexical-binding: t; -*-

;; Copyright (C) 2014  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords:

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Initialization code for the `appt' library, should get loaded when
;; `appt' is.

;;; Code:

(require 'appt)
(require 'notifications)

(defun oni:appt-display-single-notification (min-to-appt cur-time body)
  "Show an appointment in a desktop notification.

MIN-TO-APPT should be a string with the number of minutes until
the appointment.  CUR-TIME is the current time.  BODY is the text
of the appointment."
  (ignore cur-time)
  (let ((minutes (string-to-number min-to-appt)))
    (notifications-notify
     :title (cond
             ((= minutes 0) "Appointment right now")
             ((= minutes 1) "Appointment in 1 minute")
             (t (format "Appointment in %s minute(s)" min-to-appt)))
     :body body)))

(defun oni:appt-display-multiple-notifications
    (mins-to-appts cur-time bodies)
  "Show multiple appointments in desktop notifications.

MINS-TO-APPTS should be a list of strings with the numbers of
minutes until the appointments.  CUR-TIME is the current time.
BODIES is the texts of the appointments."
  (cl-mapc (lambda (min-to-appt body)
             (oni:appt-display-single-notification
              min-to-appt cur-time body))
           mins-to-appts bodies))

(defun oni:appt-display-notification (mins-to-appts cur-time bodies)
  "Show one or more appointments in desktop notifications.

MINS-TO-APPTS should be either a string with the number of
minutes until the appointment, or a list of strings with the
numbers of minutes until each appointment.  CUR-TIME is the
current time.  BODIES is either a string with the text of the
appointment or a list of strings with the text for each
appointment."
  (let ((func (if (listp bodies)
                  'oni:appt-display-multiple-notifications
                'oni:appt-display-single-notification)))
   (funcall func mins-to-appts cur-time bodies)))

(setq appt-disp-window-function #'oni:appt-display-notification
      appt-delete-window-function (lambda ())
      appt-display-diary nil)

(provide 'appt-init)
;;; appt-init.el ends here