summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2010-05-20 16:16:31 +0200
committerBastien Guerry <bzg@altern.org>2010-05-20 16:16:31 +0200
commit3bf121f8b1086ee2ce6baf575bc56bc636402e81 (patch)
tree3f7e16d14973da7c6cbfc19dd81045ae7da84bf3
parentcc47da0acb7dd9c4b66b38ca021a4f707f305535 (diff)
downloadorg-mode-3bf121f8b1086ee2ce6baf575bc56bc636402e81.tar.gz
Define and use a new variable: org-timer-default-timer
This variable defaults to nil. When non-nil, this is the default value when the user is prompted for a timer. This patch also improves org-timer-set-timer so that the user can replace the current timer by a new one.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/org-timer.el41
2 files changed, 34 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index cbc1e70..57f46f4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2010-05-20 Bastien Guerry <bzg@altern.org>
+
+ * org-timer.el (org-timer-default-timer): New variable.
+ (org-timer-set-timer): Use the new variable. Also offer the
+ possibility to replace the current timer by a new one.
+
2010-05-20 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-kill-note-or-show-branches): Hide subtree before
diff --git a/lisp/org-timer.el b/lisp/org-timer.el
index b745dc9..e1c039b 100644
--- a/lisp/org-timer.el
+++ b/lisp/org-timer.el
@@ -48,6 +48,12 @@ the value of the relative timer."
:group 'org-time
:type 'string)
+(defcustom org-timer-default-timer nil
+ "The default timer when a timer is set.
+When nil, the user is prompted for a value."
+ :group 'org-time
+ :type 'string)
+
(defvar org-timer-start-hook nil
"Hook run after relative timer is started.")
@@ -300,11 +306,16 @@ VALUE can be `on', `off', or `pause'."
rmins rsecs))))
;;;###autoload
-(defun org-timer-set-timer (minutes)
+(defun org-timer-set-timer ()
"Set a timer."
- (interactive "sTime out in (min)? ")
- (if (not (string-match "[0-9]+" minutes))
- (org-timer-show-remaining-time)
+ (interactive)
+ (let ((minutes
+ (read-from-minibuffer
+ "How many minutes left? "
+ (if org-timer-default-timer
+ (number-to-string org-timer-default-timer)))))
+ (if (not (string-match "[0-9]+" minutes))
+ (org-timer-show-remaining-time)
(let* ((mins (string-to-number (match-string 0 minutes)))
(secs (* mins 60))
(hl (cond
@@ -323,15 +334,19 @@ VALUE can be `on', `off', or `pause'."
(org-get-heading))
(t (error "Not in an Org buffer"))))
timer-set)
- (if org-timer-current-timer
- (error "You cannot run several timers at the same time")
- (setq org-timer-current-timer
- (run-with-timer
- secs nil `(lambda ()
- (setq org-timer-current-timer nil)
- (org-notify ,(format "%s: time out" hl) t)
- (run-hooks 'org-timer-done-hook))))
- (run-hooks 'org-timer-set-hook)))))
+ (if (or (and org-timer-current-timer
+ (y-or-n-p "Replace current timer? "))
+ (not org-timer-current-timer))
+ (progn
+ (cancel-timer org-timer-current-timer)
+ (setq org-timer-current-timer
+ (run-with-timer
+ secs nil `(lambda ()
+ (setq org-timer-current-timer nil)
+ (org-notify ,(format "%s: time out" hl) t)
+ (run-hooks 'org-timer-done-hook))))
+ (run-hooks 'org-timer-set-hook))
+ (message "No timer set"))))))
(provide 'org-timer)