diff options
author | Glenn Morris <rgm@gnu.org> | 2011-05-12 00:56:02 -0700 |
---|---|---|
committer | Glenn Morris <rgm@gnu.org> | 2011-05-12 00:56:02 -0700 |
commit | 98dc3df322a2706803625ddfce0038ce94eec5d8 (patch) | |
tree | 42a76a822018084c9a53b069ad288669a26a54d2 /lisp/calendar/appt.el | |
parent | e2c94218141ca8bb06c57654d341b33412d3caa9 (diff) | |
download | emacs-98dc3df322a2706803625ddfce0038ce94eec5d8.tar.gz |
appt.el code simplifications.
* lisp/calendar/appt.el (appt-now-displayed): Remove pointless variable.
(appt-check): Simplify.
Details:
appt-now-displayed was set non-nil the first time a reminder was displayed.
Nothing ever set it back to nil again. Thus when full-check was nil,
mode-line-only was always true, so the "(when (or full-check mode-line-only)"
was pointless. That was the only use of full-check. mode-line-only
was only used in a negative sense, and can be reduced to the zerop test.
Diffstat (limited to 'lisp/calendar/appt.el')
-rw-r--r-- | lisp/calendar/appt.el | 165 |
1 files changed, 76 insertions, 89 deletions
diff --git a/lisp/calendar/appt.el b/lisp/calendar/appt.el index d1483c5445d..dce6cc28239 100644 --- a/lisp/calendar/appt.el +++ b/lisp/calendar/appt.el @@ -197,9 +197,6 @@ Only used if `appt-display-mode-line' is non-nil.") "Time of day (mins since midnight) at which we last checked appointments. A nil value forces the diary file to be (re-)checked for appointments.") -(defvar appt-now-displayed nil - "Non-nil when we have started notifying about a appointment that is near.") - (defvar appt-display-count nil "Internal variable used to count number of consecutive reminders.") @@ -285,93 +282,83 @@ displayed in a window: (let* ((min-to-app -1) (prev-appt-mode-string appt-mode-string) (prev-appt-display-count (or appt-display-count 0)) - ;; Non-nil means do a full check for pending appointments and - ;; display in whatever ways the user has selected. When no - ;; appointment is being displayed, we always do a full check. - (full-check - (or (not appt-now-displayed) - ;; This is true every appt-display-interval minutes. - (zerop (mod prev-appt-display-count appt-display-interval)))) - ;; Non-nil means only update the interval displayed in the mode line. - (mode-line-only (unless full-check appt-now-displayed)) now cur-comp-time appt-comp-time appt-warn-time) - (when (or full-check mode-line-only) - (save-excursion ; FIXME ? - ;; Convert current time to minutes after midnight (12.01am = 1). - (setq now (decode-time) - cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) - ;; At first check in any day, update appointments to today's list. - (if (or force ; eg initialize, diary save - (null appt-prev-comp-time) ; first check - (< cur-comp-time appt-prev-comp-time)) ; new day - (ignore-errors - (let ((diary-hook (if (assoc 'appt-make-list diary-hook) - diary-hook - (cons 'appt-make-list diary-hook)))) - (if appt-display-diary - (diary) - ;; Not displaying the diary, so we can ignore - ;; diary-number-of-entries. Since appt.el only - ;; works on a daily basis, no need for more entries. - (diary-list-entries (calendar-current-date) 1 t))))) - (setq appt-prev-comp-time cur-comp-time - appt-mode-string nil - appt-display-count nil) - ;; If there are entries in the list, and the user wants a - ;; message issued, get the first time off of the list and - ;; calculate the number of minutes until the appointment. - (when appt-time-msg-list - (setq appt-comp-time (caar (car appt-time-msg-list)) - appt-warn-time (or (nth 3 (car appt-time-msg-list)) - appt-message-warning-time) - min-to-app (- appt-comp-time cur-comp-time)) - (while (and appt-time-msg-list - (< appt-comp-time cur-comp-time)) - (setq appt-time-msg-list (cdr appt-time-msg-list)) - (if appt-time-msg-list - (setq appt-comp-time (caar (car appt-time-msg-list))))) - ;; If we have an appointment between midnight and - ;; `appt-warn-time' minutes after midnight, we - ;; must begin to issue a message before midnight. Midnight - ;; is considered 0 minutes and 11:59pm is 1439 - ;; minutes. Therefore we must recalculate the minutes to - ;; appointment variable. It is equal to the number of - ;; minutes before midnight plus the number of minutes after - ;; midnight our appointment is. - (if (and (< appt-comp-time appt-warn-time) - (> (+ cur-comp-time appt-warn-time) - appt-max-time)) - (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time) - appt-comp-time))) - ;; Issue warning if the appointment time is within - ;; appt-message-warning time. - (when (and (<= min-to-app appt-warn-time) - (>= min-to-app 0)) - (setq appt-now-displayed t - appt-display-count (1+ prev-appt-display-count)) - (unless mode-line-only - (appt-display-message (cadr (car appt-time-msg-list)) - min-to-app)) - (when appt-display-mode-line - (setq appt-mode-string - (concat " " (propertize - (format "App't in %s min." min-to-app) - 'face 'mode-line-emphasis)))) - ;; When an appointment is reached, delete it from the - ;; list. Reset the count to 0 in case we display another - ;; appointment on the next cycle. - (if (zerop min-to-app) - (setq appt-time-msg-list (cdr appt-time-msg-list) - appt-display-count nil)))) - ;; If we have changed the mode line string, redisplay all mode lines. - (and appt-display-mode-line - (not (string-equal appt-mode-string - prev-appt-mode-string)) - (progn - (force-mode-line-update t) - ;; If the string now has a notification, redisplay right now. - (if appt-mode-string - (sit-for 0)))))))) + (save-excursion ; FIXME ? + ;; Convert current time to minutes after midnight (12.01am = 1). + (setq now (decode-time) + cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) + ;; At first check in any day, update appointments to today's list. + (if (or force ; eg initialize, diary save + (null appt-prev-comp-time) ; first check + (< cur-comp-time appt-prev-comp-time)) ; new day + (ignore-errors + (let ((diary-hook (if (assoc 'appt-make-list diary-hook) + diary-hook + (cons 'appt-make-list diary-hook)))) + (if appt-display-diary + (diary) + ;; Not displaying the diary, so we can ignore + ;; diary-number-of-entries. Since appt.el only + ;; works on a daily basis, no need for more entries. + (diary-list-entries (calendar-current-date) 1 t))))) + (setq appt-prev-comp-time cur-comp-time + appt-mode-string nil + appt-display-count nil) + ;; If there are entries in the list, and the user wants a + ;; message issued, get the first time off of the list and + ;; calculate the number of minutes until the appointment. + (when appt-time-msg-list + (setq appt-comp-time (caar (car appt-time-msg-list)) + appt-warn-time (or (nth 3 (car appt-time-msg-list)) + appt-message-warning-time) + min-to-app (- appt-comp-time cur-comp-time)) + (while (and appt-time-msg-list + (< appt-comp-time cur-comp-time)) + (setq appt-time-msg-list (cdr appt-time-msg-list)) + (if appt-time-msg-list + (setq appt-comp-time (caar (car appt-time-msg-list))))) + ;; If we have an appointment between midnight and + ;; `appt-warn-time' minutes after midnight, we + ;; must begin to issue a message before midnight. Midnight + ;; is considered 0 minutes and 11:59pm is 1439 + ;; minutes. Therefore we must recalculate the minutes to + ;; appointment variable. It is equal to the number of + ;; minutes before midnight plus the number of minutes after + ;; midnight our appointment is. + (if (and (< appt-comp-time appt-warn-time) + (> (+ cur-comp-time appt-warn-time) + appt-max-time)) + (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time) + appt-comp-time))) + ;; Issue warning if the appointment time is within + ;; appt-message-warning time. + (when (and (<= min-to-app appt-warn-time) + (>= min-to-app 0)) + (setq appt-display-count (1+ prev-appt-display-count)) + ;; This is true every appt-display-interval minutes. + (and (zerop (mod prev-appt-display-count appt-display-interval)) + (appt-display-message (cadr (car appt-time-msg-list)) + min-to-app)) + (when appt-display-mode-line + (setq appt-mode-string + (concat " " (propertize + (format "App't in %s min." min-to-app) + 'face 'mode-line-emphasis)))) + ;; When an appointment is reached, delete it from the + ;; list. Reset the count to 0 in case we display another + ;; appointment on the next cycle. + (if (zerop min-to-app) + (setq appt-time-msg-list (cdr appt-time-msg-list) + appt-display-count nil)))) + ;; If we have changed the mode line string, redisplay all mode lines. + (and appt-display-mode-line + (not (string-equal appt-mode-string + prev-appt-mode-string)) + (progn + (force-mode-line-update t) + ;; If the string now has a notification, redisplay right now. + (if appt-mode-string + (sit-for 0))))))) (defun appt-disp-window (min-to-app new-time appt-msg) "Display appointment due in MIN-TO-APP (a string) minutes. |