* any use for org-clock.el hooks?
@ 2009-06-21 15:00 Benjamin Andresen
2009-06-21 15:28 ` Carsten Dominik
0 siblings, 1 reply; 2+ messages in thread
From: Benjamin Andresen @ 2009-06-21 15:00 UTC (permalink / raw
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 571 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-clock-add-hooks.patch --]
[-- Type: text/x-patch, Size: 3450 bytes --]
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
[-- Attachment #3: Type: text/plain, Size: 204 bytes --]
_______________________________________________
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: any use for org-clock.el hooks?
2009-06-21 15:00 any use for org-clock.el hooks? Benjamin Andresen
@ 2009-06-21 15:28 ` Carsten Dominik
0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2009-06-21 15:28 UTC (permalink / raw
To: Benjamin Andresen; +Cc: emacs-orgmode
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-06-21 15:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-21 15:00 any use for org-clock.el hooks? Benjamin Andresen
2009-06-21 15:28 ` Carsten Dominik
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.