]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/calendar/timeclock.el: Minor cleanups.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 22 Aug 2013 01:09:08 +0000 (21:09 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 22 Aug 2013 01:09:08 +0000 (21:09 -0400)
(timeclock-ask-before-exiting, timeclock-use-display-time): Use `symbol'.
(timeclock-modeline-display): Define as alias before the actual definition.
(timeclock-mode-line-display): Use define-minor-mode.
(timeclock-day-list-template): Make it a function, add an argument.
(timeclock-day-list-required, timeclock-day-list-length)
(timeclock-day-list-debt, timeclock-day-list-span)
(timeclock-day-list-break): Adjust calls accordingly.

lisp/ChangeLog
lisp/calendar/timeclock.el

index d8bae263da2775f33ef8997be53c984c70cdb337..0bba2e5fb5863462b446fb063fe043513e13347e 100644 (file)
@@ -1,3 +1,16 @@
+2013-08-22  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * calendar/timeclock.el: Minor cleanups.
+       (timeclock-ask-before-exiting, timeclock-use-display-time):
+       Use `symbol'.
+       (timeclock-modeline-display): Define as alias before the
+       actual definition.
+       (timeclock-mode-line-display): Use define-minor-mode.
+       (timeclock-day-list-template): Make it a function, add an argument.
+       (timeclock-day-list-required, timeclock-day-list-length)
+       (timeclock-day-list-debt, timeclock-day-list-span)
+       (timeclock-day-list-break): Adjust calls accordingly.
+
 2013-08-21  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * emacs-lisp/pp.el (pp-eval-expression, pp-macroexpand-expression):
index 70d064143dccf01d29bbfdd3e76b96a9684dc378..da074d377b53d2cf5ecefb9f9b71dcc39bb14dde 100644 (file)
@@ -136,7 +136,7 @@ This variable only has effect if set with \\[customize]."
         (if value
             (add-hook 'kill-emacs-query-functions 'timeclock-query-out)
           (remove-hook 'kill-emacs-query-functions 'timeclock-query-out))
-        (setq timeclock-ask-before-exiting value))
+        (set symbol value))
   :type 'boolean
   :group 'timeclock)
 
@@ -174,11 +174,12 @@ a positive argument to force an update."
                             timeclock-update-timer)))
               (setq currently-displaying nil))
           (and currently-displaying
-               (set-variable 'timeclock-mode-line-display nil))
-          (setq timeclock-use-display-time value)
+               (settimeclock-mode-line-display nil))
+          (set symbol value)
           (and currently-displaying
-               (set-variable 'timeclock-mode-line-display t))
-          timeclock-use-display-time))
+               (setq timeclock-mode-line-display t))
+           ;; FIXME: The return value isn't used, AFAIK!
+          value))
   :type 'boolean
   :group 'timeclock
   :require 'time)
@@ -269,9 +270,11 @@ The time is bracketed by <> if you are clocked in, otherwise by [].")
 
 (define-obsolete-function-alias 'timeclock-modeline-display
   'timeclock-mode-line-display "24.3")
+(define-obsolete-variable-alias 'timeclock-modeline-display
+  'timeclock-mode-line-display "24.3")
 
 ;;;###autoload
-(defun timeclock-mode-line-display (&optional arg)
+(define-minor-mode timeclock-mode-line-display
   "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 mode line
@@ -280,61 +283,41 @@ the timeclock will use its own sixty second timer to do its
 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")
+  :global t
   ;; cf display-time-mode.
   (setq timeclock-mode-string "")
   (or global-mode-string (setq global-mode-string '("")))
-  (let ((on-p (if arg
-                 (> (prefix-numeric-value arg) 0)
-               (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))))
-         (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-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-mode-line)
-                  (message "Activate `display-time-mode' or turn off \
+  (if timeclock-mode-line-display
+      (progn
+        (or (memq 'timeclock-mode-string global-mode-string)
+            (setq global-mode-string
+                  (append global-mode-string '(timeclock-mode-string))))
+        (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-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-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-mode-line))
-           (setq timeclock-update-timer
-                 (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-mode-line)
-      (if (boundp 'display-time-hook)
-         (remove-hook 'display-time-hook
-                      'timeclock-update-mode-line))
-      (when timeclock-update-timer
-       (cancel-timer timeclock-update-timer)
-       (setq timeclock-update-timer nil)))
-    (force-mode-line-update)
-    (setq timeclock-mode-line-display on-p)))
-
-(define-obsolete-variable-alias 'timeclock-modeline-display
-  'timeclock-mode-line-display "24.3")
-
-;; This has to be here so that the function definition of
-;; `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-mode-line-display
-              (timeclock-mode-line-display (or value 0))))
-  :type 'boolean
-  :group 'timeclock
-  :require 'timeclock)
+              (add-hook 'display-time-hook 'timeclock-update-mode-line))
+          (setq timeclock-update-timer
+                (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-mode-line)
+    (if (boundp 'display-time-hook)
+        (remove-hook 'display-time-hook
+                     'timeclock-update-mode-line))
+    (when timeclock-update-timer
+      (cancel-timer timeclock-update-timer)
+      (setq timeclock-update-timer nil))))
 
 (defsubst timeclock-time-to-date (time)
   "Convert the TIME value to a textual date string."
@@ -835,25 +818,24 @@ This is only provided for coherency when used by
   "Return a list of all the projects in DAY."
   (timeclock-entry-list-projects (cddr day)))
 
-(defmacro timeclock-day-list-template (func)
+(defun timeclock-day-list-template (func day-list)
   "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)))
-            day-list (cdr day-list)))
-     length))
+  (let ((length 0))
+    (dolist (day day-list)
+      (setq length (+ length (funcall func day))))
+    length))
 
 (defun timeclock-day-list-required (day-list)
   "Return total required length of DAY-LIST, in seconds."
-  (timeclock-day-list-template 'timeclock-day-required))
+  (timeclock-day-list-template #'timeclock-day-required day-list))
 
 (defun timeclock-day-list-length (day-list)
   "Return actual length of DAY-LIST, in seconds."
-  (timeclock-day-list-template 'timeclock-day-length))
+  (timeclock-day-list-template #'timeclock-day-length day-list))
 
 (defun timeclock-day-list-debt (day-list)
   "Return total debt (required - actual) of DAY-LIST."
-  (timeclock-day-list-template 'timeclock-day-debt))
+  (timeclock-day-list-template #'timeclock-day-debt day-list))
 
 (defsubst timeclock-day-list-begin (day-list)
   "Return the start time of DAY-LIST."
@@ -865,11 +847,11 @@ This is only provided for coherency when used by
 
 (defun timeclock-day-list-span (day-list)
   "Return the span of DAY-LIST."
-  (timeclock-day-list-template 'timeclock-day-span))
+  (timeclock-day-list-template #'timeclock-day-span day-list))
 
 (defun timeclock-day-list-break (day-list)
   "Return the total break of DAY-LIST."
-  (timeclock-day-list-template 'timeclock-day-break))
+  (timeclock-day-list-template #'timeclock-day-break day-list))
 
 (defun timeclock-day-list-projects (day-list)
   "Return a list of all the projects in DAY-LIST."