Clock: Add more hooks

This commit add four hooks to the clocking code.

Patch by Benjamin Andresen.
This commit is contained in:
Carsten Dominik 2009-06-21 17:26:52 +02:00
parent 0b474a71d0
commit 03efd877bc
2 changed files with 29 additions and 5 deletions

View File

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

View File

@ -192,6 +192,16 @@ 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)))
(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. ;;; The clock for measuring work time.
(defvar org-mode-line-string "") (defvar org-mode-line-string "")
@ -571,7 +581,8 @@ the clocking selection, associated with the letter `d'."
(org-clock-update-mode-line) (org-clock-update-mode-line)
(setq org-clock-mode-line-timer (setq org-clock-mode-line-timer
(run-with-timer 60 60 'org-clock-update-mode-line)) (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 () (defun org-clock-mark-default-task ()
"Mark current task as 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)))))) (org-todo org-clock-out-switch-to-state))))))
(force-mode-line-update) (force-mode-line-update)
(message (concat "Clock stopped at %s after HH:MM = " org-time-clocksum-format "%s") te h m (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 () (defun org-clock-cancel ()
"Cancel the running clock be removing the start timestamp." "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 (setq global-mode-string
(delq 'org-mode-line-string global-mode-string)) (delq 'org-mode-line-string global-mode-string))
(force-mode-line-update) (force-mode-line-update)
(message "Clock canceled")) (message "Clock canceled")
(run-hooks 'org-clock-cancel-hook))
(defun org-clock-goto (&optional select) (defun org-clock-goto (&optional select)
"Go to the currently clocked-in entry, or to the most recently clocked one. "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) (org-cycle-hide-drawers 'children)
(recenter) (recenter)
(if recent (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 (defvar org-clock-file-total-minutes nil
"Holds the file total time in minutes, after a call to `org-clock-sum'.") "Holds the file total time in minutes, after a call to `org-clock-sum'.")