diff options
| author | Stefan Monnier | 2013-08-21 21:09:08 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2013-08-21 21:09:08 -0400 |
| commit | 8352b530871b89683c6a64e76ff22ed26e1701fd (patch) | |
| tree | 4f5cbf726dd8f3626f8159d0cb40302a4408d7da | |
| parent | 4a88129ae4332cbf3833c00f79100610ca2e576d (diff) | |
| download | emacs-8352b530871b89683c6a64e76ff22ed26e1701fd.tar.gz emacs-8352b530871b89683c6a64e76ff22ed26e1701fd.zip | |
* 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.
| -rw-r--r-- | lisp/ChangeLog | 13 | ||||
| -rw-r--r-- | lisp/calendar/timeclock.el | 118 |
2 files changed, 63 insertions, 68 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d8bae263da2..0bba2e5fb58 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2013-08-22 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * calendar/timeclock.el: Minor cleanups. | ||
| 4 | (timeclock-ask-before-exiting, timeclock-use-display-time): | ||
| 5 | Use `symbol'. | ||
| 6 | (timeclock-modeline-display): Define as alias before the | ||
| 7 | actual definition. | ||
| 8 | (timeclock-mode-line-display): Use define-minor-mode. | ||
| 9 | (timeclock-day-list-template): Make it a function, add an argument. | ||
| 10 | (timeclock-day-list-required, timeclock-day-list-length) | ||
| 11 | (timeclock-day-list-debt, timeclock-day-list-span) | ||
| 12 | (timeclock-day-list-break): Adjust calls accordingly. | ||
| 13 | |||
| 1 | 2013-08-21 Stefan Monnier <monnier@iro.umontreal.ca> | 14 | 2013-08-21 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 15 | ||
| 3 | * emacs-lisp/pp.el (pp-eval-expression, pp-macroexpand-expression): | 16 | * emacs-lisp/pp.el (pp-eval-expression, pp-macroexpand-expression): |
diff --git a/lisp/calendar/timeclock.el b/lisp/calendar/timeclock.el index 70d064143dc..da074d377b5 100644 --- a/lisp/calendar/timeclock.el +++ b/lisp/calendar/timeclock.el | |||
| @@ -136,7 +136,7 @@ This variable only has effect if set with \\[customize]." | |||
| 136 | (if value | 136 | (if value |
| 137 | (add-hook 'kill-emacs-query-functions 'timeclock-query-out) | 137 | (add-hook 'kill-emacs-query-functions 'timeclock-query-out) |
| 138 | (remove-hook 'kill-emacs-query-functions 'timeclock-query-out)) | 138 | (remove-hook 'kill-emacs-query-functions 'timeclock-query-out)) |
| 139 | (setq timeclock-ask-before-exiting value)) | 139 | (set symbol value)) |
| 140 | :type 'boolean | 140 | :type 'boolean |
| 141 | :group 'timeclock) | 141 | :group 'timeclock) |
| 142 | 142 | ||
| @@ -174,11 +174,12 @@ a positive argument to force an update." | |||
| 174 | timeclock-update-timer))) | 174 | timeclock-update-timer))) |
| 175 | (setq currently-displaying nil)) | 175 | (setq currently-displaying nil)) |
| 176 | (and currently-displaying | 176 | (and currently-displaying |
| 177 | (set-variable 'timeclock-mode-line-display nil)) | 177 | (setq timeclock-mode-line-display nil)) |
| 178 | (setq timeclock-use-display-time value) | 178 | (set symbol value) |
| 179 | (and currently-displaying | 179 | (and currently-displaying |
| 180 | (set-variable 'timeclock-mode-line-display t)) | 180 | (setq timeclock-mode-line-display t)) |
| 181 | timeclock-use-display-time)) | 181 | ;; FIXME: The return value isn't used, AFAIK! |
| 182 | value)) | ||
| 182 | :type 'boolean | 183 | :type 'boolean |
| 183 | :group 'timeclock | 184 | :group 'timeclock |
| 184 | :require 'time) | 185 | :require 'time) |
| @@ -269,9 +270,11 @@ The time is bracketed by <> if you are clocked in, otherwise by [].") | |||
| 269 | 270 | ||
| 270 | (define-obsolete-function-alias 'timeclock-modeline-display | 271 | (define-obsolete-function-alias 'timeclock-modeline-display |
| 271 | 'timeclock-mode-line-display "24.3") | 272 | 'timeclock-mode-line-display "24.3") |
| 273 | (define-obsolete-variable-alias 'timeclock-modeline-display | ||
| 274 | 'timeclock-mode-line-display "24.3") | ||
| 272 | 275 | ||
| 273 | ;;;###autoload | 276 | ;;;###autoload |
| 274 | (defun timeclock-mode-line-display (&optional arg) | 277 | (define-minor-mode timeclock-mode-line-display |
| 275 | "Toggle display of the amount of time left today in the mode line. | 278 | "Toggle display of the amount of time left today in the mode line. |
| 276 | If `timeclock-use-display-time' is non-nil (the default), then | 279 | If `timeclock-use-display-time' is non-nil (the default), then |
| 277 | the function `display-time-mode' must be active, and the mode line | 280 | 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 | |||
| 280 | updating. With prefix ARG, turn mode line display on if and only | 283 | updating. With prefix ARG, turn mode line display on if and only |
| 281 | if ARG is positive. Returns the new status of timeclock mode line | 284 | if ARG is positive. Returns the new status of timeclock mode line |
| 282 | display (non-nil means on)." | 285 | display (non-nil means on)." |
| 283 | (interactive "P") | 286 | :global t |
| 284 | ;; cf display-time-mode. | 287 | ;; cf display-time-mode. |
| 285 | (setq timeclock-mode-string "") | 288 | (setq timeclock-mode-string "") |
| 286 | (or global-mode-string (setq global-mode-string '(""))) | 289 | (or global-mode-string (setq global-mode-string '(""))) |
| 287 | (let ((on-p (if arg | 290 | (if timeclock-mode-line-display |
| 288 | (> (prefix-numeric-value arg) 0) | 291 | (progn |
| 289 | (not timeclock-mode-line-display)))) | 292 | (or (memq 'timeclock-mode-string global-mode-string) |
| 290 | (if on-p | 293 | (setq global-mode-string |
| 291 | (progn | 294 | (append global-mode-string '(timeclock-mode-string)))) |
| 292 | (or (memq 'timeclock-mode-string global-mode-string) | 295 | (add-hook 'timeclock-event-hook 'timeclock-update-mode-line) |
| 293 | (setq global-mode-string | 296 | (when timeclock-update-timer |
| 294 | (append global-mode-string '(timeclock-mode-string)))) | 297 | (cancel-timer timeclock-update-timer) |
| 295 | (add-hook 'timeclock-event-hook 'timeclock-update-mode-line) | 298 | (setq timeclock-update-timer nil)) |
| 296 | (when timeclock-update-timer | 299 | (if (boundp 'display-time-hook) |
| 297 | (cancel-timer timeclock-update-timer) | 300 | (remove-hook 'display-time-hook 'timeclock-update-mode-line)) |
| 298 | (setq timeclock-update-timer nil)) | 301 | (if timeclock-use-display-time |
| 299 | (if (boundp 'display-time-hook) | 302 | (progn |
| 300 | (remove-hook 'display-time-hook 'timeclock-update-mode-line)) | 303 | ;; Update immediately so there is a visible change |
| 301 | (if timeclock-use-display-time | 304 | ;; on calling this function. |
| 302 | (progn | 305 | (if display-time-mode |
| 303 | ;; Update immediately so there is a visible change | 306 | (timeclock-update-mode-line) |
| 304 | ;; on calling this function. | 307 | (message "Activate `display-time-mode' or turn off \ |
| 305 | (if display-time-mode | ||
| 306 | (timeclock-update-mode-line) | ||
| 307 | (message "Activate `display-time-mode' or turn off \ | ||
| 308 | `timeclock-use-display-time' to see timeclock information")) | 308 | `timeclock-use-display-time' to see timeclock information")) |
| 309 | (add-hook 'display-time-hook 'timeclock-update-mode-line)) | 309 | (add-hook 'display-time-hook 'timeclock-update-mode-line)) |
| 310 | (setq timeclock-update-timer | 310 | (setq timeclock-update-timer |
| 311 | (run-at-time nil 60 'timeclock-update-mode-line)))) | 311 | (run-at-time nil 60 'timeclock-update-mode-line)))) |
| 312 | (setq global-mode-string | 312 | (setq global-mode-string |
| 313 | (delq 'timeclock-mode-string global-mode-string)) | 313 | (delq 'timeclock-mode-string global-mode-string)) |
| 314 | (remove-hook 'timeclock-event-hook 'timeclock-update-mode-line) | 314 | (remove-hook 'timeclock-event-hook 'timeclock-update-mode-line) |
| 315 | (if (boundp 'display-time-hook) | 315 | (if (boundp 'display-time-hook) |
| 316 | (remove-hook 'display-time-hook | 316 | (remove-hook 'display-time-hook |
| 317 | 'timeclock-update-mode-line)) | 317 | 'timeclock-update-mode-line)) |
| 318 | (when timeclock-update-timer | 318 | (when timeclock-update-timer |
| 319 | (cancel-timer timeclock-update-timer) | 319 | (cancel-timer timeclock-update-timer) |
| 320 | (setq timeclock-update-timer nil))) | 320 | (setq timeclock-update-timer nil)))) |
| 321 | (force-mode-line-update) | ||
| 322 | (setq timeclock-mode-line-display on-p))) | ||
| 323 | |||
| 324 | (define-obsolete-variable-alias 'timeclock-modeline-display | ||
| 325 | 'timeclock-mode-line-display "24.3") | ||
| 326 | |||
| 327 | ;; This has to be here so that the function definition of | ||
| 328 | ;; `timeclock-mode-line-display' is known to the "set" function. | ||
| 329 | (defcustom timeclock-mode-line-display nil | ||
| 330 | "Toggle mode line display of time remaining. | ||
| 331 | You must modify via \\[customize] for this variable to have an effect." | ||
| 332 | :set (lambda (symbol value) | ||
| 333 | (setq timeclock-mode-line-display | ||
| 334 | (timeclock-mode-line-display (or value 0)))) | ||
| 335 | :type 'boolean | ||
| 336 | :group 'timeclock | ||
| 337 | :require 'timeclock) | ||
| 338 | 321 | ||
| 339 | (defsubst timeclock-time-to-date (time) | 322 | (defsubst timeclock-time-to-date (time) |
| 340 | "Convert the TIME value to a textual date string." | 323 | "Convert the TIME value to a textual date string." |
| @@ -835,25 +818,24 @@ This is only provided for coherency when used by | |||
| 835 | "Return a list of all the projects in DAY." | 818 | "Return a list of all the projects in DAY." |
| 836 | (timeclock-entry-list-projects (cddr day))) | 819 | (timeclock-entry-list-projects (cddr day))) |
| 837 | 820 | ||
| 838 | (defmacro timeclock-day-list-template (func) | 821 | (defun timeclock-day-list-template (func day-list) |
| 839 | "Template for summing the result of FUNC on each element of DAY-LIST." | 822 | "Template for summing the result of FUNC on each element of DAY-LIST." |
| 840 | `(let ((length 0)) | 823 | (let ((length 0)) |
| 841 | (while day-list | 824 | (dolist (day day-list) |
| 842 | (setq length (+ length (,(eval func) (car day-list))) | 825 | (setq length (+ length (funcall func day)))) |
| 843 | day-list (cdr day-list))) | 826 | length)) |
| 844 | length)) | ||
| 845 | 827 | ||
| 846 | (defun timeclock-day-list-required (day-list) | 828 | (defun timeclock-day-list-required (day-list) |
| 847 | "Return total required length of DAY-LIST, in seconds." | 829 | "Return total required length of DAY-LIST, in seconds." |
| 848 | (timeclock-day-list-template 'timeclock-day-required)) | 830 | (timeclock-day-list-template #'timeclock-day-required day-list)) |
| 849 | 831 | ||
| 850 | (defun timeclock-day-list-length (day-list) | 832 | (defun timeclock-day-list-length (day-list) |
| 851 | "Return actual length of DAY-LIST, in seconds." | 833 | "Return actual length of DAY-LIST, in seconds." |
| 852 | (timeclock-day-list-template 'timeclock-day-length)) | 834 | (timeclock-day-list-template #'timeclock-day-length day-list)) |
| 853 | 835 | ||
| 854 | (defun timeclock-day-list-debt (day-list) | 836 | (defun timeclock-day-list-debt (day-list) |
| 855 | "Return total debt (required - actual) of DAY-LIST." | 837 | "Return total debt (required - actual) of DAY-LIST." |
| 856 | (timeclock-day-list-template 'timeclock-day-debt)) | 838 | (timeclock-day-list-template #'timeclock-day-debt day-list)) |
| 857 | 839 | ||
| 858 | (defsubst timeclock-day-list-begin (day-list) | 840 | (defsubst timeclock-day-list-begin (day-list) |
| 859 | "Return the start time of DAY-LIST." | 841 | "Return the start time of DAY-LIST." |
| @@ -865,11 +847,11 @@ This is only provided for coherency when used by | |||
| 865 | 847 | ||
| 866 | (defun timeclock-day-list-span (day-list) | 848 | (defun timeclock-day-list-span (day-list) |
| 867 | "Return the span of DAY-LIST." | 849 | "Return the span of DAY-LIST." |
| 868 | (timeclock-day-list-template 'timeclock-day-span)) | 850 | (timeclock-day-list-template #'timeclock-day-span day-list)) |
| 869 | 851 | ||
| 870 | (defun timeclock-day-list-break (day-list) | 852 | (defun timeclock-day-list-break (day-list) |
| 871 | "Return the total break of DAY-LIST." | 853 | "Return the total break of DAY-LIST." |
| 872 | (timeclock-day-list-template 'timeclock-day-break)) | 854 | (timeclock-day-list-template #'timeclock-day-break day-list)) |
| 873 | 855 | ||
| 874 | (defun timeclock-day-list-projects (day-list) | 856 | (defun timeclock-day-list-projects (day-list) |
| 875 | "Return a list of all the projects in DAY-LIST." | 857 | "Return a list of all the projects in DAY-LIST." |