annotate lisp/org/org-timer.el @ 101183:96e4db45c8a5

(menu-bar-help-extra-packages): Use goto-address-mode instead of goto-address.
author Juri Linkov <juri@jurta.org>
date Wed, 14 Jan 2009 23:11:12 +0000
parents a9dc0e7c3f2b
children 36abe982e7cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1 ;;; org-clock.el --- The time clocking 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
2
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100605
diff changeset
3 ;; Copyright (C) 2008, 2009 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
100605
0d3c634e0bd9 2008-12-20 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100458
diff changeset
8 ;; Version: 6.16
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
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
32 (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
33 "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
34
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 (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
36 "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
37
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
38 (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
39 "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
40 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
41 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
42 :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
43 :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
44
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 ;;;###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
46 (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
47 "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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 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
56 (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
57 (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
58 (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
59 (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
60 (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
61 (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
62 (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
63 ((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
64 ((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
65 (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
66 (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
67 (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
68 "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
69 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
70 (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
71 (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
72 (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
73 (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
74 (seconds-to-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
75 (-
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 (time-to-seconds (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
77 (org-timer-hms-to-secs 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
78 (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
79 (format-time-string "%T" 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
80 (org-timer-secs-to-hms (or delta 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
81
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 ;;;###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
83 (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
84 "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
85 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
86 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
87 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
88 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
89 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
90 (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
91 (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
92 (or org-timer-start-time (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
93 (insert (format
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 org-timer-format
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 (org-timer-secs-to-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
96 (floor
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 (- (time-to-seconds (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
98 (time-to-seconds 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
99
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
100 ;;;###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
101 (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
102 "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
103 (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
104 "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
105 (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
106 (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
107 (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
108 (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
109 (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
110 (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
111 (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
112 (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
113 (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
114 (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
115 (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
116 (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
117 (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
118 (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
119 (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
120 (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
121 (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
122 (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
123 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
124 (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
125
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
126 ;;;###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
127 (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
128 "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
129 (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
130 (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
131 (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
132 (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
133 (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
134 (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
135 (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
136 (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
137 (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
138 (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
139 (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
140 (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
141 (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
142 (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
143
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 (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
145 "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
146 (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
147 (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
148 (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
149 (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
150 (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
151 (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
152 t t hms)
100458
ba23e35d3eaf 2008-12-17 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100448
diff changeset
153 (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
154
032aa24b2125 Checking in the correct versions of the files, sorry, I hade used the files
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
155 (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
156 "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
157 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
158 (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
159 "\\([-+]?[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
160 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
161 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
162 (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
163 (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
164 (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
165 (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
166 (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
167 (* (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
168
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 (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
170 "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
171 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
172 (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
173 (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
174 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
175 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
176 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
177 (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
178
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 ;; 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
180
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 ;;; org-timer.el ends here