Browse Source

Add and use a new option: org-show-notification-handler

This option lets the user customize the notification mechanism.
For example, she might want to use todochiku.el.

This option defaults to nil, hence doesn't change the previous
behavior: if the program notify-send is installed on the system,
use it, and falls back on using (message [notification]) if not.
Bastien Guerry 16 years ago
parent
commit
12a9381803
2 changed files with 25 additions and 4 deletions
  1. 5 0
      lisp/ChangeLog
  2. 20 4
      lisp/org-clock.el

+ 5 - 0
lisp/ChangeLog

@@ -1,3 +1,8 @@
+2009-07-23  Bastien Guerry  <bzg@altern.org>
+
+	* org-clock.el (org-show-notification-handler): New option.
+	(org-show-notification): Use the new option.
+
 2009-07-21  Bastien Guerry  <bzg@altern.org>
 2009-07-21  Bastien Guerry  <bzg@altern.org>
 
 
 	* org.el (org-eval-in-calendar): Fix a bug about calendar
 	* org.el (org-eval-in-calendar): Fix a bug about calendar

+ 20 - 4
lisp/org-clock.el

@@ -192,6 +192,15 @@ auto     Automtically, either `all', or `repeat' for repeating tasks"
 	  (const :tag "All task time" all)
 	  (const :tag "All task time" all)
 	  (const :tag "Automatically, `all' or since `repeat'" auto)))
 	  (const :tag "Automatically, `all' or since `repeat'" auto)))
 
 
+(defcustom org-show-notification-handler nil
+  "Function or program to send notification with.
+The function or program will be called with the notification
+string as argument."
+  :group 'org-clock
+  :type '(choice
+	  (string :tag "Program")
+	  (function :tag "Function")))
+
 (defvar org-clock-in-prepare-hook nil
 (defvar org-clock-in-prepare-hook nil
   "Hook run when preparing the clock.
   "Hook run when preparing the clock.
 This hook is run before anything happens to the task that
 This hook is run before anything happens to the task that
@@ -441,10 +450,17 @@ Notification is shown only once."
 
 
 (defun org-show-notification (notification)
 (defun org-show-notification (notification)
   "Show notification. Use libnotify, if available."
   "Show notification. Use libnotify, if available."
-  (if (org-program-exists "notify-send")
-      (start-process "emacs-timer-notification" nil "notify-send" notification))
-  ;; In any case, show in message area
-  (message notification))
+  (cond ((functionp org-show-notification-handler)
+	 (funcall org-show-notification-handler notification))
+	((stringp org-show-notification-handler)
+	 (start-process "emacs-timer-notification" nil 
+			org-show-notification-handler notification))
+	((org-program-exists "notify-send")
+	 (start-process "emacs-timer-notification" nil 
+			"notify-send" notification))
+	;; Maybe the handler will send a message, so only use message as
+	;; a fall back option
+	(t (message notification))))
 
 
 (defun org-clock-play-sound ()
 (defun org-clock-play-sound ()
   "Play sound as configured by `org-clock-sound'.
   "Play sound as configured by `org-clock-sound'.