浏览代码

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 年之前
父节点
当前提交
12a9381803
共有 2 个文件被更改,包括 25 次插入4 次删除
  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>
 
 	* 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 "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
   "Hook run when preparing the clock.
 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)
   "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 ()
   "Play sound as configured by `org-clock-sound'.