Browse Source

New timer functionality to set a timer from a headline.

This commit defines three new functions in org-timer.el:

- org-timer-set-timer, bound to `C-c C-x ;' in Org buffers
  and to `;' in Org agenda buffers.   This function sets a
  timer for the headline the cursor is currently it.  Up to
  three timers can be set.

- org-timer-show-remaining-time: this shows the remaining
  time for the last set timer.

- org-timer-reset-timers: this reset all timers.

This functionality was requested by Samuel Wales and emulates
that of tea-time.el -- see the emacswiki doc about tea-time.el:

  http://www.emacswiki.org/emacs/tea-time
Bastien Guerry 11 years ago
parent
commit
7cdff7b1eb
4 changed files with 78 additions and 0 deletions
  1. 9 0
      lisp/ChangeLog
  2. 1 0
      lisp/org-agenda.el
  3. 67 0
      lisp/org-timer.el
  4. 1 0
      lisp/org.el

+ 9 - 0
lisp/ChangeLog

@@ -1,5 +1,14 @@
 2009-07-26  Bastien Guerry  <bzg@altern.org>
 
+	* org-agenda.el (org-agenda-mode-map): New key for
+	org-timer-set-timer called from the agenda.
+
+	* org.el (org-mode-map): New key for org-timer-set-timer.
+
+	* org-timer.el (org-timer-reset-timers)
+	(org-timer-show-remaining-time, org-timer-set-timer): New
+	functions.
+
 	* org-clock.el (org-show-notification): Update the docstring.
 
 	* org.el (org-provide-todo-statistics): Allow new value

+ 1 - 0
lisp/org-agenda.el

@@ -1391,6 +1391,7 @@ The following commands are available:
 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
+(org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
 
 (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
   "Local keymap for agenda entries from Org-mode.")

+ 67 - 0
lisp/org-timer.el

@@ -253,6 +253,73 @@ VALUE can be `on', `off', or `pause'."
 	  (concat " <" (substring (org-timer-value-string) 0 -1) ">"))
     (force-mode-line-update)))
 
+(defvar org-timer-timer1 nil)
+(defvar org-timer-timer2 nil)
+(defvar org-timer-timer3 nil)
+
+(defun org-timer-reset-timers ()
+  "Reset all timers."
+  (interactive)
+  (mapcar (lambda(timer) 
+	    (when (eval timer)
+	      (cancel-timer timer)
+	      (setq timer nil)))
+	  '(org-timer-timer1
+	    org-timer-timer2
+	    org-timer-timer3))
+  (message "All timers reset"))
+
+(defun org-timer-show-remaining-time ()
+  "Display the remaining time before the timer ends."
+  (interactive)
+  (require 'time)
+  (if (and (not org-timer-timer1)
+	   (not org-timer-timer2)
+	   (not org-timer-timer3))
+      (message "No timer set")
+    (let* ((rtime (decode-time
+		   (time-subtract (timer--time (or org-timer-timer3
+						   org-timer-timer2
+						   org-timer-timer1))
+				  (current-time))))
+	   (rsecs (nth 0 rtime))
+	   (rmins (nth 1 rtime)))
+      (message "%d minutes %d secondes left before next time out" 
+	       rmins rsecs))))
+
+(defun org-timer-set-timer (minutes)
+  "Set a timer."
+  (interactive "sTime out in (min)? ")
+  (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 
+		((string-match "Org Agenda" (buffer-name))
+		 (let* ((marker (or (get-text-property (point) 'org-marker)
+				    (org-agenda-error)))
+			(hdmarker (or (get-text-property (point) 'org-hd-marker)
+				      marker))
+			(pos (marker-position marker)))
+		   (with-current-buffer (marker-buffer marker)
+		     (widen)
+		     (goto-char pos)
+		     (org-show-entry)
+		     (setq heading (org-get-heading)))))
+		((eq major-mode 'org-mode)
+		 (org-get-heading))
+		(t (error "Not in an Org buffer"))))
+	   timer-set)
+      (mapcar (lambda(timer) 
+		(if (not (or (eval timer) timer-set))
+		    (setq timer-set t
+			  timer
+			  (run-with-timer secs nil 'org-show-notification
+					  (format "%s: time out" hl)))))
+	      '(org-timer-timer1
+		org-timer-timer2
+		org-timer-timer3)))))
+  
 (provide 'org-timer)
 
 ;; arch-tag: 97538f8c-3871-4509-8f23-1e7b3ff3d107

+ 1 - 0
lisp/org.el

@@ -13998,6 +13998,7 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
 (org-defkey org-mode-map "\C-c\C-xp"    'org-set-property)
 (org-defkey org-mode-map "\C-c\C-xo"    'org-toggle-ordered-property)
 (org-defkey org-mode-map "\C-c\C-xi"    'org-insert-columns-dblock)
+(org-defkey org-mode-map [(control ?c) (control ?x) (control ?\;)] 'org-timer-set-timer)
 
 (org-defkey org-mode-map "\C-c\C-x."    'org-timer)
 (org-defkey org-mode-map "\C-c\C-x-"    'org-timer-item)