Remove incorrect uses of "modeline".
[bpt/emacs.git] / lisp / calendar / timeclock.el
index 9b223e3..8ca14b3 100644 (file)
@@ -1,7 +1,6 @@
 ;;; 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
 ;;   (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
-;; 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)
-;;   (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
@@ -99,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
-previous days.  This only affects the timeclock modeline display."
+previous days.  This only affects the timeclock mode line display."
   :type 'boolean
   :group 'timeclock)
 
@@ -146,39 +145,39 @@ This variable only has effect if set with \\[customize]."
 
 ;; For byte-compiler.
 (defvar display-time-hook)
-(defvar timeclock-modeline-display)
+(defvar timeclock-mode-line-display)
 
 (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
-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
-`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
-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
-               (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
-          ;; `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)
-                            (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
-               (set-variable 'timeclock-modeline-display nil))
+               (set-variable 'timeclock-mode-line-display nil))
           (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
@@ -206,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
-in the modeline.  See the variable `timeclock-modeline-display'."
+in the mode line.  See the variable `timeclock-mode-line-display'."
   :type 'hook
   :group 'timeclock)
 
@@ -252,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
-  "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.
@@ -260,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
-  "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
@@ -268,15 +267,18 @@ The time is bracketed by <> if you are clocked in, otherwise by [].")
 
 ;;; User Functions:
 
+(define-obsolete-function-alias 'timeclock-modeline-display
+  'timeclock-mode-line-display "24.2")
+
 ;;;###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
-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
-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.
@@ -284,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)
-               (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))))
-         (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)
-             (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 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"))
-                (add-hook 'display-time-hook 'timeclock-update-modeline))
+                (add-hook 'display-time-hook 'timeclock-update-mode-line))
            (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))
-      (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
-                      '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)
-    (setq timeclock-modeline-display on-p)))
+    (setq timeclock-mode-line-display on-p)))
 
 ;; 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)
-        (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)
@@ -378,7 +380,8 @@ discover the name of the project."
                                               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)))
 
@@ -401,13 +404,13 @@ discover the reason."
      (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))))
 
-;; 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'.
@@ -445,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 (interactive-p)
+    (if (called-interactively-p 'interactive)
        (message "%s" status)
       status)))
 
@@ -458,7 +461,7 @@ time of changeover.  PROJECT is the name of the last project you were
 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 ()
@@ -477,8 +480,8 @@ Returns the new value of `timeclock-discrepancy'."
   (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
@@ -516,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)))
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
        (message "%s" string)
       string)))
 
@@ -538,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)))
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
        (message "%s" string)
       string)))
 
-(defsubst timeclock-time-to-seconds (time)
-  "Convert TIME to a floating point number."
-  (+ (* (car time) 65536.0)
-     (cadr time)
-     (/ (or (nth 2 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
@@ -576,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."
-  ;; 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))))
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
        (message "%s" string)
       string)))
 
@@ -652,8 +648,11 @@ arguments of `completing-read'."
   (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.2")
+
+(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)
@@ -1028,11 +1027,10 @@ lists:
   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
@@ -1118,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)
-        event beg last-date avg
+        event beg last-date
         last-date-limited last-date-seconds)
     (unless timeclock-discrepancy
       (when (file-readable-p timeclock-file)
@@ -1418,5 +1416,4 @@ HTML-P is non-nil, HTML markup is added."
 (if (file-readable-p timeclock-file)
     (timeclock-reread-log))
 
-;; arch-tag: a0be3377-deb6-44ec-b9a2-a7be28436a40
 ;;; timeclock.el ends here