Update maintainer.
[bpt/emacs.git] / lisp / calendar / appt.el
1 ;;; appt.el --- appointment notification functions
2
3 ;; Copyright (C) 1989, 1990, 1994, 1998, 2004 Free Software Foundation, Inc.
4
5 ;; Author: Neil Mager <neilm@juliet.ll.mit.edu>
6 ;; Maintainer: Glenn Morris <gmorris@ast.cam.ac.uk>
7 ;; Keywords: calendar
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;
29 ;; appt.el - visible and/or audible notification of
30 ;; appointments from diary file.
31 ;;
32 ;;;
33 ;;; Thanks to Edward M. Reingold for much help and many suggestions,
34 ;;; And to many others for bug fixes and suggestions.
35 ;;;
36 ;;;
37 ;;; This functions in this file will alert the user of a
38 ;;; pending appointment based on his/her diary file. This package
39 ;;; is documented in the Emacs manual.
40 ;;;
41 ;;; To activate this package, simply use (appt-activate 1).
42 ;;; A `diary-file' with appointments of the format described in the
43 ;;; documentation of the function `appt-check' is required.
44 ;;; Relevant customizable variables are also listed in the
45 ;;; documentation of that function.
46 ;;;
47 ;;; Today's appointment list is initialized from the diary when this
48 ;;; package is activated. Additionally, the appointments list is
49 ;;; recreated automatically at 12:01am for those who do not logout
50 ;;; every day or are programming late. It is also updated when the
51 ;;; `diary-file' is saved. Calling `appt-check' with an argument forces
52 ;;; a re-initialization at any time.
53 ;;;
54 ;;; In order to add or delete items from today's list, without
55 ;;; changing the diary file, use `appt-add' and `appt-delete'.
56 ;;;
57
58 ;;; Brief internal description - Skip this if you are not interested!
59 ;;;
60 ;;; The function `appt-make-list' creates the appointments list which
61 ;;; `appt-check' reads.
62 ;;;
63 ;;; You can change the way the appointment window is created/deleted by
64 ;;; setting the variables
65 ;;;
66 ;;; appt-disp-window-function
67 ;;; and
68 ;;; appt-delete-window-function
69 ;;;
70 ;;; For instance, these variables could be set to functions that display
71 ;;; appointments in pop-up frames, which are lowered or iconified after
72 ;;; `appt-display-interval' minutes.
73 ;;;
74
75 ;;; Code:
76
77 ;; Make sure calendar is loaded when we compile this.
78 (require 'calendar)
79
80
81 ;;;###autoload
82 (defcustom appt-issue-message t
83 "*Non-nil means check for appointments in the diary buffer.
84 To be detected, the diary entry must have the format described in the
85 documentation of the function `appt-check'."
86 :type 'boolean
87 :group 'appt)
88
89 (make-obsolete-variable 'appt-issue-message
90 "use the function `appt-activate', and the \
91 variable `appt-display-format' instead." "22.1")
92
93 ;;;###autoload
94 (defcustom appt-message-warning-time 12
95 "*Time in minutes before an appointment that the warning begins."
96 :type 'integer
97 :group 'appt)
98
99 ;;;###autoload
100 (defcustom appt-audible t
101 "*Non-nil means beep to indicate appointment."
102 :type 'boolean
103 :group 'appt)
104
105 ;;;###autoload
106 (defcustom appt-visible t
107 "*Non-nil means display appointment message in echo area.
108 This variable is only relevant if `appt-msg-window' is nil."
109 :type 'boolean
110 :group 'appt)
111
112 (make-obsolete-variable 'appt-visible 'appt-display-format "22.1")
113
114 ;;;###autoload
115 (defcustom appt-msg-window t
116 "*Non-nil means display appointment message in another window.
117 If non-nil, this variable overrides `appt-visible'."
118 :type 'boolean
119 :group 'appt)
120
121 (make-obsolete-variable 'appt-msg-window 'appt-display-format "22.1")
122
123 ;; TODO - add popup.
124 (defcustom appt-display-format 'ignore
125 "How appointment reminders should be displayed.
126 The options are:
127 window - use a separate window
128 echo - use the echo area
129 nil - no visible reminder.
130 See also `appt-audible' and `appt-display-mode-line'.
131
132 The default value is 'ignore, which means to fall back on the value
133 of the (obsolete) variables `appt-msg-window' and `appt-visible'."
134 :type '(choice
135 (const :tag "Separate window" window)
136 (const :tag "Echo-area" echo)
137 (const :tag "No visible display" nil))
138 :group 'appt
139 :version "22.1")
140
141 ;;;###autoload
142 (defcustom appt-display-mode-line t
143 "*Non-nil means display minutes to appointment and time on the mode line.
144 This is in addition to any other display of appointment messages."
145 :type 'boolean
146 :group 'appt)
147
148 ;;;###autoload
149 (defcustom appt-display-duration 10
150 "*The number of seconds an appointment message is displayed.
151 Only relevant if reminders are to be displayed in their own window."
152 :type 'integer
153 :group 'appt)
154
155 ;;;###autoload
156 (defcustom appt-display-diary t
157 "*Non-nil displays the diary when the appointment list is first initialized.
158 This will occur at midnight when the appointment list is updated."
159 :type 'boolean
160 :group 'appt)
161
162 (defcustom appt-display-interval 3
163 "*Number of minutes to wait between checking the appointment list."
164 :type 'integer
165 :group 'appt)
166
167 (defcustom appt-disp-window-function 'appt-disp-window
168 "Function called to display appointment window.
169 Only relevant if reminders are being displayed in a window."
170 :type '(choice (const appt-disp-window)
171 function)
172 :group 'appt)
173
174 (defcustom appt-delete-window-function 'appt-delete-window
175 "Function called to remove appointment window and buffer.
176 Only relevant if reminders are being displayed in a window."
177 :type '(choice (const appt-delete-window)
178 function)
179 :group 'appt)
180
181
182 ;;; Internal variables below this point.
183
184 (defconst appt-buffer-name " *appt-buf*"
185 "Name of the appointments buffer.")
186
187 (defvar appt-time-msg-list nil
188 "The list of appointments for today.
189 Use `appt-add' and `appt-delete' to add and delete appointments.
190 The original list is generated from today's `diary-entries-list', and
191 can be regenerated using the function `appt-check'.
192 Each element of the generated list has the form (MINUTES STRING [FLAG]); where
193 MINUTES is the time in minutes of the appointment after midnight, and
194 STRING is the description of the appointment.
195 FLAG, if non-nil, says that the element was made with `appt-add'
196 so calling `appt-make-list' again should preserve it.")
197
198 (defconst appt-max-time 1439
199 "11:59pm in minutes - number of minutes in a day minus 1.")
200
201 (defvar appt-mode-string nil
202 "String being displayed in the mode line saying you have an appointment.
203 The actual string includes the amount of time till the appointment.
204 Only used if `appt-display-mode-line' is non-nil.")
205
206 (defvar appt-prev-comp-time nil
207 "Time of day (mins since midnight) at which we last checked appointments.
208 A nil value forces the diary file to be (re-)checked for appointments.")
209
210 (defvar appt-now-displayed nil
211 "Non-nil when we have started notifying about a appointment that is near.")
212
213 (defvar appt-display-count nil
214 "Internal variable used to count number of consecutive reminders.")
215
216 (defvar appt-timer nil
217 "Timer used for diary appointment notifications (`appt-check').
218 If this is non-nil, appointment checking is active.")
219
220
221 ;;; Functions.
222
223 (defun appt-display-message (string mins)
224 "Display a reminder about an appointment.
225 The string STRING describes the appointment, due in integer MINS minutes.
226 The format of the visible reminder is controlled by `appt-display-format'.
227 The variable `appt-audible' controls the audible reminder."
228 ;; let binding for backwards compatability. Remove when obsolete
229 ;; vars appt-msg-window and appt-visible are dropped.
230 (let ((appt-display-format
231 (if (eq appt-display-format 'ignore)
232 (cond (appt-msg-window 'window)
233 (appt-visible 'echo))
234 appt-display-format)))
235 (cond ((eq appt-display-format 'window)
236 (funcall appt-disp-window-function
237 (number-to-string mins)
238 (format-time-string "%a %b %e " (current-time))
239 string)
240 (run-at-time (format "%d sec" appt-display-duration)
241 nil
242 appt-delete-window-function))
243 ((eq appt-display-format 'echo)
244 (message "%s" string)))
245 (if appt-audible (beep 1))))
246
247
248 (defun appt-check (&optional force)
249 "Check for an appointment and update any reminder display.
250 If optional argument FORCE is non-nil, reparse the diary file for
251 appointments. Otherwise the diary file is only parsed once per day,
252 and when saved.
253
254 Note: the time must be the first thing in the line in the diary
255 for a warning to be issued. The format of the time can be either
256 24 hour or am/pm. For example:
257
258 02/23/89
259 18:00 Dinner
260
261 Thursday
262 11:45am Lunch meeting.
263
264 Appointments are checked every `appt-display-interval' minutes.
265 The following variables control appointment notification:
266
267 `appt-display-format'
268 Controls the format in which reminders are displayed.
269
270 `appt-audible'
271 Variable used to determine if reminder is audible.
272 Default is t.
273
274 `appt-message-warning-time'
275 Variable used to determine when appointment message
276 should first be displayed.
277
278 `appt-display-mode-line'
279 If non-nil, a generic message giving the time remaining
280 is shown in the mode-line when an appointment is due.
281
282 `appt-display-interval'
283 Interval in minutes at which to check for pending appointments.
284
285 `appt-display-diary'
286 Display the diary buffer when the appointment list is
287 initialized for the first time in a day.
288
289 The following variables are only relevant if reminders are being
290 displayed in a window:
291
292 `appt-display-duration'
293 The number of seconds an appointment message is displayed.
294
295 `appt-disp-window-function'
296 Function called to display appointment window.
297
298 `appt-delete-window-function'
299 Function called to remove appointment window and buffer."
300
301 (let* ((min-to-app -1)
302 (prev-appt-mode-string appt-mode-string)
303 (prev-appt-display-count (or appt-display-count 0))
304 ;; Non-nil means do a full check for pending appointments
305 ;; and display in whatever ways the user has selected.
306 ;; When no appointment is being displayed,
307 ;; we always do a full check.
308 (full-check
309 (or (not appt-now-displayed)
310 ;; This is true every appt-display-interval minutes.
311 (zerop (mod prev-appt-display-count appt-display-interval))))
312 ;; Non-nil means only update the interval displayed in the mode line.
313 (mode-line-only
314 (and (not full-check) appt-now-displayed)))
315
316 (when (or full-check mode-line-only)
317 (save-excursion
318
319 ;; Get the current time and convert it to minutes
320 ;; from midnight. ie. 12:01am = 1, midnight = 0.
321
322 (let* ((now (decode-time))
323 (cur-hour (nth 2 now))
324 (cur-min (nth 1 now))
325 (cur-comp-time (+ (* cur-hour 60) cur-min)))
326
327 ;; At the first check in any given day, update our
328 ;; appointments to today's list.
329
330 (if (or force ; eg initialize, diary save
331 (null appt-prev-comp-time) ; first check
332 (< cur-comp-time appt-prev-comp-time)) ; new day
333 (condition-case nil
334 (if appt-display-diary
335 (let ((diary-hook
336 (if (assoc 'appt-make-list diary-hook)
337 diary-hook
338 (cons 'appt-make-list diary-hook))))
339 (diary))
340 (let ((diary-display-hook 'appt-make-list)
341 (d-buff (find-buffer-visiting
342 (substitute-in-file-name diary-file)))
343 selective)
344 (if d-buff ; diary buffer exists
345 (with-current-buffer d-buff
346 (setq selective selective-display)))
347 (diary)
348 ;; If the diary buffer existed before this command,
349 ;; restore its display state. Otherwise, kill it.
350 (if d-buff
351 ;; Displays the diary buffer.
352 (or selective (show-all-diary-entries))
353 (and
354 (setq d-buff (find-buffer-visiting
355 (substitute-in-file-name diary-file)))
356 (kill-buffer d-buff)))))
357 (error nil)))
358
359 (setq appt-prev-comp-time cur-comp-time
360 appt-mode-string nil
361 appt-display-count nil)
362
363 ;; If there are entries in the list, and the
364 ;; user wants a message issued,
365 ;; get the first time off of the list
366 ;; and calculate the number of minutes until the appointment.
367
368 (if (and appt-issue-message appt-time-msg-list)
369 (let ((appt-comp-time (car (car (car appt-time-msg-list)))))
370 (setq min-to-app (- appt-comp-time cur-comp-time))
371
372 (while (and appt-time-msg-list
373 (< appt-comp-time cur-comp-time))
374 (setq appt-time-msg-list (cdr appt-time-msg-list))
375 (if appt-time-msg-list
376 (setq appt-comp-time
377 (car (car (car appt-time-msg-list))))))
378
379 ;; If we have an appointment between midnight and
380 ;; 'appt-message-warning-time' minutes after midnight,
381 ;; we must begin to issue a message before midnight.
382 ;; Midnight is considered 0 minutes and 11:59pm is
383 ;; 1439 minutes. Therefore we must recalculate the minutes
384 ;; to appointment variable. It is equal to the number of
385 ;; minutes before midnight plus the number of
386 ;; minutes after midnight our appointment is.
387
388 (if (and (< appt-comp-time appt-message-warning-time)
389 (> (+ cur-comp-time appt-message-warning-time)
390 appt-max-time))
391 (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time))
392 appt-comp-time))
393
394 ;; issue warning if the appointment time is
395 ;; within appt-message-warning time
396
397 (when (and (<= min-to-app appt-message-warning-time)
398 (>= min-to-app 0))
399 (setq appt-now-displayed t
400 appt-display-count (1+ prev-appt-display-count))
401 (unless mode-line-only
402 (appt-display-message (cadr (car appt-time-msg-list))
403 min-to-app))
404 (when appt-display-mode-line
405 (setq appt-mode-string
406 (format " App't in %s min." min-to-app)))
407
408 ;; When an appointment is reached,
409 ;; delete it from the list.
410 ;; Reset the count to 0 in case we display another
411 ;; appointment on the next cycle.
412 (if (zerop min-to-app)
413 (setq appt-time-msg-list (cdr appt-time-msg-list)
414 appt-display-count nil)))))
415
416 ;; If we have changed the mode line string,
417 ;; redisplay all mode lines.
418 (and appt-display-mode-line
419 (not (equal appt-mode-string
420 prev-appt-mode-string))
421 (progn
422 (force-mode-line-update t)
423 ;; If the string now has a notification,
424 ;; redisplay right now.
425 (if appt-mode-string
426 (sit-for 0)))))))))
427
428
429 (defun appt-disp-window (min-to-app new-time appt-msg)
430 "Display appointment message APPT-MSG in a separate buffer.
431 The appointment is due in MIN-TO-APP (a string) minutes.
432 NEW-TIME is a string giving the date."
433 (require 'electric)
434
435 ;; Make sure we're not in the minibuffer
436 ;; before splitting the window.
437
438 (if (equal (selected-window) (minibuffer-window))
439 (if (other-window 1)
440 (select-window (other-window 1))
441 (if (display-multi-frame-p)
442 (select-frame (other-frame 1)))))
443
444 (let ((this-window (selected-window))
445 (appt-disp-buf (set-buffer (get-buffer-create appt-buffer-name))))
446
447 (if (cdr (assq 'unsplittable (frame-parameters)))
448 ;; In an unsplittable frame, use something somewhere else.
449 (display-buffer appt-disp-buf)
450 (unless (or (special-display-p (buffer-name appt-disp-buf))
451 (same-window-p (buffer-name appt-disp-buf)))
452 ;; By default, split the bottom window and use the lower part.
453 (appt-select-lowest-window)
454 (select-window (split-window)))
455 (switch-to-buffer appt-disp-buf))
456 (calendar-set-mode-line
457 (format " Appointment in %s minutes. %s " min-to-app new-time))
458 (erase-buffer)
459 (insert appt-msg)
460 (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t))
461 (set-buffer-modified-p nil)
462 (raise-frame (selected-frame))
463 (select-window this-window)))
464
465 (defun appt-delete-window ()
466 "Function called to undisplay appointment messages.
467 Usually just deletes the appointment buffer."
468 (let ((window (get-buffer-window appt-buffer-name t)))
469 (and window
470 (or (eq window (frame-root-window (window-frame window)))
471 (delete-window window))))
472 (kill-buffer appt-buffer-name)
473 (if appt-audible
474 (beep 1)))
475
476 (defun appt-select-lowest-window ()
477 "Select the lowest window on the frame."
478 (let ((lowest-window (selected-window))
479 (bottom-edge (nth 3 (window-edges))))
480 (walk-windows (lambda (w)
481 (let ((next-bottom-edge (nth 3 (window-edges w))))
482 (when (< bottom-edge next-bottom-edge)
483 (setq bottom-edge next-bottom-edge
484 lowest-window w)))))
485 (select-window lowest-window)))
486
487 ;;;###autoload
488 (defun appt-add (new-appt-time new-appt-msg)
489 "Add an appointment for today at NEW-APPT-TIME with message NEW-APPT-MSG.
490 The time should be in either 24 hour format or am/pm format."
491 (interactive "sTime (hh:mm[am/pm]): \nsMessage: ")
492 (unless (string-match "[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?"
493 new-appt-time)
494 (error "Unacceptable time-string"))
495 (let* ((appt-time-string (concat new-appt-time " " new-appt-msg))
496 (appt-time (list (appt-convert-time new-appt-time)))
497 (time-msg (list appt-time appt-time-string t)))
498 (setq appt-time-msg-list (nconc appt-time-msg-list (list time-msg)))
499 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))))
500
501 ;;;###autoload
502 (defun appt-delete ()
503 "Delete an appointment from the list of appointments."
504 (interactive)
505 (let ((tmp-msg-list appt-time-msg-list))
506 (while tmp-msg-list
507 (let* ((element (car tmp-msg-list))
508 (prompt-string (concat "Delete "
509 ;; We want to quote any doublequotes
510 ;; in the string, as well as put
511 ;; doublequotes around it.
512 (prin1-to-string
513 (substring-no-properties
514 (car (cdr element)) 0))
515 " from list? "))
516 (test-input (y-or-n-p prompt-string)))
517 (setq tmp-msg-list (cdr tmp-msg-list))
518 (if test-input
519 (setq appt-time-msg-list (delq element appt-time-msg-list)))))
520 (appt-check)
521 (message "")))
522
523
524 (eval-when-compile (defvar number)
525 (defvar original-date)
526 (defvar diary-entries-list))
527 ;;;###autoload
528 (defun appt-make-list ()
529 "Update the appointments list from today's diary buffer.
530 The time must be at the beginning of a line for it to be
531 put in the appointments list (see examples in documentation of
532 the function `appt-check'). We assume that the variables DATE and
533 NUMBER hold the arguments that `list-diary-entries' received.
534 They specify the range of dates that the diary is being processed for.
535
536 Any appointments made with `appt-add' are not affected by this
537 function."
538
539 ;; We have something to do if the range of dates that the diary is
540 ;; considering includes the current date.
541 (if (and (not (calendar-date-compare
542 (list (calendar-current-date))
543 (list original-date)))
544 (calendar-date-compare
545 (list (calendar-current-date))
546 (list (calendar-gregorian-from-absolute
547 (+ (calendar-absolute-from-gregorian original-date)
548 number)))))
549 (save-excursion
550 ;; Clear the appointments list, then fill it in from the diary.
551 (dolist (elt appt-time-msg-list)
552 ;; Delete any entries that were not made with appt-add.
553 (unless (nth 2 elt)
554 (setq appt-time-msg-list
555 (delq elt appt-time-msg-list))))
556 (if diary-entries-list
557
558 ;; Cycle through the entry-list (diary-entries-list)
559 ;; looking for entries beginning with a time. If
560 ;; the entry begins with a time, add it to the
561 ;; appt-time-msg-list. Then sort the list.
562
563 (let ((entry-list diary-entries-list)
564 (new-time-string ""))
565 ;; Skip diary entries for dates before today.
566 (while (and entry-list
567 (calendar-date-compare
568 (car entry-list) (list (calendar-current-date))))
569 (setq entry-list (cdr entry-list)))
570 ;; Parse the entries for today.
571 (while (and entry-list
572 (calendar-date-equal
573 (calendar-current-date) (car (car entry-list))))
574 (let ((time-string (cadr (car entry-list))))
575 (while (string-match
576 "\\([0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?\\).*"
577 time-string)
578 (let* ((beg (match-beginning 0))
579 ;; Get just the time for this appointment.
580 (only-time (match-string 1 time-string))
581 ;; Find the end of this appointment
582 ;; (the start of the next).
583 (end (string-match
584 "^[ \t]*[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?"
585 time-string
586 (match-end 0)))
587 ;; Get the whole string for this appointment.
588 (appt-time-string
589 (substring time-string beg (if end (1- end)))))
590
591 ;; Add this appointment to appt-time-msg-list.
592 (let* ((appt-time (list (appt-convert-time only-time)))
593 (time-msg (list appt-time appt-time-string)))
594 (setq appt-time-msg-list
595 (nconc appt-time-msg-list (list time-msg))))
596
597 ;; Discard this appointment from the string.
598 (setq time-string
599 (if end (substring time-string end) "")))))
600 (setq entry-list (cdr entry-list)))))
601 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))
602
603 ;; Get the current time and convert it to minutes
604 ;; from midnight. ie. 12:01am = 1, midnight = 0,
605 ;; so that the elements in the list
606 ;; that are earlier than the present time can
607 ;; be removed.
608
609 (let* ((now (decode-time))
610 (cur-hour (nth 2 now))
611 (cur-min (nth 1 now))
612 (cur-comp-time (+ (* cur-hour 60) cur-min))
613 (appt-comp-time (car (caar appt-time-msg-list))))
614
615 (while (and appt-time-msg-list (< appt-comp-time cur-comp-time))
616 (setq appt-time-msg-list (cdr appt-time-msg-list))
617 (if appt-time-msg-list
618 (setq appt-comp-time (car (caar appt-time-msg-list)))))))))
619
620
621 (defun appt-sort-list (appt-list)
622 "Sort an appointment list, putting earlier items at the front.
623 APPT-LIST is a list of the same format as `appt-time-msg-list'."
624 (sort appt-list (lambda (e1 e2) (< (caar e1) (caar e2)))))
625
626
627 (defun appt-convert-time (time2conv)
628 "Convert hour:min[am/pm] format to minutes from midnight.
629 A period (.) can be used instead of a colon (:) to separate the
630 hour and minute parts."
631 (let ((conv-time 0)
632 (hr 0)
633 (min 0))
634
635 (string-match "[:.]\\([0-9][0-9]\\)" time2conv)
636 (setq min (string-to-int
637 (match-string 1 time2conv)))
638
639 (string-match "[0-9]?[0-9][:.]" time2conv)
640 (setq hr (string-to-int
641 (match-string 0 time2conv)))
642
643 ;; convert the time appointment time into 24 hour time
644
645 (cond ((and (string-match "pm" time2conv) (< hr 12))
646 (setq hr (+ 12 hr)))
647 ((and (string-match "am" time2conv) (= hr 12))
648 (setq hr 0)))
649
650 ;; convert the actual time
651 ;; into minutes for comparison
652 ;; against the actual time.
653
654 (setq conv-time (+ (* hr 60) min))
655 conv-time))
656
657
658 (defun appt-update-list ()
659 "If the current buffer is visiting the diary, update appointments.
660 This function is intended for use with `write-file-functions'."
661 (and (string-equal buffer-file-name (expand-file-name diary-file))
662 appt-timer
663 (let ((appt-display-diary nil))
664 (appt-check t)))
665 nil)
666
667
668 ;;;###autoload
669 (defun appt-activate (&optional arg)
670 "Toggle checking of appointments.
671 With optional numeric argument ARG, turn appointment checking on if
672 ARG is positive, otherwise off."
673 (interactive "P")
674 (let ((appt-active appt-timer))
675 (setq appt-active (if arg (> (prefix-numeric-value arg) 0)
676 (not appt-active)))
677 (remove-hook 'write-file-functions 'appt-update-list)
678 (or global-mode-string (setq global-mode-string '("")))
679 (delq 'appt-mode-string global-mode-string)
680 (when appt-timer
681 (cancel-timer appt-timer)
682 (setq appt-timer nil))
683 (when appt-active
684 (add-hook 'write-file-functions 'appt-update-list)
685 (setq appt-timer (run-at-time t 60 'appt-check)
686 global-mode-string
687 (append global-mode-string '(appt-mode-string)))
688 (appt-check t))))
689
690
691 ;; This is needed for backwards compatibility. Feh.
692 (appt-activate 1)
693
694
695 (provide 'appt)
696
697 ;;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347
698 ;;; appt.el ends here