[PATCH] timeclock.el: Improve error detection and reporting, intro timeclock-use-history

Adrian Aichner adrian
Mon Oct 16 17:25:18 EDT 2006


The following message is a courtesy copy of an article
that has been posted to gmane.emacs.planner.general as well.


Hello Timeclocker, how about this?

I have been running with
(setq timeclock-use-history t)
for a few days and so far I like the added functionality of having
previous timestamp data around.

I find myself adjusting clockin and clockout times more often than
not, due to my micro-procrastination tendencies.

Would be great if this could be applied.

BTW, who is the canonical maintainer of timeclock.el these days?

Best regards!

Adrian

ChangeLog addition:

2006-10-16  Adrian Aichner  <adrian at xemacs.org>

        * timeclock.el: Typo fixes.
        * timeclock.el (timeclock-history): New.
        * timeclock.el (timeclock-use-history): New.
        * timeclock.el (timeclock-log): Honor timeclock-use-history.
        * timeclock.el (timeclock-read-moment): Provide error on
        unexpected data in timeclock-file, going unnoticed until now.
        * timeclock.el (timeclock-find-discrep): Report line number of
        discrepancy to ease manual fixing.

This patch generated by
tla file-diff timeclock.el

--- orig/contrib/timeclock.el
+++ mod/contrib/timeclock.el
@@ -1,7 +1,7 @@
 ;;; timeclock.el --- mode for keeping track of how much you work
 
 ;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
-;; Parts copyright (C) 2006 Aidrian Aichner
+;; Parts copyright (C) 2006 Adrian Aichner
 
 ;; Author: John Wiegley <johnw at gnu.org>
 ;; Created: 25 Mar 1999
@@ -99,7 +99,7 @@
   (error "Do not use this version of timeclock.el with Emacs"))
 
 (defgroup timeclock nil
-  "Keeping track time of the time that gets spent."
+  "Keeping track of the time that gets spent."
   :group 'data)
 
 ;;; User Variables:
@@ -163,6 +163,19 @@
   :type 'boolean
   :group 'timeclock)
 
+(defvar timeclock-history '()
+  "History of previously used timeclock values.")
+
+(defcustom timeclock-use-history nil
+  "*If non-nil, user is prompted for timestamp, previous values are
+available via history mechanism.
+
+\\{minibuffer-local-map}.
+
+This variable only has effect if set with \\[customize]."
+:type 'boolean
+:group 'timeclock)
+
 (defvar timeclock-update-timer nil
   "The timer used to update `timeclock-mode-string'.")
 
@@ -692,7 +705,12 @@
 	(insert "\n"))
     (let ((now (current-time)))
       (insert code " "
-	      (format-time-string "%Y/%m/%d %H:%M:%S" now)
+	      (if timeclock-use-history
+		  (read-string "timeclock time: "
+			       (format-time-string "%Y/%m/%d %H:%M:%S" now)
+			       'timeclock-history
+			       (format-time-string "%Y/%m/%d %H:%M:%S" now))
+		(format-time-string "%Y/%m/%d %H:%M:%S" now))
 	      (or (and project
 		       (stringp project)
 		       (> (length project) 0)
@@ -722,16 +740,23 @@
 
 (defsubst timeclock-read-moment ()
   "Read the moment under point from the timelog."
-  (if (looking-at timeclock-moment-regexp)
-      (let ((code (match-string 1))
-	    (year (string-to-number (match-string 2)))
-	    (mon  (string-to-number (match-string 3)))
-	    (mday (string-to-number (match-string 4)))
-	    (hour (string-to-number (match-string 5)))
-	    (min  (string-to-number (match-string 6)))
-	    (sec  (string-to-number (match-string 7)))
-	    (project (match-string 8)))
-	(list code (encode-time sec min hour mday mon year) project))))
+  (cond
+   ((looking-at timeclock-moment-regexp)
+    (let ((code (match-string 1))
+	  (year (string-to-number (match-string 2)))
+	  (mon  (string-to-number (match-string 3)))
+	  (mday (string-to-number (match-string 4)))
+	  (hour (string-to-number (match-string 5)))
+	  (min  (string-to-number (match-string 6)))
+	  (sec  (string-to-number (match-string 7)))
+	  (project (match-string 8)))
+      (list code (encode-time sec min hour mday mon year) project)))
+   ((not (eobp))
+    (error "unexpected data in %s: %s"
+	   timeclock-file
+	   (buffer-substring
+	    (point-at-bol)
+	    (point-at-eol))))))
 
 (defun timeclock-last-period (&optional moment)
   "Return the value of the last event period.
@@ -1098,7 +1123,8 @@
   ;;    total)
   (let* ((now (current-time))
 	 (todays-date (timeclock-time-to-date now))
-	 (first t) (accum 0) (elapsed 0)
+	 ;; XEmacs change
+	 (first t) (accum 0) (elapsed 0) (line 0)
 	 event beg last-date avg
 	 last-date-limited last-date-seconds)
     (unless timeclock-discrepancy
@@ -1114,6 +1140,8 @@
 	  (unless (re-search-backward "^b\\s-+" nil t)
 	    (goto-char (point-min)))
 	  (while (setq event (timeclock-read-moment))
+	    ;; XEmacs change
+	    (setq line (1+ line))
 	    (cond ((equal (car event) "b")
 		   (setq accum (string-to-number (nth 2 event))))
 		  ((equal (car event) "h")
@@ -1137,14 +1165,16 @@
 		     (setq last-date date
 			   last-date-limited nil)
 		     (if beg
-			 (error "Error in format of timelog file!")
+			 ;; XEmacs change
+			 (error "Error in format of timelog file, line %d" line)
 		       (setq beg (timeclock-time-to-seconds (cadr event))))))
 		  ((equal (downcase (car event)) "o")
 		   (if (and (nth 2 event)
 			    (> (length (nth 2 event)) 0))
 		       (add-to-list 'timeclock-reason-list (nth 2 event)))
 		   (if (not beg)
-		       (error "Error in format of timelog file!")
+		       ;; XEmacs change
+		       (error "Error in format of timelog file, line %d" line)
 		     (setq timeclock-last-period
 			   (- (timeclock-time-to-seconds (cadr event)) beg)
 			   accum (+ timeclock-last-period accum)

-- 
Adrian Aichner
 mailto:adrian at xemacs.org
 http://www.xemacs.org/



More information about the XEmacs-Beta mailing list