annotate lisp/org/org-timer.el @ 108700:acad6349cba4

* password-cache.el (password-cache-remove): Fix docstring.
author Michael Albinus <michael.albinus@gmx.de>
date Wed, 19 May 2010 14:52:27 +0200
parents 594e81986a75
children a150e8a14679
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
1 ;;; org-timer.el --- The relative timer code for Org-mode
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106168
diff changeset
3 ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
4
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
6 ;; Keywords: outlines, hypermedia, calendar, wp
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
7 ;; Homepage: http://orgmode.org
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
8 ;; Version: 6.35i
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
9 ;;
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
11 ;;
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
15 ;; (at your option) any later version.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
16
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
20 ;; GNU General Public License for more details.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
21
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
25 ;;
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
26 ;;; Commentary:
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
27
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
28 ;; This file contains the relative timer code for Org-mode
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
29
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
30 (require 'org)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
31
104164
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
32 (declare-function org-show-notification "org-clock" (parameters))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
33 (declare-function org-agenda-error "org-agenda" ())
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
34
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
35 (defvar org-timer-start-time nil
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
36 "t=0 for the running timer.")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
37
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
38 (defvar org-timer-pause-time nil
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
39 "Time when the timer was paused.")
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
40
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
41 (defconst org-timer-re "\\([-+]?[0-9]+\\):\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)"
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
42 "Regular expression used to match timer stamps.")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
43
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
44 (defcustom org-timer-format "%s "
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
45 "The format to insert the time of the timer.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
46 This format must contain one instance of \"%s\" which will be replaced by
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
47 the value of the relative timer."
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
48 :group 'org-time
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
49 :type 'string)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
50
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
51 (defvar org-timer-start-hook nil
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
52 "Hook run after relative timer is started.")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
53
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
54 (defvar org-timer-stop-hook nil
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
55 "Hook run before relative timer is stopped.")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
56
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
57 (defvar org-timer-pause-hook nil
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
58 "Hook run before relative timer is paused.")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
59
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
60 (defvar org-timer-set-hook nil
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
61 "Hook run after countdown timer is set.")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
62
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
63 (defvar org-timer-done-hook nil
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
64 "Hook run after countdown timer reaches zero.")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
65
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
66 (defvar org-timer-cancel-hook nil
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
67 "Hook run before countdown timer is canceled.")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
68
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
69 ;;;###autoload
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
70 (defun org-timer-start (&optional offset)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
71 "Set the starting time for the relative timer to now.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
72 When called with prefix argument OFFSET, prompt the user for an offset time,
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
73 with the default taken from a timer stamp at point, if any.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
74 If OFFSET is a string or an integer, it is directly taken to be the offset
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
75 without user interaction.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
76 When called with a double prefix arg, all timer strings in the active
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
77 region will be shifted by a specific amount. You will be prompted for
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
78 the amount, with the default to make the first timer string in
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
79 the region 0:00:00."
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
80 (interactive "P")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
81 (if (equal offset '(16))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
82 (call-interactively 'org-timer-change-times-in-region)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
83 (let (delta def s)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
84 (if (not offset)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
85 (setq org-timer-start-time (current-time))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
86 (cond
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
87 ((integerp offset) (setq delta offset))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
88 ((stringp offset) (setq delta (org-timer-hms-to-secs offset)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
89 (t
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
90 (setq def (if (org-in-regexp org-timer-re)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
91 (match-string 0)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
92 "0:00:00")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
93 s (read-string
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
94 (format "Restart timer with offset [%s]: " def)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
95 (unless (string-match "\\S-" s) (setq s def))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
96 (setq delta (org-timer-hms-to-secs (org-timer-fix-incomplete s)))))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
97 (setq org-timer-start-time
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
98 (seconds-to-time
104810
86b7fe7d1d8f 2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 104164
diff changeset
99 (- (org-float-time) (org-timer-hms-to-secs s)))))
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
100 (org-timer-set-mode-line 'on)
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
101 (message "Timer start time set to %s, current value is %s"
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
102 (format-time-string "%T" org-timer-start-time)
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
103 (org-timer-secs-to-hms (or delta 0)))
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
104 (run-hooks 'org-timer-start-hook))))
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
105
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
106 (defun org-timer-pause-or-continue (&optional stop)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
107 "Pause or continue the relative timer. With prefix arg, stop it entirely."
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
108 (interactive "P")
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
109 (cond
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
110 (stop (org-timer-stop))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
111 ((not org-timer-start-time) (error "No timer is running"))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
112 (org-timer-pause-time
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
113 ;; timer is paused, continue
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
114 (setq org-timer-start-time
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
115 (seconds-to-time
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
116 (-
104810
86b7fe7d1d8f 2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 104164
diff changeset
117 (org-float-time)
86b7fe7d1d8f 2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 104164
diff changeset
118 (- (org-float-time org-timer-pause-time)
86b7fe7d1d8f 2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 104164
diff changeset
119 (org-float-time org-timer-start-time))))
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
120 org-timer-pause-time nil)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
121 (org-timer-set-mode-line 'on)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
122 (message "Timer continues at %s" (org-timer-value-string)))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
123 (t
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
124 ;; pause timer
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
125 (run-hooks 'org-timer-pause-hook)
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
126 (setq org-timer-pause-time (current-time))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
127 (org-timer-set-mode-line 'pause)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
128 (message "Timer paused at %s" (org-timer-value-string)))))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
129
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
130 (defun org-timer-stop ()
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
131 "Stop the relative timer."
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
132 (interactive)
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
133 (run-hooks 'org-timer-stop-hook)
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
134 (setq org-timer-start-time nil
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
135 org-timer-pause-time nil)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
136 (org-timer-set-mode-line 'off))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
137
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
138 ;;;###autoload
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
139 (defun org-timer (&optional restart)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
140 "Insert a H:MM:SS string from the timer into the buffer.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
141 The first time this command is used, the timer is started. When used with
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
142 a `C-u' prefix, force restarting the timer.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
143 When used with a double prefix arg `C-u C-u', change all the timer string
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
144 in the region by a fixed amount. This can be used to recalibrate a timer
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
145 that was not started at the correct moment."
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
146 (interactive "P")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
147 (if (equal restart '(4)) (org-timer-start))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
148 (or org-timer-start-time (org-timer-start))
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
149 (insert (org-timer-value-string)))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
150
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
151 (defun org-timer-value-string ()
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
152 (format org-timer-format (org-timer-secs-to-hms (floor (org-timer-seconds)))))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
153
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
154 (defun org-timer-seconds ()
104810
86b7fe7d1d8f 2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 104164
diff changeset
155 (- (org-float-time (or org-timer-pause-time (current-time)))
86b7fe7d1d8f 2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 104164
diff changeset
156 (org-float-time org-timer-start-time)))
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
157
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
158 ;;;###autoload
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
159 (defun org-timer-change-times-in-region (beg end delta)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
160 "Change all h:mm:ss time in region by a DELTA."
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
161 (interactive
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
162 "r\nsEnter time difference like \"-1:08:26\". Default is first time to zero: ")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
163 (let ((re "[-+]?[0-9]+:[0-9]\\{2\\}:[0-9]\\{2\\}") p)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
164 (unless (string-match "\\S-" delta)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
165 (save-excursion
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
166 (goto-char beg)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
167 (when (re-search-forward re end t)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
168 (setq delta (match-string 0))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
169 (if (equal (string-to-char delta) ?-)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
170 (setq delta (substring delta 1))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
171 (setq delta (concat "-" delta))))))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
172 (setq delta (org-timer-hms-to-secs (org-timer-fix-incomplete delta)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
173 (when (= delta 0) (error "No change"))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
174 (save-excursion
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
175 (goto-char end)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
176 (while (re-search-backward re beg t)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
177 (setq p (point))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
178 (replace-match
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
179 (save-match-data
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
180 (org-timer-secs-to-hms (+ (org-timer-hms-to-secs (match-string 0)) delta)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
181 t t)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
182 (goto-char p)))))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
183
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
184 ;;;###autoload
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
185 (defun org-timer-item (&optional arg)
100458
ba23e35d3eaf 2008-12-17 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100448
diff changeset
186 "Insert a description-type item with the current timer value."
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
187 (interactive "P")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
188 (let ((ind 0))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
189 (save-excursion
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
190 (skip-chars-backward " \n\t")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
191 (condition-case nil
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
192 (progn
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
193 (org-beginning-of-item)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
194 (setq ind (org-get-indentation)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
195 (error nil)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
196 (or (bolp) (newline))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
197 (org-indent-line-to ind)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
198 (insert "- ")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
199 (org-timer (if arg '(4)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
200 (insert ":: ")))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
201
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
202 (defun org-timer-fix-incomplete (hms)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
203 "If hms is a H:MM:SS string with missing hour or hour and minute, fix it."
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
204 (if (string-match "\\(?:\\([0-9]+:\\)?\\([0-9]+:\\)\\)?\\([0-9]+\\)" hms)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
205 (replace-match
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
206 (format "%d:%02d:%02d"
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
207 (if (match-end 1) (string-to-number (match-string 1 hms)) 0)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
208 (if (match-end 2) (string-to-number (match-string 2 hms)) 0)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
209 (string-to-number (match-string 3 hms)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
210 t t hms)
100458
ba23e35d3eaf 2008-12-17 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100448
diff changeset
211 (error "Cannot parse HMS string \"%s\"" hms)))
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
212
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
213 (defun org-timer-hms-to-secs (hms)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
214 "Convert h:mm:ss string to an integer time.
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
215 If the string starts with a minus sign, the integer will be negative."
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
216 (if (not (string-match
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
217 "\\([-+]?[0-9]+\\):\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)"
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
218 hms))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
219 0
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
220 (let* ((h (string-to-number (match-string 1 hms)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
221 (m (string-to-number (match-string 2 hms)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
222 (s (string-to-number (match-string 3 hms)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
223 (sign (equal (substring (match-string 1 hms) 0 1) "-")))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
224 (setq h (abs h))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
225 (* (if sign -1 1) (+ s (* 60 (+ m (* 60 h))))))))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
226
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
227 (defun org-timer-secs-to-hms (s)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
228 "Convert integer S into h:mm:ss.
100458
ba23e35d3eaf 2008-12-17 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100448
diff changeset
229 If the integer is negative, the string will start with \"-\"."
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
230 (let (sign m h)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
231 (setq sign (if (< s 0) "-" "")
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
232 s (abs s)
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
233 m (/ s 60) s (- s (* 60 m))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
234 h (/ m 60) m (- m (* 60 h)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
235 (format "%s%d:%02d:%02d" sign h m s)))
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
236
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
237 (defvar org-timer-mode-line-timer nil)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
238 (defvar org-timer-mode-line-string nil)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
239
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
240 (defun org-timer-set-mode-line (value)
105973
b7d8222914b4 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 105341
diff changeset
241 "Set the mode-line display of the relative timer.
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
242 VALUE can be `on', `off', or `pause'."
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
243 (or global-mode-string (setq global-mode-string '("")))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
244 (or (memq 'org-timer-mode-line-string global-mode-string)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
245 (setq global-mode-string
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
246 (append global-mode-string '(org-timer-mode-line-string))))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
247 (cond
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
248 ((equal value 'off)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
249 (when org-timer-mode-line-timer
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
250 (cancel-timer org-timer-mode-line-timer)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
251 (setq org-timer-mode-line-timer nil))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
252 (setq global-mode-string
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
253 (delq 'org-timer-mode-line-string global-mode-string))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
254 (force-mode-line-update))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
255 ((equal value 'pause)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
256 (when org-timer-mode-line-timer
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
257 (cancel-timer org-timer-mode-line-timer)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
258 (setq org-timer-mode-line-timer nil)))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
259 ((equal value 'on)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
260 (or global-mode-string (setq global-mode-string '("")))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
261 (or (memq 'org-timer-mode-line-string global-mode-string)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
262 (setq global-mode-string
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
263 (append global-mode-string '(org-timer-mode-line-string))))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
264 (org-timer-update-mode-line)
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
265 (when org-timer-mode-line-timer
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
266 (cancel-timer org-timer-mode-line-timer))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
267 (setq org-timer-mode-line-timer
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
268 (run-with-timer 1 1 'org-timer-update-mode-line)))))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
269
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
270 (defun org-timer-update-mode-line ()
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
271 "Update the timer time in the mode line."
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
272 (if org-timer-pause-time
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
273 nil
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
274 (setq org-timer-mode-line-string
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
275 (concat " <" (substring (org-timer-value-string) 0 -1) ">"))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
276 (force-mode-line-update)))
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
277
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
278 (defvar org-timer-current-timer nil)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
279 (defun org-timer-cancel-timer ()
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
280 "Cancel the current timer."
104164
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
281 (interactive)
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
282 (when (eval org-timer-current-timer)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
283 (run-hooks 'org-timer-cancel-hook)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
284 (cancel-timer org-timer-current-timer)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
285 (setq org-timer-current-timer nil))
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
286 (message "Last timer canceled"))
104164
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
287
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
288 (defun org-timer-show-remaining-time ()
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
289 "Display the remaining time before the timer ends."
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
290 (interactive)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
291 (require 'time)
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
292 (if (not org-timer-current-timer)
104164
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
293 (message "No timer set")
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
294 (let* ((rtime (decode-time
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
295 (time-subtract (timer--time org-timer-current-timer)
104164
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
296 (current-time))))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
297 (rsecs (nth 0 rtime))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
298 (rmins (nth 1 rtime)))
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
299 (message "%d minute(s) %d seconds left before next time out"
104164
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
300 rmins rsecs))))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
301
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
302 ;;;###autoload
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
303 (defun org-timer-set-timer (minutes)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
304 "Set a timer."
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
305 (interactive "sTime out in (min)? ")
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
306 (if (not (string-match "[0-9]+" minutes))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
307 (org-timer-show-remaining-time)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
308 (let* ((mins (string-to-number (match-string 0 minutes)))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
309 (secs (* mins 60))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
310 (hl (cond
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
311 ((string-match "Org Agenda" (buffer-name))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
312 (let* ((marker (or (get-text-property (point) 'org-marker)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
313 (org-agenda-error)))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
314 (hdmarker (or (get-text-property (point) 'org-hd-marker)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
315 marker))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
316 (pos (marker-position marker)))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
317 (with-current-buffer (marker-buffer marker)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
318 (widen)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
319 (goto-char pos)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
320 (org-show-entry)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
321 (org-get-heading))))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
322 ((eq major-mode 'org-mode)
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
323 (org-get-heading))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
324 (t (error "Not in an Org buffer"))))
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
325 timer-set)
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
326 (if org-timer-current-timer
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
327 (error "You cannot run several timers at the same time")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
328 (setq org-timer-current-timer
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
329 (run-with-timer
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
330 secs nil `(lambda ()
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
331 (setq org-timer-current-timer nil)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
332 (org-notify ,(format "%s: time out" hl) t)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
333 (run-hooks 'org-timer-done-hook))))
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
334 (run-hooks 'org-timer-set-hook)))))
104164
ac1a55cc2c38 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101757
diff changeset
335
101670
a15c11f894f1 2009-01-30 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101607
diff changeset
336 (provide 'org-timer)
a15c11f894f1 2009-01-30 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 101607
diff changeset
337
100269
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
338 ;; arch-tag: 97538f8c-3871-4509-8f23-1e7b3ff3d107
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
339
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
340 ;;; org-timer.el ends here