Function: appt-check

appt-check is an interactive and byte-compiled function defined in appt.el.gz.

Signature

(appt-check &optional FORCE)

Documentation

Check for an appointment and update any reminder display.

If optional argument FORCE is non-nil, reparse the diary file for appointments. Otherwise the diary file is only parsed once per day, or when it (or a file it includes) is saved.

Note: the time must be the first thing in the line in the diary for a warning to be issued. The format of the time can be either
24 hour or am/pm. For example:

              02/23/89
                18:00 Dinner

              Thursday
                11:45am Lunch meeting.

Appointments are checked every appt-display-interval minutes. The following variables control appointment notification:

appt-display-format
        Controls the format in which reminders are displayed.

appt-audible
        Non-nil means there is an audible component to reminders.

appt-message-warning-time
        The default number of minutes in advance at which reminders
        should start.

appt-display-mode-line
        Non-nil means show in the mode line a countdown to the
        time of each appointment, once reminders start.

appt-display-interval
        Interval in minutes at which to display appointment messages.

appt-display-diary
        Non-nil means display the diary whenever the appointment list is
        initialized (e.g. the first time we check for appointments each day).

The following variables are only relevant if reminders are being displayed in a window:

appt-display-duration
        Number of seconds for which an appointment message is displayed.

appt-disp-window-function
        Function called to display appointment window.

appt-delete-window-function
        Function called to remove appointment window and buffer.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/appt.el.gz
(defun appt-check (&optional force)
  "Check for an appointment and update any reminder display.
If optional argument FORCE is non-nil, reparse the diary file for
appointments.  Otherwise the diary file is only parsed once per day,
or when it (or a file it includes) is saved.

Note: the time must be the first thing in the line in the diary
for a warning to be issued.  The format of the time can be either
24 hour or am/pm.  For example:

              02/23/89
                18:00 Dinner

              Thursday
                11:45am Lunch meeting.

Appointments are checked every `appt-display-interval' minutes.
The following variables control appointment notification:

`appt-display-format'
        Controls the format in which reminders are displayed.

`appt-audible'
        Non-nil means there is an audible component to reminders.

`appt-message-warning-time'
        The default number of minutes in advance at which reminders
        should start.

`appt-display-mode-line'
        Non-nil means show in the mode line a countdown to the
        time of each appointment, once reminders start.

`appt-display-interval'
        Interval in minutes at which to display appointment messages.

`appt-display-diary'
        Non-nil means display the diary whenever the appointment list is
        initialized (e.g. the first time we check for appointments each day).

The following variables are only relevant if reminders are being
displayed in a window:

`appt-display-duration'
        Number of seconds for which an appointment message is displayed.

`appt-disp-window-function'
        Function called to display appointment window.

`appt-delete-window-function'
        Function called to remove appointment window and buffer."
  (interactive "P")                     ; so people can force updates
  (let* ((prev-appt-mode-string appt-mode-string)
         (prev-appt-display-count appt-display-count)
         ;; Convert current time to minutes after midnight (12.01am = 1).
         (now (decode-time))
         (now-mins (+ (* 60 (decoded-time-hour now)) (decoded-time-minute now)))
         appt-mins appt-warn-time min-to-app min-list string-list)
    (save-excursion                   ; FIXME ?
      ;; 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
              (< now-mins appt-prev-comp-time)) ; new day
          (ignore-errors
            (let ((diary-hook (if (memq #'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)))))
      ;; Reset everything now in case we somehow missed a minute,
      ;; or (more likely) an appt was deleted.  (This is the only
      ;; reason we need prev-appt-display-count.)
      (setq appt-prev-comp-time now-mins
            appt-mode-string nil
            appt-display-count 0)
      ;; If there are entries in the list get each time off of the
      ;; list and calculate the number of minutes until the appointment.
      ;; TODO we are looping over all the appointments each time.
      ;; We could instead sort them by the time at which we need to
      ;; start warning.  But then removing entries in the past becomes
      ;; less straightforward.
      (dolist (appt appt-time-msg-list)
        ;; Remove any entries that are in the past.
        ;; FIXME how can there be any such entries, given that this
        ;; function removes entries when they hit zero minutes,
        ;; and appt-make-list doesn't add any in the past in the first place?
        (if (< (setq appt-mins (caar appt)) now-mins)
            (setq appt-time-msg-list (cdr appt-time-msg-list))
          (setq appt-warn-time (or (nth 3 appt) appt-message-warning-time)
                min-to-app (- appt-mins now-mins))
          ;; 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.
          ;; FIXME but appt-make-list constructs appt-time-msg-list to only
          ;; contain entries with today's date, so this cannot work?
          ;; Also above we just removed anything with appt-mins < now-mins.
          (if (and (< appt-mins appt-warn-time)
                   (> (+ now-mins appt-warn-time) appt-max-time))
              (setq min-to-app (+ (- (1+ appt-max-time) now-mins)
                                  appt-mins)))
          ;; Issue warning if the appointment time is within the warning time.
          (when (and (<= min-to-app appt-warn-time)
                     (>= min-to-app 0))
            (push min-to-app min-list)
            (push (cadr appt) string-list)
            ;; When an appointment is reached, delete it from the list.
            (if (zerop min-to-app)
                (setq appt-time-msg-list (delete appt appt-time-msg-list))))))
      (when min-list
        (setq min-list (nreverse min-list)
              string-list (nreverse string-list))
        ;; This is true every appt-display-interval minutes from the
        ;; time at which we first started reminding.
        ;; TODO in the case of multiple appointments, whose interval
        ;; should we respect?  The first one that we started warning about?
        ;; That's what we do now, and this makes sense if you interpret
        ;; a-d-i as "don't remind me any more frequently than this".
        ;; But should we always show a message when a new appt becomes due?
        ;; When one appt gets removed, should we switch to the interval
        ;; of the next?
        (and (zerop (mod prev-appt-display-count appt-display-interval))
             (appt-display-message string-list min-list))
        (when appt-display-mode-line
          (setq appt-mode-string
                (concat (propertize
                         (appt-mode-line (mapcar #'number-to-string
                                                 min-list)
                                         t)
                         'face 'appt-notification)
                        " ")))
        ;; Reset count to 0 in case we display another appt on the next cycle.
        (setq appt-display-count (if (equal '(0) min-list) 0
                                   (1+ prev-appt-display-count))))
      ;; 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)))))))