aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2011-05-12 00:56:02 -0700
committerGlenn Morris2011-05-12 00:56:02 -0700
commit98dc3df322a2706803625ddfce0038ce94eec5d8 (patch)
tree42a76a822018084c9a53b069ad288669a26a54d2
parente2c94218141ca8bb06c57654d341b33412d3caa9 (diff)
downloademacs-98dc3df322a2706803625ddfce0038ce94eec5d8.tar.gz
emacs-98dc3df322a2706803625ddfce0038ce94eec5d8.zip
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.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/calendar/appt.el165
2 files changed, 81 insertions, 89 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d1348485002..beaee515a52 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12011-05-12 Glenn Morris <rgm@gnu.org>
2
3 * calendar/appt.el (appt-now-displayed): Remove pointless variable.
4 (appt-check): Simplify.
5
12011-05-12 Eli Zaretskii <eliz@gnu.org> 62011-05-12 Eli Zaretskii <eliz@gnu.org>
2 7
3 * smerge-mode.el (smerge-resolve): Use null-device rather than a 8 * smerge-mode.el (smerge-resolve): Use null-device rather than a
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.")
197 "Time of day (mins since midnight) at which we last checked appointments. 197 "Time of day (mins since midnight) at which we last checked appointments.
198A nil value forces the diary file to be (re-)checked for appointments.") 198A nil value forces the diary file to be (re-)checked for appointments.")
199 199
200(defvar appt-now-displayed nil
201 "Non-nil when we have started notifying about a appointment that is near.")
202
203(defvar appt-display-count nil 200(defvar appt-display-count nil
204 "Internal variable used to count number of consecutive reminders.") 201 "Internal variable used to count number of consecutive reminders.")
205 202
@@ -285,93 +282,83 @@ displayed in a window:
285 (let* ((min-to-app -1) 282 (let* ((min-to-app -1)
286 (prev-appt-mode-string appt-mode-string) 283 (prev-appt-mode-string appt-mode-string)
287 (prev-appt-display-count (or appt-display-count 0)) 284 (prev-appt-display-count (or appt-display-count 0))
288 ;; Non-nil means do a full check for pending appointments and
289 ;; display in whatever ways the user has selected. When no
290 ;; appointment is being displayed, we always do a full check.
291 (full-check
292 (or (not appt-now-displayed)
293 ;; This is true every appt-display-interval minutes.
294 (zerop (mod prev-appt-display-count appt-display-interval))))
295 ;; Non-nil means only update the interval displayed in the mode line.
296 (mode-line-only (unless full-check appt-now-displayed))
297 now cur-comp-time appt-comp-time appt-warn-time) 285 now cur-comp-time appt-comp-time appt-warn-time)
298 (when (or full-check mode-line-only) 286 (save-excursion ; FIXME ?
299 (save-excursion ; FIXME ? 287 ;; Convert current time to minutes after midnight (12.01am = 1).
300 ;; Convert current time to minutes after midnight (12.01am = 1). 288 (setq now (decode-time)
301 (setq now (decode-time) 289 cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now)))
302 cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) 290 ;; At first check in any day, update appointments to today's list.
303 ;; At first check in any day, update appointments to today's list. 291 (if (or force ; eg initialize, diary save
304 (if (or force ; eg initialize, diary save 292 (null appt-prev-comp-time) ; first check
305 (null appt-prev-comp-time) ; first check 293 (< cur-comp-time appt-prev-comp-time)) ; new day
306 (< cur-comp-time appt-prev-comp-time)) ; new day 294 (ignore-errors
307 (ignore-errors 295 (let ((diary-hook (if (assoc 'appt-make-list diary-hook)
308 (let ((diary-hook (if (assoc 'appt-make-list diary-hook) 296 diary-hook
309 diary-hook 297 (cons 'appt-make-list diary-hook))))
310 (cons 'appt-make-list diary-hook)))) 298 (if appt-display-diary
311 (if appt-display-diary 299 (diary)
312 (diary) 300 ;; Not displaying the diary, so we can ignore
313 ;; Not displaying the diary, so we can ignore 301 ;; diary-number-of-entries. Since appt.el only
314 ;; diary-number-of-entries. Since appt.el only 302 ;; works on a daily basis, no need for more entries.
315 ;; works on a daily basis, no need for more entries. 303 (diary-list-entries (calendar-current-date) 1 t)))))
316 (diary-list-entries (calendar-current-date) 1 t))))) 304 (setq appt-prev-comp-time cur-comp-time
317 (setq appt-prev-comp-time cur-comp-time 305 appt-mode-string nil
318 appt-mode-string nil 306 appt-display-count nil)
319 appt-display-count nil) 307 ;; If there are entries in the list, and the user wants a
320 ;; If there are entries in the list, and the user wants a 308 ;; message issued, get the first time off of the list and
321 ;; message issued, get the first time off of the list and 309 ;; calculate the number of minutes until the appointment.
322 ;; calculate the number of minutes until the appointment. 310 (when appt-time-msg-list
323 (when appt-time-msg-list 311 (setq appt-comp-time (caar (car appt-time-msg-list))
324 (setq appt-comp-time (caar (car appt-time-msg-list)) 312 appt-warn-time (or (nth 3 (car appt-time-msg-list))
325 appt-warn-time (or (nth 3 (car appt-time-msg-list)) 313 appt-message-warning-time)
326 appt-message-warning-time) 314 min-to-app (- appt-comp-time cur-comp-time))
327 min-to-app (- appt-comp-time cur-comp-time)) 315 (while (and appt-time-msg-list
328 (while (and appt-time-msg-list 316 (< appt-comp-time cur-comp-time))
329 (< appt-comp-time cur-comp-time)) 317 (setq appt-time-msg-list (cdr appt-time-msg-list))
330 (setq appt-time-msg-list (cdr appt-time-msg-list)) 318 (if appt-time-msg-list
331 (if appt-time-msg-list 319 (setq appt-comp-time (caar (car appt-time-msg-list)))))
332 (setq appt-comp-time (caar (car appt-time-msg-list))))) 320 ;; If we have an appointment between midnight and
333 ;; If we have an appointment between midnight and 321 ;; `appt-warn-time' minutes after midnight, we
334 ;; `appt-warn-time' minutes after midnight, we 322 ;; must begin to issue a message before midnight. Midnight
335 ;; must begin to issue a message before midnight. Midnight 323 ;; is considered 0 minutes and 11:59pm is 1439
336 ;; is considered 0 minutes and 11:59pm is 1439 324 ;; minutes. Therefore we must recalculate the minutes to
337 ;; minutes. Therefore we must recalculate the minutes to 325 ;; appointment variable. It is equal to the number of
338 ;; appointment variable. It is equal to the number of 326 ;; minutes before midnight plus the number of minutes after
339 ;; minutes before midnight plus the number of minutes after 327 ;; midnight our appointment is.
340 ;; midnight our appointment is. 328 (if (and (< appt-comp-time appt-warn-time)
341 (if (and (< appt-comp-time appt-warn-time) 329 (> (+ cur-comp-time appt-warn-time)
342 (> (+ cur-comp-time appt-warn-time) 330 appt-max-time))
343 appt-max-time)) 331 (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time)
344 (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time) 332 appt-comp-time)))
345 appt-comp-time))) 333 ;; Issue warning if the appointment time is within
346 ;; Issue warning if the appointment time is within 334 ;; appt-message-warning time.
347 ;; appt-message-warning time. 335 (when (and (<= min-to-app appt-warn-time)
348 (when (and (<= min-to-app appt-warn-time) 336 (>= min-to-app 0))
349 (>= min-to-app 0)) 337 (setq appt-display-count (1+ prev-appt-display-count))
350 (setq appt-now-displayed t 338 ;; This is true every appt-display-interval minutes.
351 appt-display-count (1+ prev-appt-display-count)) 339 (and (zerop (mod prev-appt-display-count appt-display-interval))
352 (unless mode-line-only 340 (appt-display-message (cadr (car appt-time-msg-list))
353 (appt-display-message (cadr (car appt-time-msg-list)) 341 min-to-app))
354 min-to-app)) 342 (when appt-display-mode-line
355 (when appt-display-mode-line 343 (setq appt-mode-string
356 (setq appt-mode-string 344 (concat " " (propertize
357 (concat " " (propertize 345 (format "App't in %s min." min-to-app)
358 (format "App't in %s min." min-to-app) 346 'face 'mode-line-emphasis))))
359 'face 'mode-line-emphasis)))) 347 ;; When an appointment is reached, delete it from the
360 ;; When an appointment is reached, delete it from the 348 ;; list. Reset the count to 0 in case we display another
361 ;; list. Reset the count to 0 in case we display another 349 ;; appointment on the next cycle.
362 ;; appointment on the next cycle. 350 (if (zerop min-to-app)
363 (if (zerop min-to-app) 351 (setq appt-time-msg-list (cdr appt-time-msg-list)
364 (setq appt-time-msg-list (cdr appt-time-msg-list) 352 appt-display-count nil))))
365 appt-display-count nil)))) 353 ;; If we have changed the mode line string, redisplay all mode lines.
366 ;; If we have changed the mode line string, redisplay all mode lines. 354 (and appt-display-mode-line
367 (and appt-display-mode-line 355 (not (string-equal appt-mode-string
368 (not (string-equal appt-mode-string 356 prev-appt-mode-string))
369 prev-appt-mode-string)) 357 (progn
370 (progn 358 (force-mode-line-update t)
371 (force-mode-line-update t) 359 ;; If the string now has a notification, redisplay right now.
372 ;; If the string now has a notification, redisplay right now. 360 (if appt-mode-string
373 (if appt-mode-string 361 (sit-for 0)))))))
374 (sit-for 0))))))))
375 362
376(defun appt-disp-window (min-to-app new-time appt-msg) 363(defun appt-disp-window (min-to-app new-time appt-msg)
377 "Display appointment due in MIN-TO-APP (a string) minutes. 364 "Display appointment due in MIN-TO-APP (a string) minutes.