diff options
| author | Carsten Dominik | 2010-11-11 22:10:19 -0600 |
|---|---|---|
| committer | Carsten Dominik | 2010-11-11 22:10:19 -0600 |
| commit | afe98dfa700de5cf0493e8bf95b7d894e2734e47 (patch) | |
| tree | 92a812b353bb09c1286e8a44fb552de9f1af3384 /lisp/org/org-timer.el | |
| parent | df26e1f58a7e484b7ed500ea48d0e1c49345ffbf (diff) | |
| download | emacs-afe98dfa700de5cf0493e8bf95b7d894e2734e47.tar.gz emacs-afe98dfa700de5cf0493e8bf95b7d894e2734e47.zip | |
Install org-mode version 7.3
Diffstat (limited to 'lisp/org/org-timer.el')
| -rw-r--r-- | lisp/org/org-timer.el | 84 |
1 files changed, 51 insertions, 33 deletions
diff --git a/lisp/org/org-timer.el b/lisp/org/org-timer.el index b773274e93b..6c1f4984cf1 100644 --- a/lisp/org/org-timer.el +++ b/lisp/org/org-timer.el | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | ;; Author: Carsten Dominik <carsten at orgmode dot org> | 5 | ;; Author: Carsten Dominik <carsten at orgmode dot org> |
| 6 | ;; Keywords: outlines, hypermedia, calendar, wp | 6 | ;; Keywords: outlines, hypermedia, calendar, wp |
| 7 | ;; Homepage: http://orgmode.org | 7 | ;; Homepage: http://orgmode.org |
| 8 | ;; Version: 7.01 | 8 | ;; Version: 7.3 |
| 9 | ;; | 9 | ;; |
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | ;; | 11 | ;; |
| @@ -31,7 +31,7 @@ | |||
| 31 | 31 | ||
| 32 | (require 'org) | 32 | (require 'org) |
| 33 | 33 | ||
| 34 | (declare-function org-show-notification "org-clock" (parameters)) | 34 | (declare-function org-notify "org-clock" (notification &optional play-sound)) |
| 35 | (declare-function org-agenda-error "org-agenda" ()) | 35 | (declare-function org-agenda-error "org-agenda" ()) |
| 36 | 36 | ||
| 37 | (defvar org-timer-start-time nil | 37 | (defvar org-timer-start-time nil |
| @@ -145,25 +145,33 @@ With prefix arg STOP, stop it entirely." | |||
| 145 | (org-timer-set-mode-line 'off)) | 145 | (org-timer-set-mode-line 'off)) |
| 146 | 146 | ||
| 147 | ;;;###autoload | 147 | ;;;###autoload |
| 148 | (defun org-timer (&optional restart) | 148 | (defun org-timer (&optional restart no-insert-p) |
| 149 | "Insert a H:MM:SS string from the timer into the buffer. | 149 | "Insert a H:MM:SS string from the timer into the buffer. |
| 150 | The first time this command is used, the timer is started. When used with | 150 | The first time this command is used, the timer is started. When used with |
| 151 | a \\[universal-argument] prefix, force restarting the timer. | 151 | a \\[universal-argument] prefix, force restarting the timer. |
| 152 | When used with a double prefix argument \ | 152 | When used with a double prefix argument \\[universal-argument], change all the timer string |
| 153 | \\[universal-argument] \\universal-argument], change all the timer string | ||
| 154 | in the region by a fixed amount. This can be used to recalibrate a timer | 153 | in the region by a fixed amount. This can be used to recalibrate a timer |
| 155 | that was not started at the correct moment." | 154 | that was not started at the correct moment. |
| 155 | |||
| 156 | If NO-INSERT-P is non-nil, return the string instead of inserting | ||
| 157 | it in the buffer." | ||
| 156 | (interactive "P") | 158 | (interactive "P") |
| 157 | (if (equal restart '(4)) (org-timer-start)) | 159 | (when (or (equal restart '(4)) (not org-timer-start-time)) |
| 158 | (or org-timer-start-time (org-timer-start)) | 160 | (org-timer-start)) |
| 159 | (insert (org-timer-value-string))) | 161 | (if no-insert-p |
| 162 | (org-timer-value-string) | ||
| 163 | (insert (org-timer-value-string)))) | ||
| 160 | 164 | ||
| 161 | (defun org-timer-value-string () | 165 | (defun org-timer-value-string () |
| 162 | (format org-timer-format (org-timer-secs-to-hms (floor (org-timer-seconds))))) | 166 | (format org-timer-format (org-timer-secs-to-hms (floor (org-timer-seconds))))) |
| 163 | 167 | ||
| 168 | (defvar org-timer-timer-is-countdown nil) | ||
| 164 | (defun org-timer-seconds () | 169 | (defun org-timer-seconds () |
| 165 | (- (org-float-time (or org-timer-pause-time (current-time))) | 170 | (if org-timer-timer-is-countdown |
| 166 | (org-float-time org-timer-start-time))) | 171 | (- (org-float-time org-timer-start-time) |
| 172 | (org-float-time (current-time))) | ||
| 173 | (- (org-float-time (or org-timer-pause-time (current-time))) | ||
| 174 | (org-float-time org-timer-start-time)))) | ||
| 167 | 175 | ||
| 168 | ;;;###autoload | 176 | ;;;###autoload |
| 169 | (defun org-timer-change-times-in-region (beg end delta) | 177 | (defun org-timer-change-times-in-region (beg end delta) |
| @@ -195,19 +203,22 @@ that was not started at the correct moment." | |||
| 195 | (defun org-timer-item (&optional arg) | 203 | (defun org-timer-item (&optional arg) |
| 196 | "Insert a description-type item with the current timer value." | 204 | "Insert a description-type item with the current timer value." |
| 197 | (interactive "P") | 205 | (interactive "P") |
| 198 | (let ((ind 0)) | 206 | (cond |
| 199 | (save-excursion | 207 | ;; In a timer list, insert with `org-list-insert-item-generic'. |
| 200 | (skip-chars-backward " \n\t") | 208 | ((and (org-in-item-p) |
| 201 | (condition-case nil | 209 | (save-excursion (org-beginning-of-item) (org-at-item-timer-p))) |
| 202 | (progn | 210 | (org-list-insert-item-generic |
| 203 | (org-beginning-of-item) | 211 | (point) nil (concat (org-timer (when arg '(4)) t) ":: "))) |
| 204 | (setq ind (org-get-indentation))) | 212 | ;; In a list of another type, don't break anything: throw an error. |
| 205 | (error nil))) | 213 | ((org-in-item-p) |
| 206 | (or (bolp) (newline)) | 214 | (error "This is not a timer list")) |
| 207 | (org-indent-line-to ind) | 215 | ;; Else, insert the timer correctly indented at bol. |
| 208 | (insert "- ") | 216 | (t |
| 209 | (org-timer (if arg '(4))) | 217 | (beginning-of-line) |
| 210 | (insert ":: "))) | 218 | (org-indent-line-function) |
| 219 | (insert "- ") | ||
| 220 | (org-timer (when arg '(4))) | ||
| 221 | (insert ":: ")))) | ||
| 211 | 222 | ||
| 212 | (defun org-timer-fix-incomplete (hms) | 223 | (defun org-timer-fix-incomplete (hms) |
| 213 | "If hms is a H:MM:SS string with missing hour or hour and minute, fix it." | 224 | "If hms is a H:MM:SS string with missing hour or hour and minute, fix it." |
| @@ -292,7 +303,9 @@ VALUE can be `on', `off', or `pause'." | |||
| 292 | (when (eval org-timer-current-timer) | 303 | (when (eval org-timer-current-timer) |
| 293 | (run-hooks 'org-timer-cancel-hook) | 304 | (run-hooks 'org-timer-cancel-hook) |
| 294 | (cancel-timer org-timer-current-timer) | 305 | (cancel-timer org-timer-current-timer) |
| 295 | (setq org-timer-current-timer nil)) | 306 | (setq org-timer-current-timer nil) |
| 307 | (setq org-timer-timer-is-countdown nil) | ||
| 308 | (org-timer-set-mode-line 'off)) | ||
| 296 | (message "Last timer canceled")) | 309 | (message "Last timer canceled")) |
| 297 | 310 | ||
| 298 | (defun org-timer-show-remaining-time () | 311 | (defun org-timer-show-remaining-time () |
| @@ -309,17 +322,13 @@ VALUE can be `on', `off', or `pause'." | |||
| 309 | (message "%d minute(s) %d seconds left before next time out" | 322 | (message "%d minute(s) %d seconds left before next time out" |
| 310 | rmins rsecs)))) | 323 | rmins rsecs)))) |
| 311 | 324 | ||
| 312 | (defun bzg-test (&optional test) | ||
| 313 | (interactive "P") | ||
| 314 | test) | ||
| 315 | |||
| 316 | ;;;###autoload | 325 | ;;;###autoload |
| 317 | (defun org-timer-set-timer (&optional opt) | 326 | (defun org-timer-set-timer (&optional opt) |
| 318 | "Prompt for a duration and set a timer. | 327 | "Prompt for a duration and set a timer. |
| 319 | 328 | ||
| 320 | If `org-timer-default-timer' is not zero, suggest this value as | 329 | If `org-timer-default-timer' is not zero, suggest this value as |
| 321 | the default duration for the timer. If a timer is already set, | 330 | the default duration for the timer. If a timer is already set, |
| 322 | prompt the use if she wants to replace it. | 331 | prompt the user if she wants to replace it. |
| 323 | 332 | ||
| 324 | Called with a numeric prefix argument, use this numeric value as | 333 | Called with a numeric prefix argument, use this numeric value as |
| 325 | the duration of the timer. | 334 | the duration of the timer. |
| @@ -353,9 +362,11 @@ replace any running timer." | |||
| 353 | (widen) | 362 | (widen) |
| 354 | (goto-char pos) | 363 | (goto-char pos) |
| 355 | (org-show-entry) | 364 | (org-show-entry) |
| 356 | (org-get-heading)))) | 365 | (or (ignore-errors (org-get-heading)) |
| 366 | (concat "File:" (file-name-nondirectory (buffer-file-name))))))) | ||
| 357 | ((eq major-mode 'org-mode) | 367 | ((eq major-mode 'org-mode) |
| 358 | (org-get-heading)) | 368 | (or (ignore-errors (org-get-heading)) |
| 369 | (concat "File:" (file-name-nondirectory (buffer-file-name))))) | ||
| 359 | (t (error "Not in an Org buffer")))) | 370 | (t (error "Not in an Org buffer")))) |
| 360 | timer-set) | 371 | timer-set) |
| 361 | (if (or (and org-timer-current-timer | 372 | (if (or (and org-timer-current-timer |
| @@ -363,6 +374,7 @@ replace any running timer." | |||
| 363 | (y-or-n-p "Replace current timer? "))) | 374 | (y-or-n-p "Replace current timer? "))) |
| 364 | (not org-timer-current-timer)) | 375 | (not org-timer-current-timer)) |
| 365 | (progn | 376 | (progn |
| 377 | (require 'org-clock) | ||
| 366 | (when org-timer-current-timer | 378 | (when org-timer-current-timer |
| 367 | (cancel-timer org-timer-current-timer)) | 379 | (cancel-timer org-timer-current-timer)) |
| 368 | (setq org-timer-current-timer | 380 | (setq org-timer-current-timer |
| @@ -370,8 +382,14 @@ replace any running timer." | |||
| 370 | secs nil `(lambda () | 382 | secs nil `(lambda () |
| 371 | (setq org-timer-current-timer nil) | 383 | (setq org-timer-current-timer nil) |
| 372 | (org-notify ,(format "%s: time out" hl) t) | 384 | (org-notify ,(format "%s: time out" hl) t) |
| 385 | (setq org-timer-timer-is-countdown nil) | ||
| 386 | (org-timer-set-mode-line 'off) | ||
| 373 | (run-hooks 'org-timer-done-hook)))) | 387 | (run-hooks 'org-timer-done-hook)))) |
| 374 | (run-hooks 'org-timer-set-hook)) | 388 | (run-hooks 'org-timer-set-hook) |
| 389 | (setq org-timer-timer-is-countdown t | ||
| 390 | org-timer-start-time | ||
| 391 | (time-add (current-time) (seconds-to-time (* mins 60)))) | ||
| 392 | (org-timer-set-mode-line 'on)) | ||
| 375 | (message "No timer set")))))) | 393 | (message "No timer set")))))) |
| 376 | 394 | ||
| 377 | (provide 'org-timer) | 395 | (provide 'org-timer) |