emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r113970: * lisp/calendar/timeclock.el: Minor cleanup


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r113970: * lisp/calendar/timeclock.el: Minor cleanups.
Date: Thu, 22 Aug 2013 01:09:12 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113970
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Wed 2013-08-21 21:09:08 -0400
message:
  * lisp/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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/calendar/timeclock.el     
timeclock.el-20091113204419-o5vbwnq5f7feedwu-1896
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-08-21 18:26:15 +0000
+++ b/lisp/ChangeLog    2013-08-22 01:09:08 +0000
@@ -1,3 +1,16 @@
+2013-08-22  Stefan Monnier  <address@hidden>
+
+       * 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  <address@hidden>
 
        * emacs-lisp/pp.el (pp-eval-expression, pp-macroexpand-expression):

=== modified file 'lisp/calendar/timeclock.el'
--- a/lisp/calendar/timeclock.el        2013-03-12 02:08:21 +0000
+++ b/lisp/calendar/timeclock.el        2013-08-22 01:09:08 +0000
@@ -136,7 +136,7 @@
         (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 @@
                             timeclock-update-timer)))
               (setq currently-displaying nil))
           (and currently-displaying
-               (set-variable 'timeclock-mode-line-display nil))
-          (setq timeclock-use-display-time value)
+               (setq timeclock-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 @@
 
 (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 @@
 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 @@
   "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 @@
 
 (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."


reply via email to

[Prev in Thread] Current Thread [Next in Thread]