emacs-orgmode
[Top][All Lists]
Advanced

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

[Orgmode] any use for org-clock.el hooks?


From: Benjamin Andresen
Subject: [Orgmode] any use for org-clock.el hooks?
Date: Sun, 21 Jun 2009 17:00:57 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.94 (gnu/linux)

Hello Carsten,

I found myself wanting to run actions after I used the clock so I added
hooks to the most commonly actions in regards to clocks.

In case anyone is curious: I want to display the currently clocked in
task in my statusbar, and so I write it to a file and have an inotify
script update the statusbar on modification.

I used to do this via defadvice, but hooks seem cleaner and maybe
someone else wants to do something similar.

Carsten, if you think that not everything deserves a hook I won't have
any hard feelings if you don't apply it. :-)

br,
benny

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 97eb4c6..0922b49 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
+2009-06-21  Carsten Dominik  <address@hidden>
+
+       * org-clock.el (org-clock-in-hook): New hook.
+       (org-clock-in): Run `org-clock-in-hook.
+       (org-clock-out-hook): New hook.
+       (org-clock-out): Run `org-clock-out-hook.
+       (org-clock-cancel-hook): New hook.
+       (org-clock-cancel): Run `org-clock-cancel-hook.
+       (org-clock-goto-hook): New hook.
+       (org-clock-goto): Run `org-clock-goto-hook.
+
 2009-06-20  Carsten Dominik  <address@hidden>
 
        * org.el (org-store-link): Better default description for link to
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 780ad3f..2ae56a7 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -452,6 +452,8 @@ Use alsa's aplay tool if available."
       (= 0 (call-process "which" nil nil nil program-name))
     ))
 
+(defvar org-clock-in-hook nil
+  "Hook run when starting the clock.")
 
 (defvar org-clock-mode-line-entry nil
   "Information for the modeline about the running clock.")
@@ -571,7 +573,8 @@ the clocking selection, associated with the letter `d'."
            (org-clock-update-mode-line)
            (setq org-clock-mode-line-timer
                  (run-with-timer 60 60 'org-clock-update-mode-line))
-           (message "Clock starts at %s - %s" ts msg-extra)))))))
+           (message "Clock starts at %s - %s" ts msg-extra)
+            (run-hooks 'org-clock-in-hook)))))))
 
 (defun org-clock-mark-default-task ()
   "Mark current task as default task."
@@ -701,6 +704,9 @@ line and position cursor in that line."
            (and (re-search-forward org-property-end-re nil t)
                 (goto-char (match-beginning 0))))))))
 
+(defvar org-clock-out-hook nil
+  "Hook run when stopping the current clock.")
+
 (defun org-clock-out (&optional fail-quietly)
   "Stop the currently running clock.
 If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
@@ -762,7 +768,11 @@ If there is no running clock, throw an error, unless 
FAIL-QUIETLY is set."
                  (org-todo org-clock-out-switch-to-state))))))
          (force-mode-line-update)
          (message (concat "Clock stopped at %s after HH:MM = " 
org-time-clocksum-format "%s") te h m
-                  (if remove " => LINE REMOVED" "")))))))
+                  (if remove " => LINE REMOVED" ""))
+          (run-hooks 'org-clock-out-hook))))))
+
+(defvar org-clock-cancel-hook nil
+  "Hook run when cancelling the current clock.")
 
 (defun org-clock-cancel ()
   "Cancel the running clock be removing the start timestamp."
@@ -776,7 +786,11 @@ If there is no running clock, throw an error, unless 
FAIL-QUIETLY is set."
   (setq global-mode-string
        (delq 'org-mode-line-string global-mode-string))
   (force-mode-line-update)
-  (message "Clock canceled"))
+  (message "Clock canceled")
+  (run-hooks 'org-clock-cancel-hook))
+
+(defvar org-clock-goto-hook nil
+  "Hook run when selecting the currently clocked-in entry.")
 
 (defun org-clock-goto (&optional select)
   "Go to the currently clocked-in entry, or to the most recently clocked one.
@@ -802,7 +816,8 @@ With prefix arg SELECT, offer recently clocked tasks for 
selection."
     (org-cycle-hide-drawers 'children)
     (recenter)
     (if recent
-       (message "No running clock, this is the most recently clocked task"))))
+       (message "No running clock, this is the most recently clocked task"))
+    (run-hooks 'org-clock-goto-hook)))
 
 
 (defvar org-clock-file-total-minutes nil

reply via email to

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