Browse Source

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.
Bastien Guerry 15 years ago
parent
commit
3bf121f8b1
2 changed files with 34 additions and 13 deletions
  1. 6 0
      lisp/ChangeLog
  2. 28 13
      lisp/org-timer.el

+ 6 - 0
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

+ 28 - 13
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)