>From 0d204807d8c7866f661d65810d32c8ca9e4d5f00 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Sat, 26 Mar 2011 16:46:35 +0100 Subject: [PATCH 11/13] copy appt-time-msg-list in a local variabl ac-appt-list This is in preparation to using this variable do handle multiple appointment. Clean up obscure code at the beginning of the function. The strategy is to remove all appointment prior to the current time. We then setup all necessary local variable in one setq. There is no need to remove appointment from the list at the end of the routine since that's taken care of at the beginning. --- appt.el | 34 +++++++++++++++++----------------- 1 files changed, 17 insertions(+), 17 deletions(-) diff --git a/appt.el b/appt.el index 17473d2..9bae717 100644 --- a/appt.el +++ b/appt.el @@ -311,23 +311,25 @@ displayed in a window: (let* ((ac-now (decode-time)) ;; Convert current time to minutes after midnight (12.01am = 1). (ac-cur-time (+ (* 60 (nth 2 ac-now)) (nth 1 ac-now))) + (ac-appt-list appt-time-msg-list) ac-appt-time ac-warn-time ac-min-to-app) (save-excursion (appt-check-diary force ac-cur-time) - (setq appt-mode-string nil) + ;; Discard appointments previous to current time + (while (and ac-appt-list + (setq ac-appt-time (caar (car ac-appt-list))) + (< ac-appt-time ac-cur-time)) + (setq ac-appt-list (cdr ac-appt-list))) + (setq appt-time-msg-list ac-appt-list) ;; 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 ac-appt-time (caar (car appt-time-msg-list)) - ac-warn-time (or (nth 3 (car appt-time-msg-list)) - appt-message-warning-time) - ac-min-to-app (- ac-appt-time ac-cur-time)) - (while (and appt-time-msg-list - (< ac-appt-time ac-cur-time)) - (setq appt-time-msg-list (cdr appt-time-msg-list)) - (if appt-time-msg-list - (setq ac-appt-time (caar (car appt-time-msg-list))))) + (when ac-appt-list + (setq ac-warn-time (or (nth 3 (car ac-appt-list)) + appt-message-warning-time) + ac-min-to-app (- ac-appt-time ac-cur-time) + ac-appt-time (caar (car ac-appt-list)) + appt-mode-string nil) ;; If we have an appointment between midnight and ;; `ac-warn-time' minutes after midnight, we ;; must begin to issue a message before midnight. Midnight @@ -347,7 +349,7 @@ displayed in a window: (>= ac-min-to-app 0)) ;; This is true every appt-display-interval minutes. (if (zerop (mod appt-display-count appt-display-interval)) - (appt-display-message (cadr (car appt-time-msg-list)) + (appt-display-message (cadr (car ac-appt-list)) ac-min-to-app)) (setq appt-display-count (1+ appt-display-count)) (when appt-display-mode-line @@ -355,12 +357,10 @@ displayed in a window: (concat " " (propertize (format "App't in %s min." ac-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. + ;; 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-time-msg-list (cdr appt-time-msg-list) - appt-display-count 0)))) + (setq appt-display-count 0)))) ;; Redisplay all mode lines. (when appt-display-mode-line (force-mode-line-update))))) -- 1.7.1