From 2260dde68d72536fd3502bcc20a55c1ea34dce89 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 17 May 2016 02:00:38 +0200 Subject: Show appointment notifications as notifications --- emacs/.emacs.d/site-lisp/appt-init.el | 52 ++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'emacs') diff --git a/emacs/.emacs.d/site-lisp/appt-init.el b/emacs/.emacs.d/site-lisp/appt-init.el index d24b68c..d516af2 100644 --- a/emacs/.emacs.d/site-lisp/appt-init.el +++ b/emacs/.emacs.d/site-lisp/appt-init.el @@ -26,20 +26,52 @@ ;;; Code: (require 'appt) +(require 'notifications) -(autoload 'jabber-send-message "jabber-chat") -(defvar jabber-connections) +(defun oni:appt-display-single-notification (min-to-appt cur-time body) + "Show an appointment in a desktop notification. -(defun oni:appt-display-window-and-jabber (min-to-app new-time appt-msg) - "Send a message to my phone jabber account." - (let ((fmt "%s%s (in %s minutes)")) - (jabber-send-message - (car jabber-connections) "phone@ryuslash.org" nil - (format fmt new-time appt-msg min-to-app) nil)) - (appt-disp-window min-to-app new-time appt-msg)) +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))) -(setq appt-display-diary nil) +(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 -- cgit v1.2.3-54-g00ecf