فهرست منبع

Clock: Add more hooks

This commit add four hooks to the clocking code.

Patch by Benjamin Andresen.
Carsten Dominik 16 سال پیش
والد
کامیت
03efd877bc
2فایلهای تغییر یافته به همراه29 افزوده شده و 5 حذف شده
  1. 11 0
      lisp/ChangeLog
  2. 18 5
      lisp/org-clock.el

+ 11 - 0
lisp/ChangeLog

@@ -1,3 +1,14 @@
+2009-06-21  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* 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  <carsten.dominik@gmail.com>
 
 	* org.el (org-store-link): Better default description for link to

+ 18 - 5
lisp/org-clock.el

@@ -192,6 +192,16 @@ auto     Automtically, either `all', or `repeat' for repeating tasks"
 	  (const :tag "All task time" all)
 	  (const :tag "Automatically, `all' or since `repeat'" auto)))
 
+(defvar org-clock-in-hook nil
+  "Hook run when starting the clock.")
+(defvar org-clock-out-hook nil
+  "Hook run when stopping the current clock.")
+
+(defvar org-clock-cancel-hook nil
+  "Hook run when cancelling the current clock.")
+(defvar org-clock-goto-hook nil
+  "Hook run when selecting the currently clocked-in entry.")
+
 ;;; The clock for measuring work time.
 
 (defvar org-mode-line-string "")
@@ -571,7 +581,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-click-in-hook)))))))
 
 (defun org-clock-mark-default-task ()
   "Mark current task as default task."
@@ -762,7 +773,8 @@ 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))))))
 
 (defun org-clock-cancel ()
   "Cancel the running clock be removing the start timestamp."
@@ -776,7 +788,8 @@ 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))
 
 (defun org-clock-goto (&optional select)
   "Go to the currently clocked-in entry, or to the most recently clocked one.
@@ -802,8 +815,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
   "Holds the file total time in minutes, after a call to `org-clock-sum'.")