* lisp/calendar/appt.el (appt-check): Doc fix.
[emacs.git] / lisp / calendar / appt.el
blobc850abc63cc7422ac740d42eb1c5937b61663f29
1 ;;; appt.el --- appointment notification functions
3 ;; Copyright (C) 1989, 1990, 1994, 1998, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Neil Mager <neilm@juliet.ll.mit.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
8 ;; Keywords: calendar
10 ;; This file is part of GNU Emacs.
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.
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.
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/>.
25 ;;; Commentary:
28 ;; appt.el - visible and/or audible notification of
29 ;; appointments from diary file.
32 ;; Thanks to Edward M. Reingold for much help and many suggestions,
33 ;; And to many others for bug fixes and suggestions.
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.
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.
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.
54 ;; In order to add or delete items from today's list, without
55 ;; changing the diary file, use `appt-add' and `appt-delete'.
58 ;; Brief internal description - Skip this if you are not interested!
60 ;; The function `appt-make-list' creates the appointments list which
61 ;; `appt-check' reads.
63 ;; You can change the way the appointment window is created/deleted by
64 ;; setting the variables
66 ;; appt-disp-window-function
67 ;; and
68 ;; appt-delete-window-function
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.
75 ;;; Code:
77 (require 'diary-lib)
80 (defgroup appt nil
81 "Appointment notification."
82 :prefix "appt-"
83 :group 'calendar)
85 (defcustom appt-issue-message t
86 "Non-nil means check for appointments in the diary buffer.
87 To be detected, the diary entry must have the format described in the
88 documentation of the function `appt-check'."
89 :type 'boolean
90 :group 'appt)
92 (make-obsolete-variable 'appt-issue-message
93 "use the function `appt-activate', and the \
94 variable `appt-display-format' instead." "22.1")
96 (defcustom appt-message-warning-time 12
97 "Time in minutes before an appointment that the warning begins."
98 :type 'integer
99 :group 'appt)
101 (defcustom appt-audible t
102 "Non-nil means beep to indicate appointment."
103 :type 'boolean
104 :group 'appt)
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)
112 (make-obsolete-variable 'appt-visible 'appt-display-format "22.1")
114 (defcustom appt-msg-window t
115 "Non-nil means display appointment message in another window.
116 If non-nil, this variable overrides `appt-visible'."
117 :type 'boolean
118 :group 'appt)
120 (make-obsolete-variable 'appt-msg-window 'appt-display-format "22.1")
122 ;; TODO - add popup.
123 (defcustom appt-display-format 'ignore
124 "How appointment reminders should be displayed.
125 The options are:
126 window - use a separate window
127 echo - use the echo area
128 nil - no visible reminder.
129 See also `appt-audible' and `appt-display-mode-line'.
131 The default value is 'ignore, which means to fall back on the value
132 of the (obsolete) variables `appt-msg-window' and `appt-visible'."
133 :type '(choice
134 (const :tag "Separate window" window)
135 (const :tag "Echo-area" echo)
136 (const :tag "No visible display" nil)
137 (const :tag "Backwards compatibility setting - choose another value"
138 ignore))
139 :group 'appt
140 :version "22.1")
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)
148 (defcustom appt-display-duration 10
149 "The number of seconds an appointment message is displayed.
150 Only relevant if reminders are to be displayed in their own window."
151 :type 'integer
152 :group 'appt)
154 (defcustom appt-display-diary t
155 "Non-nil displays the diary when the appointment list is first initialized.
156 This will occur at midnight when the appointment list is updated."
157 :type 'boolean
158 :group 'appt)
160 (defcustom appt-display-interval 3
161 "Number of minutes to wait between checking the appointment list."
162 :type 'integer
163 :group 'appt)
165 (defcustom appt-disp-window-function 'appt-disp-window
166 "Function called to display appointment window.
167 Only relevant if reminders are being displayed in a window.
168 It should take three string arguments: the number of minutes till
169 the appointment, the current time, and the text of the appointment."
170 :type '(choice (const appt-disp-window)
171 function)
172 :group 'appt)
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)
182 ;;; Internal variables below this point.
184 (defconst appt-buffer-name "*appt-buf*"
185 "Name of the appointments buffer.")
187 ;; TODO Turn this into an alist? It would be easier to add more
188 ;; optional elements.
189 ;; TODO There should be a way to set WARNTIME (and other properties)
190 ;; from the diary-file. Implementing that would be a good reason
191 ;; to change this to an alist.
192 (defvar appt-time-msg-list nil
193 "The list of appointments for today.
194 Use `appt-add' and `appt-delete' to add and delete appointments.
195 The original list is generated from today's `diary-entries-list', and
196 can be regenerated using the function `appt-check'.
197 Each element of the generated list has the form
198 \(MINUTES STRING [FLAG] [WARNTIME])
199 where MINUTES is the time in minutes of the appointment after midnight,
200 and STRING is the description of the appointment.
201 FLAG and WARNTIME can only be present if the element was made
202 with `appt-add'. A non-nil FLAG indicates that the element was made
203 with `appt-add', so calling `appt-make-list' again should preserve it.
204 If WARNTIME is non-nil, it is an integer to use in place
205 of `appt-message-warning-time'.")
207 (defconst appt-max-time (1- (* 24 60))
208 "11:59pm in minutes - number of minutes in a day minus 1.")
210 (defvar appt-mode-string nil
211 "String being displayed in the mode line saying you have an appointment.
212 The actual string includes the amount of time till the appointment.
213 Only used if `appt-display-mode-line' is non-nil.")
214 (put 'appt-mode-string 'risky-local-variable t) ; for 'face property
216 (defvar appt-prev-comp-time nil
217 "Time of day (mins since midnight) at which we last checked appointments.
218 A nil value forces the diary file to be (re-)checked for appointments.")
220 (defvar appt-now-displayed nil
221 "Non-nil when we have started notifying about a appointment that is near.")
223 (defvar appt-display-count nil
224 "Internal variable used to count number of consecutive reminders.")
226 (defvar appt-timer nil
227 "Timer used for diary appointment notifications (`appt-check').
228 If this is non-nil, appointment checking is active.")
231 ;;; Functions.
233 (defun appt-display-message (string mins)
234 "Display a reminder about an appointment.
235 The string STRING describes the appointment, due in integer MINS minutes.
236 The format of the visible reminder is controlled by `appt-display-format'.
237 The variable `appt-audible' controls the audible reminder."
238 ;; Let-binding for backwards compatibility. Remove when obsolete
239 ;; vars appt-msg-window and appt-visible are dropped.
240 (let ((appt-display-format
241 (if (eq appt-display-format 'ignore)
242 (cond (appt-msg-window 'window)
243 (appt-visible 'echo))
244 appt-display-format)))
245 (if appt-audible (beep 1))
246 (cond ((eq appt-display-format 'window)
247 (funcall appt-disp-window-function
248 (number-to-string mins)
249 ;; TODO - use calendar-month-abbrev-array rather than %b?
250 (format-time-string "%a %b %e " (current-time))
251 string)
252 (run-at-time (format "%d sec" appt-display-duration)
254 appt-delete-window-function))
255 ((eq appt-display-format 'echo)
256 (message "%s" string)))))
259 (defvar diary-selective-display)
261 (defun appt-check (&optional force)
262 "Check for an appointment and update any reminder display.
263 If optional argument FORCE is non-nil, reparse the diary file for
264 appointments. Otherwise the diary file is only parsed once per day,
265 or when it (or a file it includes) is saved.
267 Note: the time must be the first thing in the line in the diary
268 for a warning to be issued. The format of the time can be either
269 24 hour or am/pm. For example:
271 02/23/89
272 18:00 Dinner
274 Thursday
275 11:45am Lunch meeting.
277 Appointments are checked every `appt-display-interval' minutes.
278 The following variables control appointment notification:
280 `appt-display-format'
281 Controls the format in which reminders are displayed.
283 `appt-audible'
284 Variable used to determine if reminder is audible.
285 Default is t.
287 `appt-message-warning-time'
288 Variable used to determine when appointment message
289 should first be displayed.
291 `appt-display-mode-line'
292 If non-nil, a generic message giving the time remaining
293 is shown in the mode-line when an appointment is due.
295 `appt-display-interval'
296 Interval in minutes at which to check for pending appointments.
298 `appt-display-diary'
299 Display the diary buffer when the appointment list is
300 initialized for the first time in a day.
302 The following variables are only relevant if reminders are being
303 displayed in a window:
305 `appt-display-duration'
306 The number of seconds an appointment message is displayed.
308 `appt-disp-window-function'
309 Function called to display appointment window.
311 `appt-delete-window-function'
312 Function called to remove appointment window and buffer."
313 (interactive "P") ; so people can force updates
314 (let* ((min-to-app -1)
315 (prev-appt-mode-string appt-mode-string)
316 (prev-appt-display-count (or appt-display-count 0))
317 ;; Non-nil means do a full check for pending appointments and
318 ;; display in whatever ways the user has selected. When no
319 ;; appointment is being displayed, we always do a full check.
320 (full-check
321 (or (not appt-now-displayed)
322 ;; This is true every appt-display-interval minutes.
323 (zerop (mod prev-appt-display-count appt-display-interval))))
324 ;; Non-nil means only update the interval displayed in the mode line.
325 (mode-line-only (unless full-check appt-now-displayed))
326 now cur-comp-time appt-comp-time appt-warn-time)
327 (when (or full-check mode-line-only)
328 (save-excursion
329 ;; Convert current time to minutes after midnight (12.01am = 1).
330 (setq now (decode-time)
331 cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now)))
332 ;; At first check in any day, update appointments to today's list.
333 (if (or force ; eg initialize, diary save
334 (null appt-prev-comp-time) ; first check
335 (< cur-comp-time appt-prev-comp-time)) ; new day
336 (condition-case nil
337 (if appt-display-diary
338 (let ((diary-hook
339 (if (assoc 'appt-make-list diary-hook)
340 diary-hook
341 (cons 'appt-make-list diary-hook))))
342 (diary))
343 (let* ((diary-display-function 'appt-make-list)
344 (d-buff (find-buffer-visiting diary-file))
345 (selective
346 (if d-buff ; diary buffer exists
347 (with-current-buffer d-buff
348 diary-selective-display))))
349 ;; FIXME why not using diary-list-entries with
350 ;; non-nil LIST-ONLY?
351 (diary)
352 ;; If the diary buffer existed before this command,
353 ;; restore its display state. Otherwise, kill it.
354 (if d-buff
355 ;; Displays the diary buffer.
356 (or selective (diary-show-all-entries))
357 (and (setq d-buff (find-buffer-visiting diary-file))
358 (kill-buffer d-buff)))))
359 (error nil)))
360 (setq appt-prev-comp-time cur-comp-time
361 appt-mode-string nil
362 appt-display-count nil)
363 ;; If there are entries in the list, and the user wants a
364 ;; message issued, get the first time off of the list and
365 ;; calculate the number of minutes until the appointment.
366 (when (and appt-issue-message appt-time-msg-list)
367 (setq appt-comp-time (caar (car appt-time-msg-list))
368 appt-warn-time (or (nth 3 (car appt-time-msg-list))
369 appt-message-warning-time)
370 min-to-app (- appt-comp-time cur-comp-time))
371 (while (and appt-time-msg-list
372 (< appt-comp-time cur-comp-time))
373 (setq appt-time-msg-list (cdr appt-time-msg-list))
374 (if appt-time-msg-list
375 (setq appt-comp-time (caar (car appt-time-msg-list)))))
376 ;; If we have an appointment between midnight and
377 ;; `appt-warn-time' minutes after midnight, we
378 ;; must begin to issue a message before midnight. Midnight
379 ;; is considered 0 minutes and 11:59pm is 1439
380 ;; minutes. Therefore we must recalculate the minutes to
381 ;; appointment variable. It is equal to the number of
382 ;; minutes before midnight plus the number of minutes after
383 ;; midnight our appointment is.
384 (if (and (< appt-comp-time appt-warn-time)
385 (> (+ cur-comp-time appt-warn-time)
386 appt-max-time))
387 (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time)
388 appt-comp-time)))
389 ;; Issue warning if the appointment time is within
390 ;; appt-message-warning time.
391 (when (and (<= min-to-app appt-warn-time)
392 (>= min-to-app 0))
393 (setq appt-now-displayed t
394 appt-display-count (1+ prev-appt-display-count))
395 (unless mode-line-only
396 (appt-display-message (cadr (car appt-time-msg-list))
397 min-to-app))
398 (when appt-display-mode-line
399 (setq appt-mode-string
400 (concat " " (propertize
401 (format "App't in %s min." min-to-app)
402 'face 'mode-line-emphasis))))
403 ;; When an appointment is reached, delete it from the
404 ;; list. Reset the count to 0 in case we display another
405 ;; appointment on the next cycle.
406 (if (zerop min-to-app)
407 (setq appt-time-msg-list (cdr appt-time-msg-list)
408 appt-display-count nil))))
409 ;; If we have changed the mode line string, redisplay all mode lines.
410 (and appt-display-mode-line
411 (not (string-equal appt-mode-string
412 prev-appt-mode-string))
413 (progn
414 (force-mode-line-update t)
415 ;; If the string now has a notification, redisplay right now.
416 (if appt-mode-string
417 (sit-for 0))))))))
419 (defun appt-disp-window (min-to-app new-time appt-msg)
420 "Display appointment due in MIN-TO-APP (a string) minutes.
421 NEW-TIME is a string giving the date. Displays the appointment
422 message APPT-MSG in a separate buffer."
423 (let ((this-window (selected-window))
424 (appt-disp-buf (get-buffer-create appt-buffer-name)))
425 ;; Make sure we're not in the minibuffer before splitting the window.
426 ;; FIXME this seems needlessly complicated?
427 (when (minibufferp)
428 (other-window 1)
429 (and (minibufferp) (display-multi-frame-p) (other-frame 1)))
430 (if (cdr (assq 'unsplittable (frame-parameters)))
431 ;; In an unsplittable frame, use something somewhere else.
432 (progn
433 (set-buffer appt-disp-buf)
434 (display-buffer appt-disp-buf))
435 (unless (or (special-display-p (buffer-name appt-disp-buf))
436 (same-window-p (buffer-name appt-disp-buf)))
437 ;; By default, split the bottom window and use the lower part.
438 (appt-select-lowest-window)
439 ;; Split the window, unless it's too small to do so.
440 (when (>= (window-height) (* 2 window-min-height))
441 (select-window (split-window))))
442 (switch-to-buffer appt-disp-buf))
443 ;; FIXME Link to diary entry?
444 (calendar-set-mode-line
445 (format " Appointment %s. %s "
446 (if (string-equal "0" min-to-app) "now"
447 (format "in %s minute%s" min-to-app
448 (if (string-equal "1" min-to-app) "" "s")))
449 new-time))
450 (setq buffer-read-only nil
451 buffer-undo-list t)
452 (erase-buffer)
453 (insert appt-msg)
454 (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t))
455 (set-buffer-modified-p nil)
456 (setq buffer-read-only t)
457 (raise-frame (selected-frame))
458 (select-window this-window)))
460 (defun appt-delete-window ()
461 "Function called to undisplay appointment messages.
462 Usually just deletes the appointment buffer."
463 (let ((window (get-buffer-window appt-buffer-name t)))
464 (and window
465 (or (eq window (frame-root-window (window-frame window)))
466 (delete-window window))))
467 (kill-buffer appt-buffer-name)
468 (if appt-audible
469 (beep 1)))
471 (defun appt-select-lowest-window ()
472 "Select the lowest window on the frame."
473 (let ((lowest-window (selected-window))
474 (bottom-edge (nth 3 (window-edges)))
475 next-bottom-edge)
476 (walk-windows (lambda (w)
477 (when (< bottom-edge (setq next-bottom-edge
478 (nth 3 (window-edges w))))
479 (setq bottom-edge next-bottom-edge
480 lowest-window w))) 'nomini)
481 (select-window lowest-window)))
483 (defconst appt-time-regexp
484 "[0-9]?[0-9]\\(h\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]\\)\\(am\\|pm\\)?")
486 ;;;###autoload
487 (defun appt-add (time msg &optional warntime)
488 "Add an appointment for today at TIME with message MSG.
489 The time should be in either 24 hour format or am/pm format.
490 Optional argument WARNTIME is an integer (or string) giving the number
491 of minutes before the appointment at which to start warning.
492 The default is `appt-message-warning-time'."
493 (interactive "sTime (hh:mm[am/pm]): \nsMessage:
494 sMinutes before the appointment to start warning: ")
495 (unless (string-match appt-time-regexp time)
496 (error "Unacceptable time-string"))
497 (and (stringp warntime)
498 (setq warntime (unless (string-equal warntime "")
499 (string-to-number warntime))))
500 (and warntime
501 (not (integerp warntime))
502 (error "Argument WARNTIME must be an integer, or nil"))
503 (let ((time-msg (list (list (appt-convert-time time))
504 (concat time " " msg) t)))
505 ;; It is presently non-sensical to have multiple warnings about
506 ;; the same appointment with just different delays, but it might
507 ;; not always be so. TODO
508 (if warntime (setq time-msg (append time-msg (list warntime))))
509 (unless (member time-msg appt-time-msg-list)
510 (setq appt-time-msg-list
511 (appt-sort-list (nconc appt-time-msg-list (list time-msg)))))))
513 ;;;###autoload
514 (defun appt-delete ()
515 "Delete an appointment from the list of appointments."
516 (interactive)
517 (let ((tmp-msg-list appt-time-msg-list))
518 (dolist (element tmp-msg-list)
519 (if (y-or-n-p (concat "Delete "
520 ;; We want to quote any doublequotes in the
521 ;; string, as well as put doublequotes around it.
522 (prin1-to-string
523 (substring-no-properties (cadr element) 0))
524 " from list? "))
525 (setq appt-time-msg-list (delq element appt-time-msg-list)))))
526 (appt-check)
527 (message ""))
530 (defvar number)
531 (defvar original-date)
532 (defvar diary-entries-list)
533 ;; Autoload for the old way of using this package. Can be removed sometime.
534 ;;;###autoload
535 (defun appt-make-list ()
536 "Update the appointments list from today's diary buffer.
537 The time must be at the beginning of a line for it to be
538 put in the appointments list (see examples in documentation of
539 the function `appt-check'). We assume that the variables DATE and
540 NUMBER hold the arguments that `diary-list-entries' received.
541 They specify the range of dates that the diary is being processed for.
543 Any appointments made with `appt-add' are not affected by this function.
545 For backwards compatibility, this function activates the
546 appointment package (if it is not already active)."
547 ;; See comments above appt-activate defun.
548 (if (not appt-timer)
549 (appt-activate 1)
550 ;; We have something to do if the range of dates that the diary is
551 ;; considering includes the current date.
552 (if (and (not (calendar-date-compare
553 (list (calendar-current-date))
554 (list original-date)))
555 (calendar-date-compare
556 (list (calendar-current-date))
557 (list (calendar-gregorian-from-absolute
558 (+ (calendar-absolute-from-gregorian original-date)
559 number)))))
560 (save-excursion
561 ;; Clear the appointments list, then fill it in from the diary.
562 (dolist (elt appt-time-msg-list)
563 ;; Delete any entries that were not made with appt-add.
564 (unless (nth 2 elt)
565 (setq appt-time-msg-list
566 (delq elt appt-time-msg-list))))
567 (if diary-entries-list
568 ;; Cycle through the entry-list (diary-entries-list)
569 ;; looking for entries beginning with a time. If the
570 ;; entry begins with a time, add it to the
571 ;; appt-time-msg-list. Then sort the list.
572 (let ((entry-list diary-entries-list)
573 (new-time-string "")
574 time-string)
575 ;; Skip diary entries for dates before today.
576 (while (and entry-list
577 (calendar-date-compare
578 (car entry-list) (list (calendar-current-date))))
579 (setq entry-list (cdr entry-list)))
580 ;; Parse the entries for today.
581 (while (and entry-list
582 (calendar-date-equal
583 (calendar-current-date) (caar entry-list)))
584 (setq time-string (cadr (car entry-list)))
585 (while (string-match appt-time-regexp time-string)
586 (let* ((beg (match-beginning 0))
587 ;; Get just the time for this appointment.
588 (only-time (match-string 0 time-string))
589 ;; Find the end of this appointment
590 ;; (the start of the next).
591 (end (string-match
592 (concat "\n[ \t]*" appt-time-regexp)
593 time-string
594 (match-end 0)))
595 ;; Get the whole string for this appointment.
596 (appt-time-string
597 (substring time-string beg end))
598 (appt-time (list (appt-convert-time only-time)))
599 (time-msg (list appt-time appt-time-string)))
600 ;; Add this appointment to appt-time-msg-list.
601 (setq appt-time-msg-list
602 (nconc appt-time-msg-list (list time-msg))
603 ;; Discard this appointment from the string.
604 time-string
605 (if end (substring time-string end) ""))))
606 (setq entry-list (cdr entry-list)))))
607 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))
608 ;; Convert current time to minutes after midnight (12:01am = 1),
609 ;; so that elements in the list that are earlier than the
610 ;; present time can be removed.
611 (let* ((now (decode-time))
612 (cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now)))
613 (appt-comp-time (caar (car appt-time-msg-list))))
614 (while (and appt-time-msg-list (< appt-comp-time cur-comp-time))
615 (setq appt-time-msg-list (cdr appt-time-msg-list))
616 (if appt-time-msg-list
617 (setq appt-comp-time (caar (car appt-time-msg-list))))))))))
620 (defun appt-sort-list (appt-list)
621 "Sort an appointment list, putting earlier items at the front.
622 APPT-LIST is a list of the same format as `appt-time-msg-list'."
623 (sort appt-list (lambda (e1 e2) (< (caar e1) (caar e2)))))
626 (defun appt-convert-time (time2conv)
627 "Convert hour:min[am/pm] format TIME2CONV to minutes from midnight.
628 A period (.) can be used instead of a colon (:) to separate the
629 hour and minute parts."
630 ;; Formats that should be accepted:
631 ;; 10:00 10.00 10h00 10h 10am 10:00am 10.00am
632 (let ((min (if (string-match "[h:.]\\([0-9][0-9]\\)" time2conv)
633 (string-to-number (match-string 1 time2conv))
635 (hr (if (string-match "[0-9]*[0-9]" time2conv)
636 (string-to-number (match-string 0 time2conv))
637 0)))
638 ;; Convert the time appointment time into 24 hour time.
639 (cond ((and (string-match "pm" time2conv) (< hr 12))
640 (setq hr (+ 12 hr)))
641 ((and (string-match "am" time2conv) (= hr 12))
642 (setq hr 0)))
643 ;; Convert the actual time into minutes.
644 (+ (* hr 60) min)))
646 (defun appt-update-list ()
647 "If the current buffer is visiting the diary, update appointments.
648 This function also acts on any file listed in `diary-included-files'.
649 It is intended for use with `write-file-functions'."
650 (and (member buffer-file-name (append diary-included-files
651 (list (expand-file-name diary-file))))
652 appt-timer
653 (let ((appt-display-diary nil))
654 (appt-check t)))
655 nil)
657 ;; In Emacs-21.3, the manual documented the following procedure to
658 ;; activate this package:
659 ;; (display-time)
660 ;; (add-hook 'diary-hook 'appt-make-list)
661 ;; (diary 0)
662 ;; The display-time call was not necessary, AFAICS.
663 ;; What was really needed was to add the hook and load this file.
664 ;; Calling (diary 0) once the hook had been added was in some sense a
665 ;; roundabout way of loading this file. This file used to have code at
666 ;; the top-level that set up the appt-timer and global-mode-string.
667 ;; One way to maintain backwards compatibility would be to call
668 ;; (appt-activate 1) at top-level. However, this goes against the
669 ;; convention that just loading an Emacs package should not activate
670 ;; it. Instead, we make appt-make-list activate the package (after a
671 ;; suggestion from rms). This means that one has to call diary in
672 ;; order to get it to work, but that is in line with the old (weird,
673 ;; IMO) documented behavior for activating the package.
674 ;; Actually, since (diary 0) does not run diary-hook, I don't think
675 ;; the documented behavior in Emacs-21.3 would ever have worked.
676 ;; Oh well, at least with the changes to appt-make-list it will now
677 ;; work as well as it ever did.
678 ;; The new method is just to use (appt-activate 1).
679 ;; -- gmorris
681 ;;;###autoload
682 (defun appt-activate (&optional arg)
683 "Toggle checking of appointments.
684 With optional numeric argument ARG, turn appointment checking on if
685 ARG is positive, otherwise off."
686 (interactive "P")
687 (let ((appt-active appt-timer))
688 (setq appt-active (if arg (> (prefix-numeric-value arg) 0)
689 (not appt-active)))
690 (remove-hook 'write-file-functions 'appt-update-list)
691 (or global-mode-string (setq global-mode-string '("")))
692 (delq 'appt-mode-string global-mode-string)
693 (when appt-timer
694 (cancel-timer appt-timer)
695 (setq appt-timer nil))
696 (when appt-active
697 (add-hook 'write-file-functions 'appt-update-list)
698 (setq appt-timer (run-at-time t 60 'appt-check)
699 global-mode-string
700 (append global-mode-string '(appt-mode-string)))
701 (appt-check t))))
704 (provide 'appt)
706 ;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347
707 ;;; appt.el ends here