summaryrefslogtreecommitdiff
path: root/contrib/lisp/org-notify.el
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/lisp/org-notify.el')
-rw-r--r--contrib/lisp/org-notify.el63
1 files changed, 40 insertions, 23 deletions
diff --git a/contrib/lisp/org-notify.el b/contrib/lisp/org-notify.el
index 9ddf150..4047448 100644
--- a/contrib/lisp/org-notify.el
+++ b/contrib/lisp/org-notify.el
@@ -1,10 +1,12 @@
;;; org-notify.el --- Notifications for Org-mode
-;; Copyright (C) 2012 Free Software Foundation, Inc.
+;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
;; Author: Peter M√ľnster <pmrb@free.fr>
;; Keywords: notification, todo-list, alarm, reminder, pop-up
+;; This file is not part of GNU Emacs.
+
;; 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
@@ -35,6 +37,7 @@
;; (org-notify-start)
;; Example setup:
+;;
;; (org-notify-add 'appt
;; '(:time "-1s" :period "20s" :duration 10
;; :actions (-message -ding))
@@ -42,11 +45,12 @@
;; :actions -notify)
;; '(:time "2h" :period "5m" :actions -message)
;; '(:time "3d" :actions -email))
+;;
;; This means for todo-items with `notify' property set to `appt': 3 days
;; before deadline, send a reminder-email, 2 hours before deadline, start to
;; send messages every 5 minutes, then 15 minutes before deadline, start to
-;; pop up notification windows every 2 minutes. The timeout of the window is
-;; set to 100 seconds. Finally, when deadline is overdue, send messages and
+;; pop up notification windows every 2 minutes. The timeout of the window is
+;; set to 100 seconds. Finally, when deadline is overdue, send messages and
;; make noise."
;; Take also a look at the function `org-notify-add'.
@@ -104,12 +108,21 @@
(cdr (assoc (match-string 3 str) conv))
(if (= (length (match-string 1 str)) 1) -1 1)))))
+(defun org-notify-convert-deadline (orig)
+ "Convert original deadline from `org-element-parse-buffer' to
+simple timestamp string."
+ (if orig
+ (replace-regexp-in-string "^<\\|>$" ""
+ (plist-get (plist-get orig 'timestamp)
+ :raw-value))))
+
(defun org-notify-make-todo (heading &rest ignored)
"Create one todo item."
(macrolet ((get (k) `(plist-get list ,k))
(pr (k v) `(setq result (plist-put result ,k ,v))))
(let* ((list (nth 1 heading)) (notify (or (get :notify) "default"))
- (deadline (get :deadline)) (heading (get :raw-value))
+ (deadline (org-notify-convert-deadline (get :deadline)))
+ (heading (get :raw-value))
result)
(when (and (eq (get :todo-type) 'todo) heading deadline)
(pr :heading heading) (pr :notify (intern notify))
@@ -173,26 +186,29 @@ forgotten tasks."
(return)))))))
(defun org-notify-add (name &rest params)
- "Add a new notification type. The NAME can be used in Org-mode property
-`notify'. If NAME is `default', the notification type applies for todo items
-without the `notify' property. This file predefines such a default
+ "Add a new notification type.
+The NAME can be used in Org-mode property `notify'. If NAME is
+`default', the notification type applies for todo items without
+the `notify' property. This file predefines such a default
notification type.
Each element of PARAMS is a list with parameters for a given time
-distance to the deadline. This distance must increase from one element to
-the next.
+distance to the deadline. This distance must increase from one
+element to the next.
+
List of possible parameters:
+
:time Time distance to deadline, when this type of notification shall
- start. It's a string: an integral value (positive or negative)
+ start. It's a string: an integral value (positive or negative)
followed by a unit (s, m, h, d, w, M).
:actions A function or a list of functions to be called to notify the
- user. Instead of a function name, you can also supply a suffix
+ user. Instead of a function name, you can also supply a suffix
of one of the various predefined `org-notify-action-xxx'
functions.
- :period Optional: can be used to repeat the actions periodically. Same
- format as :time.
+ :period Optional: can be used to repeat the actions periodically.
+ Same format as :time.
:duration Some actions use this parameter to specify the duration of the
- notification. It's an integral number in seconds.
+ notification. It's an integral number in seconds.
:audible Overwrite the value of `org-notify-audible' for this action.
For the actions, you can use your own functions or some of the predefined
@@ -200,11 +216,12 @@ ones, whose names are prefixed with `org-notify-action-'."
(setq org-notify-map (plist-put org-notify-map name params)))
(defun org-notify-start (&optional secs)
- "Start the notification daemon. If SECS is positive, it's the
-period in seconds for processing the notifications of one
-org-agenda file, and if negative, notifications will be checked
-only when emacs is idle for -SECS seconds. The default value for
-SECS is 20."
+ "Start the notification daemon.
+If SECS is positive, it's the period in seconds for processing
+the notifications of one org-agenda file, and if negative,
+notifications will be checked only when emacs is idle for -SECS
+seconds. The default value for SECS is 20."
+ (interactive)
(if org-notify-timer
(org-notify-stop))
(setq secs (or secs 20)
@@ -216,8 +233,8 @@ SECS is 20."
(defun org-notify-stop ()
"Stop the notification daemon."
(when org-notify-timer
- (cancel-timer org-notify-timer)
- (setq org-notify-timer nil)))
+ (cancel-timer org-notify-timer)
+ (setq org-notify-timer nil)))
(defun org-notify-on-action (plist key)
"User wants to see action."
@@ -299,7 +316,7 @@ SECS is 20."
(defun org-notify-select-highest-window ()
"Select the highest window on the frame, that is not is not an
-org-notify window. Mostly copied from `appt-select-lowest-window'."
+org-notify window. Mostly copied from `appt-select-lowest-window'."
(let ((highest-window (selected-window))
(bottom-edge (nth 3 (window-edges)))
next-bottom-edge)
@@ -370,7 +387,7 @@ terminal an emacs window."
;;; Provide a minimal default setup.
(org-notify-add 'default '(:time "1h" :actions -notify/window
- :period "2m" :duration 60))
+ :period "2m" :duration 60))
(provide 'org-notify)