* calendar/todos.el: Extend and improve item filtering and handling of
[bpt/emacs.git] / lisp / calendar / timeclock.el
index fb4a4c1..2ebb8c7 100644 (file)
@@ -1,7 +1,6 @@
 ;;; timeclock.el --- mode for keeping track of how much you work
 
 ;;; timeclock.el --- mode for keeping track of how much you work
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008  Free Software Foundation, Inc.
+;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 ;; Created: 25 Mar 1999
 
 ;; Author: John Wiegley <johnw@gnu.org>
 ;; Created: 25 Mar 1999
 
 ;; This file is part of GNU Emacs.
 
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; Commentary:
 
 ;;   (define-key ctl-x-map "to" 'timeclock-out)
 ;;   (define-key ctl-x-map "tc" 'timeclock-change)
 ;;   (define-key ctl-x-map "tr" 'timeclock-reread-log)
 ;;   (define-key ctl-x-map "to" 'timeclock-out)
 ;;   (define-key ctl-x-map "tc" 'timeclock-change)
 ;;   (define-key ctl-x-map "tr" 'timeclock-reread-log)
-;;   (define-key ctl-x-map "tu" 'timeclock-update-modeline)
+;;   (define-key ctl-x-map "tu" 'timeclock-update-mode-line)
 ;;   (define-key ctl-x-map "tw" 'timeclock-when-to-leave-string)
 
 ;; If you want Emacs to display the amount of time "left" to your
 ;;   (define-key ctl-x-map "tw" 'timeclock-when-to-leave-string)
 
 ;; If you want Emacs to display the amount of time "left" to your
-;; workday in the modeline, you can either set the value of
-;; `timeclock-modeline-display' to t using M-x customize, or you
-;; can add this code to your .emacs file:
+;; workday in the mode-line, you can either set the value of
+;; `timeclock-mode-line-display' to t using M-x customize, or you can
+;; add this code to your .emacs file:
 ;;
 ;;   (require 'timeclock)
 ;;
 ;;   (require 'timeclock)
-;;   (timeclock-modeline-display)
+;;   (timeclock-mode-line-display)
 ;;
 ;;
-;; To cancel this modeline display at any time, just call
-;; `timeclock-modeline-display' again.
+;; To cancel this mode line display at any time, just call
+;; `timeclock-mode-line-display' again.
 
 ;; You may also want Emacs to ask you before exiting, if you are
 ;; currently working on a project.  This can be done either by setting
 
 ;; You may also want Emacs to ask you before exiting, if you are
 ;; currently working on a project.  This can be done either by setting
@@ -101,7 +98,7 @@ work four hours on Monday, then the amount of time \"remaining\" on
 Tuesday is twelve hours -- relative to an averaged work period of
 eight hours -- or eight hours, non-relative.  So relative time takes
 into account any discrepancy of time under-worked or over-worked on
 Tuesday is twelve hours -- relative to an averaged work period of
 eight hours -- or eight hours, non-relative.  So relative time takes
 into account any discrepancy of time under-worked or over-worked on
-previous days.  This only affects the timeclock modeline display."
+previous days.  This only affects the timeclock mode line display."
   :type 'boolean
   :group 'timeclock)
 
   :type 'boolean
   :group 'timeclock)
 
@@ -148,39 +145,39 @@ This variable only has effect if set with \\[customize]."
 
 ;; For byte-compiler.
 (defvar display-time-hook)
 
 ;; For byte-compiler.
 (defvar display-time-hook)
-(defvar timeclock-modeline-display)
+(defvar timeclock-mode-line-display)
 
 (defcustom timeclock-use-display-time t
 
 (defcustom timeclock-use-display-time t
-  "If non-nil, use `display-time-hook' for doing modeline updates.
+  "If non-nil, use `display-time-hook' for doing mode line updates.
 The advantage of this is that one less timer has to be set running
 The advantage of this is that one less timer has to be set running
-amok in Emacs' process space.  The disadvantage is that it requires
+amok in Emacs's process space.  The disadvantage is that it requires
 you to have `display-time' running.  If you don't want to use
 you to have `display-time' running.  If you don't want to use
-`display-time', but still want the modeline to show how much time is
+`display-time', but still want the mode line to show how much time is
 left, set this variable to nil.  Changing the value of this variable
 left, set this variable to nil.  Changing the value of this variable
-while timeclock information is being displayed in the modeline has no
-effect.  You should call the function `timeclock-modeline-display' with
+while timeclock information is being displayed in the mode line has no
+effect.  You should call the function `timeclock-mode-line-display' with
 a positive argument to force an update."
   :set (lambda (symbol value)
         (let ((currently-displaying
 a positive argument to force an update."
   :set (lambda (symbol value)
         (let ((currently-displaying
-               (and (boundp 'timeclock-modeline-display)
-                    timeclock-modeline-display)))
+               (and (boundp 'timeclock-mode-line-display)
+                    timeclock-mode-line-display)))
           ;; if we're changing to the state that
           ;; if we're changing to the state that
-          ;; `timeclock-modeline-display' is already using, don't
+          ;; `timeclock-mode-line-display' is already using, don't
           ;; bother toggling it.  This happens on the initial loading
           ;; of timeclock.el.
           (if (and currently-displaying
                    (or (and value
                             (boundp 'display-time-hook)
           ;; bother toggling it.  This happens on the initial loading
           ;; of timeclock.el.
           (if (and currently-displaying
                    (or (and value
                             (boundp 'display-time-hook)
-                            (memq 'timeclock-update-modeline
+                            (memq 'timeclock-update-mode-line
                                   display-time-hook))
                        (and (not value)
                             timeclock-update-timer)))
               (setq currently-displaying nil))
           (and currently-displaying
                                   display-time-hook))
                        (and (not value)
                             timeclock-update-timer)))
               (setq currently-displaying nil))
           (and currently-displaying
-               (set-variable 'timeclock-modeline-display nil))
+               (set-variable 'timeclock-mode-line-display nil))
           (setq timeclock-use-display-time value)
           (and currently-displaying
           (setq timeclock-use-display-time value)
           (and currently-displaying
-               (set-variable 'timeclock-modeline-display t))
+               (set-variable 'timeclock-mode-line-display t))
           timeclock-use-display-time))
   :type 'boolean
   :group 'timeclock
           timeclock-use-display-time))
   :type 'boolean
   :group 'timeclock
@@ -208,7 +205,7 @@ to today."
 (defcustom timeclock-day-over-hook nil
   "A hook that is run when the workday has been completed.
 This hook is only run if the current time remaining is being displayed
 (defcustom timeclock-day-over-hook nil
   "A hook that is run when the workday has been completed.
 This hook is only run if the current time remaining is being displayed
-in the modeline.  See the variable `timeclock-modeline-display'."
+in the mode line.  See the variable `timeclock-mode-line-display'."
   :type 'hook
   :group 'timeclock)
 
   :type 'hook
   :group 'timeclock)
 
@@ -254,7 +251,7 @@ worked so far today.  Also, if `timeclock-relative' is nil, this value
 will be the same as `timeclock-discrepancy'.")
 
 (defvar timeclock-use-elapsed nil
 will be the same as `timeclock-discrepancy'.")
 
 (defvar timeclock-use-elapsed nil
-  "Non-nil if the modeline should display time elapsed, not remaining.")
+  "Non-nil if the mode line should display time elapsed, not remaining.")
 
 (defvar timeclock-last-period nil
   "Integer representing the number of seconds in the last period.
 
 (defvar timeclock-last-period nil
   "Integer representing the number of seconds in the last period.
@@ -262,7 +259,7 @@ Note that you shouldn't access this value, but instead should use the
 function `timeclock-last-period'.")
 
 (defvar timeclock-mode-string nil
 function `timeclock-last-period'.")
 
 (defvar timeclock-mode-string nil
-  "The timeclock string (optionally) displayed in the modeline.
+  "The timeclock string (optionally) displayed in the mode line.
 The time is bracketed by <> if you are clocked in, otherwise by [].")
 
 (defvar timeclock-day-over nil
 The time is bracketed by <> if you are clocked in, otherwise by [].")
 
 (defvar timeclock-day-over nil
@@ -270,15 +267,18 @@ The time is bracketed by <> if you are clocked in, otherwise by [].")
 
 ;;; User Functions:
 
 
 ;;; User Functions:
 
+(define-obsolete-function-alias 'timeclock-modeline-display
+  'timeclock-mode-line-display "24.3")
+
 ;;;###autoload
 ;;;###autoload
-(defun timeclock-modeline-display (&optional arg)
-  "Toggle display of the amount of time left today in the modeline.
+(defun timeclock-mode-line-display (&optional arg)
+  "Toggle display of the amount of time left today in the mode line.
 If `timeclock-use-display-time' is non-nil (the default), then
 If `timeclock-use-display-time' is non-nil (the default), then
-the function `display-time-mode' must be active, and the modeline
+the function `display-time-mode' must be active, and the mode line
 will be updated whenever the time display is updated.  Otherwise,
 the timeclock will use its own sixty second timer to do its
 will be updated whenever the time display is updated.  Otherwise,
 the timeclock will use its own sixty second timer to do its
-updating.  With prefix ARG, turn modeline display on if and only
-if ARG is positive.  Returns the new status of timeclock modeline
+updating.  With prefix ARG, turn mode line display on if and only
+if ARG is positive.  Returns the new status of timeclock mode line
 display (non-nil means on)."
   (interactive "P")
   ;; cf display-time-mode.
 display (non-nil means on)."
   (interactive "P")
   ;; cf display-time-mode.
@@ -286,49 +286,49 @@ display (non-nil means on)."
   (or global-mode-string (setq global-mode-string '("")))
   (let ((on-p (if arg
                  (> (prefix-numeric-value arg) 0)
   (or global-mode-string (setq global-mode-string '("")))
   (let ((on-p (if arg
                  (> (prefix-numeric-value arg) 0)
-               (not timeclock-modeline-display))))
+               (not timeclock-mode-line-display))))
     (if on-p
         (progn
           (or (memq 'timeclock-mode-string global-mode-string)
               (setq global-mode-string
                     (append global-mode-string '(timeclock-mode-string))))
     (if on-p
         (progn
           (or (memq 'timeclock-mode-string global-mode-string)
               (setq global-mode-string
                     (append global-mode-string '(timeclock-mode-string))))
-         (unless (memq 'timeclock-update-modeline timeclock-event-hook)
-           (add-hook 'timeclock-event-hook 'timeclock-update-modeline))
+         (add-hook 'timeclock-event-hook 'timeclock-update-mode-line)
          (when timeclock-update-timer
            (cancel-timer timeclock-update-timer)
            (setq timeclock-update-timer nil))
          (if (boundp 'display-time-hook)
          (when timeclock-update-timer
            (cancel-timer timeclock-update-timer)
            (setq timeclock-update-timer nil))
          (if (boundp 'display-time-hook)
-             (remove-hook 'display-time-hook 'timeclock-update-modeline))
+             (remove-hook 'display-time-hook 'timeclock-update-mode-line))
          (if timeclock-use-display-time
               (progn
                 ;; Update immediately so there is a visible change
                 ;; on calling this function.
          (if timeclock-use-display-time
               (progn
                 ;; Update immediately so there is a visible change
                 ;; on calling this function.
-                (if display-time-mode (timeclock-update-modeline)
+                (if display-time-mode
+                   (timeclock-update-mode-line)
                   (message "Activate `display-time-mode' or turn off \
 `timeclock-use-display-time' to see timeclock information"))
                   (message "Activate `display-time-mode' or turn off \
 `timeclock-use-display-time' to see timeclock information"))
-                (add-hook 'display-time-hook 'timeclock-update-modeline))
+                (add-hook 'display-time-hook 'timeclock-update-mode-line))
            (setq timeclock-update-timer
            (setq timeclock-update-timer
-                 (run-at-time nil 60 'timeclock-update-modeline))))
+                 (run-at-time nil 60 'timeclock-update-mode-line))))
       (setq global-mode-string
            (delq 'timeclock-mode-string global-mode-string))
       (setq global-mode-string
            (delq 'timeclock-mode-string global-mode-string))
-      (remove-hook 'timeclock-event-hook 'timeclock-update-modeline)
+      (remove-hook 'timeclock-event-hook 'timeclock-update-mode-line)
       (if (boundp 'display-time-hook)
          (remove-hook 'display-time-hook
       (if (boundp 'display-time-hook)
          (remove-hook 'display-time-hook
-                      'timeclock-update-modeline))
+                      'timeclock-update-mode-line))
       (when timeclock-update-timer
        (cancel-timer timeclock-update-timer)
        (setq timeclock-update-timer nil)))
     (force-mode-line-update)
       (when timeclock-update-timer
        (cancel-timer timeclock-update-timer)
        (setq timeclock-update-timer nil)))
     (force-mode-line-update)
-    (setq timeclock-modeline-display on-p)))
+    (setq timeclock-mode-line-display on-p)))
 
 ;; This has to be here so that the function definition of
 
 ;; This has to be here so that the function definition of
-;; `timeclock-modeline-display' is known to the "set" function.
-(defcustom timeclock-modeline-display nil
-  "Toggle modeline display of time remaining.
+;; `timeclock-mode-line-display' is known to the "set" function.
+(defcustom timeclock-mode-line-display nil
+  "Toggle mode line display of time remaining.
 You must modify via \\[customize] for this variable to have an effect."
   :set (lambda (symbol value)
 You must modify via \\[customize] for this variable to have an effect."
   :set (lambda (symbol value)
-        (setq timeclock-modeline-display
-              (timeclock-modeline-display (or value 0))))
+        (setq timeclock-mode-line-display
+              (timeclock-mode-line-display (or value 0))))
   :type 'boolean
   :group 'timeclock
   :require 'timeclock)
   :type 'boolean
   :group 'timeclock
   :require 'timeclock)
@@ -380,7 +380,8 @@ discover the name of the project."
                                               60 60.0) 60))))))
     (timeclock-log "i" (or project
                           (and timeclock-get-project-function
                                               60 60.0) 60))))))
     (timeclock-log "i" (or project
                           (and timeclock-get-project-function
-                               (or find-project (interactive-p))
+                               (or find-project
+                                   (called-interactively-p 'interactive))
                                (funcall timeclock-get-project-function))))
     (run-hooks 'timeclock-in-hook)))
 
                                (funcall timeclock-get-project-function))))
     (run-hooks 'timeclock-in-hook)))
 
@@ -403,13 +404,13 @@ discover the reason."
      (if arg "O" "o")
      (or reason
         (and timeclock-get-reason-function
      (if arg "O" "o")
      (or reason
         (and timeclock-get-reason-function
-             (or find-reason (interactive-p))
+             (or find-reason (called-interactively-p 'interactive))
              (funcall timeclock-get-reason-function))))
     (run-hooks 'timeclock-out-hook)
     (if arg
        (run-hooks 'timeclock-done-hook))))
 
              (funcall timeclock-get-reason-function))))
     (run-hooks 'timeclock-out-hook)
     (if arg
        (run-hooks 'timeclock-done-hook))))
 
-;; Should today-only be removed in favour of timeclock-relative? - gm
+;; Should today-only be removed in favor of timeclock-relative? - gm
 (defsubst timeclock-workday-remaining (&optional today-only)
   "Return the number of seconds until the workday is complete.
 The amount returned is relative to the value of `timeclock-workday'.
 (defsubst timeclock-workday-remaining (&optional today-only)
   "Return the number of seconds until the workday is complete.
 The amount returned is relative to the value of `timeclock-workday'.
@@ -447,7 +448,7 @@ worked today, ignoring the time worked on previous days."
                  (if (> remainder 0)
                      "remaining" "over")
                  (timeclock-when-to-leave-string show-seconds today-only)))
                  (if (> remainder 0)
                      "remaining" "over")
                  (timeclock-when-to-leave-string show-seconds today-only)))
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
        (message "%s" status)
       status)))
 
        (message "%s" status)
       status)))
 
@@ -460,7 +461,7 @@ time of changeover.  PROJECT is the name of the last project you were
 working on."
   (interactive "P")
   (timeclock-out arg)
 working on."
   (interactive "P")
   (timeclock-out arg)
-  (timeclock-in nil project (interactive-p)))
+  (timeclock-in nil project (called-interactively-p 'interactive)))
 
 ;;;###autoload
 (defun timeclock-query-out ()
 
 ;;;###autoload
 (defun timeclock-query-out ()
@@ -479,8 +480,8 @@ Returns the new value of `timeclock-discrepancy'."
   (interactive)
   (setq timeclock-discrepancy nil)
   (timeclock-find-discrep)
   (interactive)
   (setq timeclock-discrepancy nil)
   (timeclock-find-discrep)
-  (if (and timeclock-discrepancy timeclock-modeline-display)
-      (timeclock-update-modeline))
+  (if (and timeclock-discrepancy timeclock-mode-line-display)
+      (timeclock-update-mode-line))
   timeclock-discrepancy)
 
 (defun timeclock-seconds-to-string (seconds &optional show-seconds
   timeclock-discrepancy)
 
 (defun timeclock-seconds-to-string (seconds &optional show-seconds
@@ -518,7 +519,7 @@ See `timeclock-relative' for more information about the meaning of
   (let ((string (timeclock-seconds-to-string
                 (timeclock-workday-remaining today-only)
                 show-seconds t)))
   (let ((string (timeclock-seconds-to-string
                 (timeclock-workday-remaining today-only)
                 show-seconds t)))
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
        (message "%s" string)
       string)))
 
        (message "%s" string)
       string)))
 
@@ -540,23 +541,16 @@ non-nil, the amount returned will be relative to past time worked."
   (interactive)
   (let ((string (timeclock-seconds-to-string (timeclock-workday-elapsed)
                                             show-seconds)))
   (interactive)
   (let ((string (timeclock-seconds-to-string (timeclock-workday-elapsed)
                                             show-seconds)))
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
        (message "%s" string)
       string)))
 
        (message "%s" string)
       string)))
 
-(defsubst timeclock-time-to-seconds (time)
-  "Convert TIME to a floating point number."
-  (+ (* (car time) 65536.0)
-     (cadr time)
-     (/ (or (car (cdr (cdr time))) 0) 1000000.0)))
+(defalias 'timeclock-time-to-seconds (if (fboundp 'float-time) 'float-time
+                                      'time-to-seconds))
 
 
-(defsubst timeclock-seconds-to-time (seconds)
-  "Convert SECONDS (a floating point number) to an Emacs time structure."
-  (list (floor seconds 65536)
-       (floor (mod seconds 65536))
-       (floor (* (- seconds (ffloor seconds)) 1000000))))
+(defalias 'timeclock-seconds-to-time 'seconds-to-time)
 
 
-;; Should today-only be removed in favour of timeclock-relative? - gm
+;; Should today-only be removed in favor of timeclock-relative? - gm
 (defsubst timeclock-when-to-leave (&optional today-only)
   "Return a time value representing the end of today's workday.
 If TODAY-ONLY is non-nil, the value returned will be relative only to
 (defsubst timeclock-when-to-leave (&optional today-only)
   "Return a time value representing the end of today's workday.
 If TODAY-ONLY is non-nil, the value returned will be relative only to
@@ -578,14 +572,14 @@ This string is relative to the value of `timeclock-workday'.  If
 SHOW-SECONDS is non-nil, the value printed/returned will include
 seconds.  If TODAY-ONLY is non-nil, the value returned will be
 relative only to the time worked today, and not to past time."
 SHOW-SECONDS is non-nil, the value printed/returned will include
 seconds.  If TODAY-ONLY is non-nil, the value returned will be
 relative only to the time worked today, and not to past time."
-  ;; Should today-only be removed in favour of timeclock-relative? - gm
+  ;; Should today-only be removed in favor of timeclock-relative? - gm
   (interactive)
   (let* ((then (timeclock-when-to-leave today-only))
         (string
          (if show-seconds
              (format-time-string "%-I:%M:%S %p" then)
            (format-time-string "%-I:%M %p" then))))
   (interactive)
   (let* ((then (timeclock-when-to-leave today-only))
         (string
          (if show-seconds
              (format-time-string "%-I:%M:%S %p" then)
            (format-time-string "%-I:%M %p" then))))
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
        (message "%s" string)
       string)))
 
        (message "%s" string)
       string)))
 
@@ -632,7 +626,7 @@ PROMPT, ALIST and DEFAULT are used for the PROMPT, COLLECTION and DEF
 arguments of `completing-read'."
   (if (featurep 'xemacs)
       (let ((str (completing-read prompt alist)))
 arguments of `completing-read'."
   (if (featurep 'xemacs)
       (let ((str (completing-read prompt alist)))
-       (if (or (null str) (= (length str) 0))
+       (if (or (null str) (zerop (length str)))
            default
          str))
     (completing-read prompt alist nil nil nil nil default)))
            default
          str))
     (completing-read prompt alist nil nil nil nil default)))
@@ -654,8 +648,11 @@ arguments of `completing-read'."
   (timeclock-completing-read "Reason for clocking out: "
                             (mapcar 'list timeclock-reason-list)))
 
   (timeclock-completing-read "Reason for clocking out: "
                             (mapcar 'list timeclock-reason-list)))
 
-(defun timeclock-update-modeline ()
-  "Update the `timeclock-mode-string' displayed in the modeline.
+(define-obsolete-function-alias 'timeclock-update-modeline
+  'timeclock-update-mode-line "24.3")
+
+(defun timeclock-update-mode-line ()
+  "Update the `timeclock-mode-string' displayed in the mode line.
 The value of `timeclock-relative' affects the display as described in
 that variable's documentation."
   (interactive)
 The value of `timeclock-relative' affects the display as described in
 that variable's documentation."
   (interactive)
@@ -833,14 +830,14 @@ This is only provided for coherency when used by
 
 (defsubst timeclock-day-projects (day)
   "Return a list of all the projects in DAY."
 
 (defsubst timeclock-day-projects (day)
   "Return a list of all the projects in DAY."
-  (timeclock-entry-list-projects (cdr day)))
+  (timeclock-entry-list-projects (cddr day)))
 
 (defmacro timeclock-day-list-template (func)
   "Template for summing the result of FUNC on each element of DAY-LIST."
   `(let ((length 0))
      (while day-list
 
 (defmacro timeclock-day-list-template (func)
   "Template for summing the result of FUNC on each element of DAY-LIST."
   `(let ((length 0))
      (while day-list
-       (setq length (+ length (,(eval func) (car day-list))))
-       (setq day-list (cdr day-list)))
+       (setq length (+ length (,(eval func) (car day-list)))
+            day-list (cdr day-list)))
      length))
 
 (defun timeclock-day-list-required (day-list)
      length))
 
 (defun timeclock-day-list-required (day-list)
@@ -1030,11 +1027,10 @@ lists:
   timeclock-current-debt LOG-DATA
 
 See the documentation for the given function if more info is needed."
   timeclock-current-debt LOG-DATA
 
 See the documentation for the given function if more info is needed."
-  (let* ((log-data (list 0.0 nil nil))
-        (now (current-time))
-        (todays-date (timeclock-time-to-date now))
-        last-date-limited last-date-seconds last-date
-        (line 0) last beg day entry event)
+  (let ((log-data (list 0.0 nil nil))
+       (now (current-time))
+       last-date-limited last-date-seconds last-date
+       (line 0) last beg day entry event)
     (with-temp-buffer
       (insert-file-contents (or filename timeclock-file))
       (when recent-only
     (with-temp-buffer
       (insert-file-contents (or filename timeclock-file))
       (when recent-only
@@ -1091,7 +1087,7 @@ See the documentation for the given function if more info is needed."
                   (if (null proj)
                       (setcar (cddr log-data)
                               (cons (cons desc (list entry))
                   (if (null proj)
                       (setcar (cddr log-data)
                               (cons (cons desc (list entry))
-                                    (car (cddr log-data))))
+                                    (nth 2 log-data)))
                     (nconc (cdr proj) (list entry)))))))
        (forward-line))
       (if day
                     (nconc (cdr proj) (list entry)))))))
        (forward-line))
       (if day
@@ -1120,7 +1116,7 @@ discrepancy, today's discrepancy, and the time worked today."
   (let* ((now (current-time))
         (todays-date (timeclock-time-to-date now))
         (first t) (accum 0) (elapsed 0)
   (let* ((now (current-time))
         (todays-date (timeclock-time-to-date now))
         (first t) (accum 0) (elapsed 0)
-        event beg last-date avg
+        event beg last-date
         last-date-limited last-date-seconds)
     (unless timeclock-discrepancy
       (when (file-readable-p timeclock-file)
         last-date-limited last-date-seconds)
     (unless timeclock-discrepancy
       (when (file-readable-p timeclock-file)
@@ -1210,13 +1206,12 @@ If optional argument TIME is non-nil, use that instead of the current time."
   "Compute the arithmetic mean of the values in the list L."
   (let ((total 0)
        (count 0))
   "Compute the arithmetic mean of the values in the list L."
   (let ((total 0)
        (count 0))
-    (while l
-      (setq total (+ total (car l))
-           count (1+ count)
-           l (cdr l)))
-    (if (> count 0)
-       (/ total count)
-      0)))
+    (dolist (thisl l)
+      (setq total (+ total thisl)
+           count (1+ count)))
+    (if (zerop count)
+       0
+      (/ total count))))
 
 (defun timeclock-generate-report (&optional html-p)
   "Generate a summary report based on the current timelog file.
 
 (defun timeclock-generate-report (&optional html-p)
   "Generate a summary report based on the current timelog file.
@@ -1232,7 +1227,7 @@ HTML-P is non-nil, HTML markup is added."
          done)
       (if (timeclock-currently-in-p)
          (insert "IN")
          done)
       (if (timeclock-currently-in-p)
          (insert "IN")
-       (if (or (null project) (= (length project) 0))
+       (if (zerop (length project))
            (progn (insert "Done Working Today")
                   (setq done t))
          (insert "OUT")))
            (progn (insert "Done Working Today")
                   (setq done t))
          (insert "OUT")))
@@ -1319,22 +1314,22 @@ HTML-P is non-nil, HTML markup is added."
               (lengths  (vector '(0 0) thirty-days-ago three-months-ago
                                 six-months-ago one-year-ago)))
          ;; collect statistics from complete timelog
               (lengths  (vector '(0 0) thirty-days-ago three-months-ago
                                 six-months-ago one-year-ago)))
          ;; collect statistics from complete timelog
-         (while day-list
+         (dolist (day day-list)
            (let ((i 0) (l 5))
              (while (< i l)
                (unless (time-less-p
            (let ((i 0) (l 5))
              (while (< i l)
                (unless (time-less-p
-                        (timeclock-day-begin (car day-list))
+                        (timeclock-day-begin day)
                         (aref lengths i))
                  (let ((base (timeclock-time-to-seconds
                               (timeclock-day-base
                         (aref lengths i))
                  (let ((base (timeclock-time-to-seconds
                               (timeclock-day-base
-                               (timeclock-day-begin (car day-list))))))
+                               (timeclock-day-begin day)))))
                    (nconc (aref time-in i)
                           (list (- (timeclock-time-to-seconds
                    (nconc (aref time-in i)
                           (list (- (timeclock-time-to-seconds
-                                    (timeclock-day-begin (car day-list)))
+                                    (timeclock-day-begin day))
                                    base)))
                                    base)))
-                   (let ((span (timeclock-day-span (car day-list)))
-                         (len (timeclock-day-length (car day-list)))
-                         (req (timeclock-day-required (car day-list))))
+                   (let ((span (timeclock-day-span day))
+                         (len (timeclock-day-length day))
+                         (req (timeclock-day-required day)))
                      ;; If the day's actual work length is less than
                      ;; 70% of its span, then likely the exit time
                      ;; and break amount are not worthwhile adding to
                      ;; If the day's actual work length is less than
                      ;; 70% of its span, then likely the exit time
                      ;; and break amount are not worthwhile adding to
@@ -1343,14 +1338,13 @@ HTML-P is non-nil, HTML markup is added."
                                 (> (/ (float len) (float span)) 0.70))
                        (nconc (aref time-out i)
                               (list (- (timeclock-time-to-seconds
                                 (> (/ (float len) (float span)) 0.70))
                        (nconc (aref time-out i)
                               (list (- (timeclock-time-to-seconds
-                                        (timeclock-day-end (car day-list)))
+                                        (timeclock-day-end day))
                                        base)))
                        (nconc (aref breaks i) (list (- span len))))
                      (if req
                          (setq len (+ len (- timeclock-workday req))))
                      (nconc (aref workday i) (list len)))))
                                        base)))
                        (nconc (aref breaks i) (list (- span len))))
                      (if req
                          (setq len (+ len (- timeclock-workday req))))
                      (nconc (aref workday i) (list len)))))
-               (setq i (1+ i))))
-           (setq day-list (cdr day-list)))
+               (setq i (1+ i)))))
          ;; average statistics
          (let ((i 0) (l 5))
            (while (< i l)
          ;; average statistics
          (let ((i 0) (l 5))
            (while (< i l)
@@ -1422,5 +1416,4 @@ HTML-P is non-nil, HTML markup is added."
 (if (file-readable-p timeclock-file)
     (timeclock-reread-log))
 
 (if (file-readable-p timeclock-file)
     (timeclock-reread-log))
 
-;; arch-tag: a0be3377-deb6-44ec-b9a2-a7be28436a40
 ;;; timeclock.el ends here
 ;;; timeclock.el ends here