emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carsten Dominik <carsten.dominik@gmail.com>
To: Benjamin Andresen <benny@in-ulm.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: any use for org-clock.el hooks?
Date: Sun, 21 Jun 2009 17:28:44 +0200	[thread overview]
Message-ID: <C87E9AF7-2A8C-4E19-8F7B-8A53851A095C@gmail.com> (raw)
In-Reply-To: <877hz5pr6e.fsf@in-ulm.de>

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  <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
> 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

      reply	other threads:[~2009-06-21 15:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-21 15:00 any use for org-clock.el hooks? Benjamin Andresen
2009-06-21 15:28 ` Carsten Dominik [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C87E9AF7-2A8C-4E19-8F7B-8A53851A095C@gmail.com \
    --to=carsten.dominik@gmail.com \
    --cc=benny@in-ulm.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).