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