From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: any use for org-clock.el hooks? Date: Sun, 21 Jun 2009 17:28:44 +0200 Message-ID: References: <877hz5pr6e.fsf@in-ulm.de> Mime-Version: 1.0 (Apple Message framework v935.3) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MIOyU-0006qK-0N for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 11:28:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MIOyP-0006pa-HX for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 11:28:53 -0400 Received: from [199.232.76.173] (port=44748 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIOyP-0006pX-BI for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 11:28:49 -0400 Received: from mail-ew0-f220.google.com ([209.85.219.220]:53449) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MIOyO-0001y1-SZ for emacs-orgmode@gnu.org; Sun, 21 Jun 2009 11:28:49 -0400 Received: by ewy20 with SMTP id 20so767366ewy.42 for ; Sun, 21 Jun 2009 08:28:48 -0700 (PDT) In-Reply-To: <877hz5pr6e.fsf@in-ulm.de> 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: Benjamin Andresen Cc: emacs-orgmode@gnu.org Hi Benjamin, I have no problems adding hooks wherever anyone can use one. If you have good use cases, write them up and put them up on Worg or simply describe them here on the list. I have applied your patch, thanks. - Carsten On Jun 21, 2009, at 5:00 PM, Benjamin Andresen wrote: > 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 > + > + * 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 > _______________________________________________ > 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