From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benjamin Andresen Subject: any use for org-clock.el hooks? Date: Sun, 21 Jun 2009 17:00:57 +0200 Message-ID: <877hz5pr6e.fsf@in-ulm.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MIOXz-0004Sv-8f for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 11:01:31 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MIOXu-0004Sh-7B for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 11:01:30 -0400 Received: from [199.232.76.173] (port=43202 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIOXu-0004Se-0V for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 11:01:26 -0400 Received: from main.gmane.org ([80.91.229.2]:59039 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MIOXt-0005Wf-3c for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 11:01:25 -0400 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MIOXo-0007w1-89 for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 15:01:20 +0000 Received: from i577a2066.versanet.de ([87.122.32.102]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Jun 2009 15:01:20 +0000 Received: from benny by i577a2066.versanet.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Jun 2009 15:01:20 +0000 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= 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 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=org-clock-add-hooks.patch 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 + + * 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 * 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 --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--