[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] [org-timer] PATCH add hooks to org-timer.el

From: Austin Frank
Subject: [Orgmode] [org-timer] PATCH add hooks to org-timer.el
Date: Sat, 20 Feb 2010 08:41:55 -0500
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.92 (darwin)

Hello all--

I'm experimenting with the pomodoro technique [1] and trying to
integrate it with org mode.  I've attached a patch that defines some
hooks for org-timer.el.  My intention is to use these hooks to automate
record keeping and interactions with org-clock.

If this isn't the correct approach to adding hooks to timer functions,
what would you suggest?

Thanks for considering it,

[1] http://www.pomodorotechnique.com

From 86de94d18302bda17379c35f11423788b11348c2 Mon Sep 17 00:00:00 2001
From: Austin F. Frank <address@hidden>
Date: Sat, 20 Feb 2010 08:22:47 -0500
Subject: [PATCH 3/3] add hooks for relative and countdown timers

 lisp/org-timer.el |   36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/lisp/org-timer.el b/lisp/org-timer.el
index ed5a423..47397aa 100644
--- a/lisp/org-timer.el
+++ b/lisp/org-timer.el
@@ -48,6 +48,31 @@ the value of the relative timer."
   :group 'org-time
   :type 'string)
+(defcustom org-timer-start-hook nil
+  "Hook run after relative timer is started."
+  :group 'org-time
+  :type 'hook)
+(defvar org-timer-stop-hook nil
+  "Hook run before relative timer is stopped."
+  :group 'org-time
+  :type 'hook)
+(defvar org-timer-pause-hook nil
+  "Hook run before relative timer is paused."
+  :group 'org-time
+  :type 'hook)
+(defvar org-timer-set-hook nil
+  "Hook run after countdown timer is set."
+  :group 'org-time
+  :type 'hook)
+(defvar org-timer-cancel-hook nil
+  "Hook run before countdown timer is canceled."
+  :group 'org-time
+  :type 'hook)
 (defun org-timer-start (&optional offset)
   "Set the starting time for the relative timer to now.
@@ -82,7 +107,8 @@ the region 0:00:00."
       (org-timer-set-mode-line 'on)
       (message "Timer start time set to %s, current value is %s"
               (format-time-string "%T" org-timer-start-time)
-              (org-timer-secs-to-hms (or delta 0))))))
+              (org-timer-secs-to-hms (or delta 0)))
+      (run-hooks 'org-timer-start-hook))))
 (defun org-timer-pause-or-continue (&optional stop)
   "Pause or continue the relative timer.  With prefix arg, stop it entirely."
@@ -102,6 +128,7 @@ the region 0:00:00."
     (org-timer-set-mode-line 'on)
     (message "Timer continues at %s" (org-timer-value-string)))
+    (run-hooks 'org-timer-pause-hook)
     ;; pause timer
     (setq org-timer-pause-time (current-time))
     (org-timer-set-mode-line 'pause)
@@ -110,6 +137,7 @@ the region 0:00:00."
 (defun org-timer-stop ()
   "Stop the relative timer."
+  (run-hooks 'org-timer-stop-hook)
   (setq org-timer-start-time nil
        org-timer-pause-time nil)
   (org-timer-set-mode-line 'off))
@@ -264,6 +292,7 @@ VALUE can be `on', `off', or `pause'."
   (mapc (lambda(timer)
          (when (eval timer)
+            (run-hooks 'org-timer-cancel-hook)
            (cancel-timer timer)
            (setq timer nil)))
@@ -317,7 +346,10 @@ VALUE can be `on', `off', or `pause'."
                  (setq org-timer-last-timer
                        secs nil 'org-notify (format "%s: time out" hl) t))
-                 (set timer org-timer-last-timer)))
+                  (setq org-timer-mode-line-timer
+                        (run-with-timer 1 1 'org-timer-update-mode-line))
+                 (set timer org-timer-last-timer)
+                  (run-hooks 'org-timer-set-hook)))

Austin Frank
GPG Public Key (D7398C2F): http://aufrank.net/personal.asc

Attachment: pgpoGAd6BIpOF.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]