>From f58eba27aebbcfb0bbf5385a9efe7a5f3b32f289 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Mon, 28 Mar 2011 19:54:09 +0200 Subject: [PATCH 13/13] move appointment checking code in a function This makes function appt-check a reasonable size and I have added some comments as well. --- appt.el | 78 +++++++++++++++++++++++++++++++++++++------------------------- 1 files changed, 46 insertions(+), 32 deletions(-) diff --git a/appt.el b/appt.el index 1a9e9f3..c3cc429 100644 --- a/appt.el +++ b/appt.el @@ -348,55 +348,39 @@ displayed in a window: (ac-cur-time (+ (* 60 (nth 2 ac-now)) (nth 1 ac-now))) (ac-appt-list appt-time-msg-list) (ac-first nil) - ac-appt-time ac-warn-time ac-min-to-app ac-msg ac-msg-list) + ac-msg ac-msg-list ac-min-to-app) (save-excursion (appt-check-diary force ac-cur-time) + ;; Discard appointments previous to current time (while (and ac-appt-list (< (caar (car ac-appt-list)) ac-cur-time)) (setq ac-appt-list (cdr ac-appt-list))) + + ;; Update global list and few other things (setq appt-time-msg-list ac-appt-list appt-mode-string nil appt-display-count (1+ appt-display-count)) + ;; Now walk the remaining list checking for appointments (while ac-appt-list - (setq ac-warn-time (or (nth 3 (car ac-appt-list)) - appt-message-warning-time) - ac-appt-time (caar (car ac-appt-list)) - ac-min-to-app (- ac-appt-time ac-cur-time)) - - ;; If we have an appointment between midnight and - ;; `ac-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 (< ac-appt-time ac-warn-time) - (> (+ ac-cur-time ac-warn-time) - appt-max-time)) - (setq ac-min-to-app (+ (- (1+ appt-max-time) ac-cur-time) - ac-appt-time))) - ;; Issue warning if the appointment time is within - ;; appt-message-warning time. - (when (and (<= ac-min-to-app ac-warn-time) - (>= ac-min-to-app 0)) - (setq ac-msg (cadr (car ac-appt-list))) - (add-to-list 'ac-msg-list ac-msg) - (when (not ac-first) - (setq ac-first (list ac-min-to-app ac-msg))) - ;; When an appointment is reached reset the count to 0 in - ;; case we display another appointment on the next cycle. - (if (zerop ac-min-to-app) - (setq appt-display-count 0))) + (setq ac-min-to-app + (appt-check-appointment (car ac-appt-list) ac-cur-time)) + (when ac-min-to-app + (setq ac-msg (cadr (car ac-appt-list))) + (add-to-list 'ac-msg-list ac-msg)) + (when (not ac-first) + (setq ac-first (list ac-min-to-app ac-msg))) (setq ac-appt-list (cdr ac-appt-list))) + + ;; Display messages (when (and ac-first (zerop (mod appt-display-count appt-display-interval)) (if appt-display-multiple (appt-display-multiple-message ac-msg-list (car ac-first)) (appt-display-message (cadr ac-first) (car ac-first))))) - ;; Redisplay all mode lines. + + ;; Display mode line (when appt-display-mode-line (when ac-first (setq appt-mode-string @@ -405,6 +389,36 @@ displayed in a window: 'face 'mode-line-emphasis))))) (force-mode-line-update)))) +(defun appt-check-appointment (appt cur-time) + "Check if apppointment needs to be displayed. +Returns integer of minute till the appointment is due or nil" + (let* ((aca-warn-time (or (nth 3 appt) + appt-message-warning-time)) + (aca-appt-time (caar appt)) + (aca-min-to-app (- aca-appt-time cur-time))) + + ;; If we have an appointment between midnight and + ;; `aca-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. + (when (and (< aca-appt-time aca-warn-time) + (> (+ cur-time aca-warn-time) + appt-max-time)) + (setq aca-min-to-app (+ (- (1+ appt-max-time) cur-time) + aca-appt-time))) + ;; Issue warning if the appointment time is within + ;; appt-message-warning time. + (when (and (<= aca-min-to-app aca-warn-time) + (>= aca-min-to-app 0)) + ;; When an appointment is reached reset the count to 0 in + ;; case we display another appointment on the next cycle. + (when (zerop aca-min-to-app) + (setq appt-display-count 0)) aca-min-to-app))) + (defun appt-check-diary (force cur-comp-time) "Update appointments to today's list." ;; At first check in any day -- 1.7.1