* alloc.c (allocate_vectorlike): Surround calls to mallopt with
[bpt/emacs.git] / lisp / calendar / appt.el
CommitLineData
55535639 1;;; appt.el --- appointment notification functions
c0274f38 2
f3e7c0dc 3;; Copyright (C) 1989, 1990, 1994, 1998 Free Software Foundation, Inc.
3a801d0c 4
e5167999 5;; Author: Neil Mager <neilm@juliet.ll.mit.edu>
0dba5606 6;; Maintainer: FSF
e5167999
ER
7;; Keywords: calendar
8
902a0e3c
JB
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
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
902a0e3c
JB
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
b578f267
EN
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.
902a0e3c 25
e5167999
ER
26;;; Commentary:
27
902a0e3c
JB
28;;
29;; appt.el - visible and/or audible notification of
f3e7c0dc 30;; appointments from ~/diary file.
902a0e3c 31;;
902a0e3c 32;;;
d073fa5b 33;;; Thanks to Edward M. Reingold for much help and many suggestions,
902a0e3c
JB
34;;; And to many others for bug fixes and suggestions.
35;;;
36;;;
a1506d29 37;;; This functions in this file will alert the user of a
902a0e3c
JB
38;;; pending appointment based on their diary file.
39;;;
f3e7c0dc
KH
40;;; A message will be displayed in the mode line of the Emacs buffer
41;;; and (if you request) the terminal will beep and display a message
a1506d29 42;;; from the diary in the mini-buffer, or you can choose to
902a0e3c
JB
43;;; have a message displayed in a new buffer.
44;;;
f3e7c0dc 45;;; The variable `appt-message-warning-time' allows the
a1506d29 46;;; user to specify how much notice they want before the appointment. The
f3e7c0dc 47;;; variable `appt-issue-message' specifies whether the user wants
e6608c12 48;;; to be notified of a pending appointment.
a1506d29 49;;;
f3e7c0dc
KH
50;;; In order to use the appt package, you only need
51;;; to load it---provided you have appointments.
902a0e3c 52;;;
efa434d9
RS
53;;; Before that, you can also set some options if you want
54;;; (setq view-diary-entries-initially t)
55;;; (setq appt-issue-message t)
a1506d29 56;;;
902a0e3c
JB
57;;; This is an example of what can be in your diary file:
58;;; Monday
59;;; 9:30am Coffee break
a1506d29
JB
60;;; 12:00pm Lunch
61;;;
62;;; Based upon the above lines in your .emacs and diary files,
902a0e3c 63;;; the calendar and diary will be displayed when you enter
f3e7c0dc 64;;; Emacs and your appointments list will automatically be created.
902a0e3c 65;;; You will then be reminded at 9:20am about your coffee break
a1506d29 66;;; and at 11:50am to go to lunch.
902a0e3c
JB
67;;;
68;;; Use describe-function on appt-check for a description of other variables
69;;; that can be used to personalize the notification system.
70;;;
71;;; In order to add or delete items from todays list, use appt-add
72;;; and appt-delete.
73;;;
74;;; Additionally, the appointments list is recreated automatically
75;;; at 12:01am for those who do not logout every day or are programming
76;;; late.
77;;;
d073fa5b 78;;; Brief internal description - Skip this if you are not interested!
902a0e3c 79;;;
902a0e3c
JB
80;;; The function appt-make-list creates the appointments list which appt-check
81;;; reads. This is all done automatically.
82;;; It is invoked from the function list-diary-entries.
83;;;
5b586155
RS
84;;; You can change the way the appointment window is created/deleted by
85;;; setting the variables
86;;;
87;;; appt-disp-window-function
88;;; and
89;;; appt-delete-window-function
90;;;
91;;; For instance, these variables can be set to functions that display
92;;; appointments in pop-up frames, which are lowered or iconified after
f3e7c0dc 93;;; appt-display-interval minutes.
5b586155 94;;;
e5167999
ER
95
96;;; Code:
97
6afadb57
RS
98;; Make sure calendar is loaded when we compile this.
99(require 'calendar)
100
cc3511de
KH
101(provide 'appt)
102
7e1dae73 103;;;###autoload
8db540c5 104(defcustom appt-issue-message t
902a0e3c
JB
105 "*Non-nil means check for appointments in the diary buffer.
106To be detected, the diary entry must have the time
8db540c5
RS
107as the first thing on a line."
108 :type 'boolean
109 :group 'appt)
902a0e3c 110
7e1dae73 111;;;###autoload
8db540c5
RS
112(defcustom appt-message-warning-time 12
113 "*Time in minutes before an appointment that the warning begins."
114 :type 'integer
115 :group 'appt)
902a0e3c 116
7e1dae73 117;;;###autoload
8db540c5
RS
118(defcustom appt-audible t
119 "*Non-nil means beep to indicate appointment."
120 :type 'boolean
121 :group 'appt)
902a0e3c 122
7e1dae73 123;;;###autoload
8db540c5
RS
124(defcustom appt-visible t
125 "*Non-nil means display appointment message in echo area."
126 :type 'boolean
127 :group 'appt)
902a0e3c 128
7e1dae73 129;;;###autoload
8db540c5
RS
130(defcustom appt-display-mode-line t
131 "*Non-nil means display minutes to appointment and time on the mode line."
132 :type 'boolean
133 :group 'appt)
902a0e3c 134
7e1dae73 135;;;###autoload
8db540c5
RS
136(defcustom appt-msg-window t
137 "*Non-nil means display appointment message in another window."
138 :type 'boolean
139 :group 'appt)
902a0e3c 140
7e1dae73 141;;;###autoload
8db540c5
RS
142(defcustom appt-display-duration 10
143 "*The number of seconds an appointment message is displayed."
144 :type 'integer
145 :group 'appt)
902a0e3c 146
7e1dae73 147;;;###autoload
8db540c5 148(defcustom appt-display-diary t
a1506d29 149 "*Non-nil means to display the next days diary on the screen.
8db540c5
RS
150This will occur at midnight when the appointment list is updated."
151 :type 'boolean
152 :group 'appt)
902a0e3c
JB
153
154(defvar appt-time-msg-list nil
155 "The list of appointments for today.
156Use `appt-add' and `appt-delete' to add and delete appointments from list.
157The original list is generated from the today's `diary-entries-list'.
158The number before each time/message is the time in minutes from midnight.")
159
f3e7c0dc 160(defconst appt-max-time 1439
902a0e3c
JB
161 "11:59pm in minutes - number of minutes in a day minus 1.")
162
8db540c5
RS
163(defcustom appt-display-interval 3
164 "*Number of minutes to wait between checking the appointment list."
165 :type 'integer
166 :group 'appt)
a1506d29 167
5b586155
RS
168(defvar appt-buffer-name " *appt-buf*"
169 "Name of the appointments buffer.")
a1506d29 170
5b586155
RS
171(defvar appt-disp-window-function 'appt-disp-window
172 "Function called to display appointment window.")
a1506d29 173
5b586155
RS
174(defvar appt-delete-window-function 'appt-delete-window
175 "Function called to remove appointment window and buffer.")
b570e652 176
efa434d9 177(defvar appt-mode-string nil
f3e7c0dc
KH
178 "String being displayed in the mode line saying you have an appointment.
179The actual string includes the amount of time till the appointment.")
180
181(defvar appt-prev-comp-time nil
182 "Time of day (mins since midnight) at which we last checked appointments.")
183
184(defvar appt-now-displayed nil
185 "Non-nil when we have started notifying about a appointment that is near.")
186
187(defvar appt-display-count nil)
efa434d9 188
902a0e3c
JB
189(defun appt-check ()
190 "Check for an appointment and update the mode line.
191Note: the time must be the first thing in the line in the diary
192for a warning to be issued.
193
194The format of the time can be either 24 hour or am/pm.
a1506d29 195Example:
902a0e3c
JB
196
197 02/23/89
198 18:00 Dinner
a1506d29 199
902a0e3c
JB
200 Thursday
201 11:45am Lunch meeting.
202
f3e7c0dc
KH
203Appointments are checked every `appt-display-interval' minutes.
204The following variables control appointment notification:
902a0e3c 205
efa434d9
RS
206`appt-issue-message'
207 If t, the diary buffer is checked for appointments.
902a0e3c 208
efa434d9 209`appt-message-warning-time'
b570e652
RS
210 Variable used to determine if appointment message
211 should be displayed.
902a0e3c 212
efa434d9 213`appt-audible'
b570e652
RS
214 Variable used to determine if appointment is audible.
215 Default is t.
902a0e3c 216
efa434d9 217`appt-visible'
b570e652 218 Variable used to determine if appointment message should be
efa434d9 219 displayed in the mini-buffer. Default is t.
902a0e3c 220
efa434d9 221`appt-msg-window'
b570e652 222 Variable used to determine if appointment message
efa434d9
RS
223 should temporarily appear in another window. Mutually exclusive
224 to `appt-visible'.
902a0e3c 225
efa434d9 226`appt-display-duration'
b570e652
RS
227 The number of seconds an appointment message
228 is displayed in another window.
229
f3e7c0dc 230`appt-disp-window-function'
efa434d9 231 Function called to display appointment window. You can customize
adae5323
RS
232 appt.el by setting this variable to a function different from the
233 one provided with this package.
a1506d29 234
f3e7c0dc 235`appt-delete-window-function'
adae5323
RS
236 Function called to remove appointment window and buffer. You can
237 customize appt.el by setting this variable to a function different
efa434d9 238 from the one provided with this package."
902a0e3c 239
f3e7c0dc
KH
240 (let* ((min-to-app -1)
241 (new-time "")
242 (prev-appt-mode-string appt-mode-string)
243 (prev-appt-display-count (or appt-display-count 0))
244 ;; Non-nil means do a full check for pending appointments
245 ;; and display in whatever ways the user has selected.
246 ;; When no appointment is being displayed,
247 ;; we always do a full check.
248 (full-check
249 (or (not appt-now-displayed)
250 ;; This is true every appt-display-interval minutes.
251 (= 0 (mod prev-appt-display-count appt-display-interval))))
252 ;; Non-nil means only update the interval displayed in the mode line.
253 (mode-line-only
254 (and (not full-check) appt-now-displayed)))
255
256 (when (or full-check mode-line-only)
257 (save-excursion
258
259 ;; Get the current time and convert it to minutes
260 ;; from midnight. ie. 12:01am = 1, midnight = 0.
902a0e3c 261
f3e7c0dc
KH
262 (let* ((now (decode-time))
263 (cur-hour (nth 2 now))
264 (cur-min (nth 1 now))
265 (cur-comp-time (+ (* cur-hour 60) cur-min)))
266
a1506d29 267 ;; At the first check in any given day, update our
f3e7c0dc
KH
268 ;; appointments to today's list.
269
270 (if (or (null appt-prev-comp-time)
271 (< cur-comp-time appt-prev-comp-time))
272 (condition-case nil
273 (progn
274 (if (and view-diary-entries-initially appt-display-diary)
275 (diary)
276 (let ((diary-display-hook 'appt-make-list))
277 (diary))))
278 (error nil)))
279 (setq appt-prev-comp-time cur-comp-time)
280
281 (setq appt-mode-string nil)
282 (setq appt-display-count nil)
283
284 ;; If there are entries in the list, and the
285 ;; user wants a message issued,
286 ;; get the first time off of the list
287 ;; and calculate the number of minutes until the appointment.
288
289 (if (and appt-issue-message appt-time-msg-list)
290 (let ((appt-comp-time (car (car (car appt-time-msg-list)))))
291 (setq min-to-app (- appt-comp-time cur-comp-time))
292
a1506d29 293 (while (and appt-time-msg-list
f3e7c0dc 294 (< appt-comp-time cur-comp-time))
a1506d29 295 (setq appt-time-msg-list (cdr appt-time-msg-list))
f3e7c0dc 296 (if appt-time-msg-list
a1506d29 297 (setq appt-comp-time
f3e7c0dc
KH
298 (car (car (car appt-time-msg-list))))))
299
300 ;; If we have an appointment between midnight and
301 ;; 'appt-message-warning-time' minutes after midnight,
302 ;; we must begin to issue a message before midnight.
303 ;; Midnight is considered 0 minutes and 11:59pm is
304 ;; 1439 minutes. Therefore we must recalculate the minutes
a1506d29
JB
305 ;; to appointment variable. It is equal to the number of
306 ;; minutes before midnight plus the number of
f3e7c0dc
KH
307 ;; minutes after midnight our appointment is.
308
309 (if (and (< appt-comp-time appt-message-warning-time)
310 (> (+ cur-comp-time appt-message-warning-time)
311 appt-max-time))
312 (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time))
313 appt-comp-time))
314
a1506d29 315 ;; issue warning if the appointment time is
f3e7c0dc
KH
316 ;; within appt-message-warning time
317
318 (when (and (<= min-to-app appt-message-warning-time)
319 (>= min-to-app 0))
320 (setq appt-now-displayed t)
321 (setq appt-display-count
322 (1+ prev-appt-display-count))
323 (unless mode-line-only
efa434d9
RS
324 (if appt-msg-window
325 (progn
326 (setq new-time (format-time-string "%a %b %e "
327 (current-time)))
328 (funcall
329 appt-disp-window-function
d073fa5b 330 (number-to-string min-to-app) new-time
efa434d9 331 (car (cdr (car appt-time-msg-list))))
f3e7c0dc 332
efa434d9
RS
333 (run-at-time
334 (format "%d sec" appt-display-duration)
335 nil
336 appt-delete-window-function))
f3e7c0dc 337 ;;; else
b570e652 338
efa434d9 339 (if appt-visible
a1506d29 340 (message "%s"
efa434d9 341 (car (cdr (car appt-time-msg-list)))))
b570e652 342
efa434d9 343 (if appt-audible
f3e7c0dc
KH
344 (beep 1))))
345
346 (when appt-display-mode-line
347 (setq appt-mode-string
d073fa5b
DL
348 (concat " App't in "
349 (number-to-string min-to-app)
350 " min. ")))
f3e7c0dc
KH
351
352 ;; When an appointment is reached,
353 ;; delete it from the list.
354 ;; Reset the count to 0 in case we display another
355 ;; appointment on the next cycle.
356 (if (= min-to-app 0)
357 (setq appt-time-msg-list
358 (cdr appt-time-msg-list)
359 appt-display-count nil)))))
360
361 ;; If we have changed the mode line string,
362 ;; redisplay all mode lines.
363 (and appt-display-mode-line
364 (not (equal appt-mode-string
365 prev-appt-mode-string))
366 (progn
367 (force-mode-line-update t)
368 ;; If the string now has a notification,
369 ;; redisplay right now.
370 (if appt-mode-string
371 (sit-for 0)))))))))
902a0e3c
JB
372
373
902a0e3c 374(defun appt-disp-window (min-to-app new-time appt-msg)
d073fa5b 375 "Display appointment message APPT-MSG in a separate buffer."
902a0e3c 376 (require 'electric)
5b586155
RS
377
378 ;; Make sure we're not in the minibuffer
379 ;; before splitting the window.
380
381 (if (equal (selected-window) (minibuffer-window))
a1506d29 382 (if (other-window 1)
5b586155 383 (select-window (other-window 1))
fbebec27 384 (if (display-multi-frame-p)
5b586155 385 (select-frame (other-frame 1)))))
a1506d29 386
5b586155
RS
387 (let* ((this-buffer (current-buffer))
388 (this-window (selected-window))
389 (appt-disp-buf (set-buffer (get-buffer-create appt-buffer-name))))
390
d5b22d88
RS
391 (if (cdr (assq 'unsplittable (frame-parameters)))
392 ;; In an unsplittable frame, use something somewhere else.
393 (display-buffer appt-disp-buf)
058961dd
RS
394 (unless (or (special-display-p (buffer-name appt-disp-buf))
395 (same-window-p (buffer-name appt-disp-buf)))
396 ;; By default, split the bottom window and use the lower part.
397 (appt-select-lowest-window)
398 (split-window))
d5b22d88 399 (pop-to-buffer appt-disp-buf))
a1506d29 400 (setq mode-line-format
5b586155
RS
401 (concat "-------------------- Appointment in "
402 min-to-app " minutes. " new-time " %-"))
efa434d9 403 (erase-buffer)
0e13751e 404 (insert appt-msg)
d5b22d88 405 (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t))
5b586155 406 (set-buffer-modified-p nil)
725ec4bc 407 (raise-frame (selected-frame))
5b586155
RS
408 (select-window this-window)
409 (if appt-audible
410 (beep 1))))
a1506d29 411
5b586155
RS
412(defun appt-delete-window ()
413 "Function called to undisplay appointment messages.
414Usually just deletes the appointment buffer."
95cdbff5
RS
415 (let ((window (get-buffer-window appt-buffer-name t)))
416 (and window
d073fa5b 417 (or (eq window (frame-root-window (window-frame window)))
95cdbff5 418 (delete-window window))))
5b586155
RS
419 (kill-buffer appt-buffer-name)
420 (if appt-audible
421 (beep 1)))
902a0e3c 422
902a0e3c 423(defun appt-select-lowest-window ()
d073fa5b 424"Select the lowest window on the frame."
7c0d9b89
GM
425 (let ((lowest-window (selected-window))
426 (bottom-edge (nth 3 (window-edges))))
427 (walk-windows (lambda (w)
428 (let ((next-bottom-edge (nth 3 (window-edges w))))
429 (when (< bottom-edge next-bottom-edge)
430 (setq bottom-edge next-bottom-edge
431 lowest-window w)))))
432 (select-window lowest-window)))
902a0e3c 433
f3e7c0dc 434;;;###autoload
902a0e3c 435(defun appt-add (new-appt-time new-appt-msg)
d073fa5b 436 "Add an appointment for the day at NEW-APPT-TIME and issue message NEW-APPT-MSG.
902a0e3c
JB
437The time should be in either 24 hour format or am/pm format."
438
439 (interactive "sTime (hh:mm[am/pm]): \nsMessage: ")
3b42c185
TTN
440 (if (string-match "[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?"
441 new-appt-time)
902a0e3c
JB
442 nil
443 (error "Unacceptable time-string"))
a1506d29 444
902a0e3c
JB
445 (let* ((appt-time-string (concat new-appt-time " " new-appt-msg))
446 (appt-time (list (appt-convert-time new-appt-time)))
447 (time-msg (cons appt-time (list appt-time-string))))
d073fa5b 448 (setq appt-time-msg-list (nconc appt-time-msg-list (list time-msg)))
a1506d29 449 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))))
902a0e3c 450
f3e7c0dc 451;;;###autoload
902a0e3c
JB
452(defun appt-delete ()
453 "Delete an appointment from the list of appointments."
454 (interactive)
455 (let* ((tmp-msg-list appt-time-msg-list))
456 (while tmp-msg-list
457 (let* ((element (car tmp-msg-list))
a1506d29 458 (prompt-string (concat "Delete "
bf9a91d0
RS
459 ;; We want to quote any doublequotes
460 ;; in the string, as well as put
461 ;; doublequotes around it.
462 (prin1-to-string
463 (substring-no-properties
a1506d29 464 (car (cdr element)) 0))
902a0e3c
JB
465 " from list? "))
466 (test-input (y-or-n-p prompt-string)))
467 (setq tmp-msg-list (cdr tmp-msg-list))
468 (if test-input
95cdbff5 469 (setq appt-time-msg-list (delq element appt-time-msg-list)))))
85bbde63 470 (appt-check)
902a0e3c 471 (message "")))
a1506d29 472
902a0e3c 473
ea04824c
DL
474(eval-when-compile (defvar number)
475 (defvar original-date)
476 (defvar diary-entries-list))
637a8ae9 477;;;###autoload
902a0e3c 478(defun appt-make-list ()
d073fa5b
DL
479 "Create the appointments list from todays diary buffer.
480The time must be at the beginning of a line for it to be
481put in the appointments list.
482 02/23/89
483 12:00pm lunch
484 Wednesday
485 10:00am group meeting
486We assume that the variables DATE and NUMBER
487hold the arguments that `list-diary-entries' received.
488They specify the range of dates that the diary is being processed for."
489
9c197f24
RS
490 ;; We have something to do if the range of dates that the diary is
491 ;; considering includes the current date.
492 (if (and (not (calendar-date-compare
493 (list (calendar-current-date))
494 (list original-date)))
495 (calendar-date-compare
496 (list (calendar-current-date))
497 (list (calendar-gregorian-from-absolute
498 (+ (calendar-absolute-from-gregorian original-date)
499 number)))))
500 (save-excursion
501 ;; Clear the appointments list, then fill it in from the diary.
502 (setq appt-time-msg-list nil)
503 (if diary-entries-list
504
505 ;; Cycle through the entry-list (diary-entries-list)
a1506d29 506 ;; looking for entries beginning with a time. If
9c197f24
RS
507 ;; the entry begins with a time, add it to the
508 ;; appt-time-msg-list. Then sort the list.
509
510 (let ((entry-list diary-entries-list)
511 (new-time-string ""))
512 ;; Skip diary entries for dates before today.
513 (while (and entry-list
514 (calendar-date-compare
515 (car entry-list) (list (calendar-current-date))))
516 (setq entry-list (cdr entry-list)))
517 ;; Parse the entries for today.
a1506d29
JB
518 (while (and entry-list
519 (calendar-date-equal
9c197f24 520 (calendar-current-date) (car (car entry-list))))
bf9a91d0 521 (let ((time-string (cadr (car entry-list))))
9c197f24 522 (while (string-match
3b42c185 523 "\\([0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?\\).*"
9c197f24 524 time-string)
4e96d63b
RS
525 (let* ((beg (match-beginning 0))
526 ;; Get just the time for this appointment.
527 (only-time (match-string 1 time-string))
528 ;; Find the end of this appointment
529 ;; (the start of the next).
530 (end (string-match
3b42c185 531 "^[ \t]*[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?"
4e96d63b
RS
532 time-string
533 (match-end 0)))
534 ;; Get the whole string for this appointment.
535 (appt-time-string
536 (substring time-string beg (if end (1- end)))))
537
538 ;; Add this appointment to appt-time-msg-list.
539 (let* ((appt-time (list (appt-convert-time only-time)))
540 (time-msg (list appt-time appt-time-string)))
541 (setq appt-time-msg-list
542 (nconc appt-time-msg-list (list time-msg))))
543
544 ;; Discard this appointment from the string.
545 (setq time-string
546 (if end (substring time-string end) "")))))
9c197f24
RS
547 (setq entry-list (cdr entry-list)))))
548 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))
549
550 ;; Get the current time and convert it to minutes
551 ;; from midnight. ie. 12:01am = 1, midnight = 0,
552 ;; so that the elements in the list
553 ;; that are earlier than the present time can
554 ;; be removed.
555
0d26feea
KH
556 (let* ((now (decode-time))
557 (cur-hour (nth 2 now))
558 (cur-min (nth 1 now))
9c197f24
RS
559 (cur-comp-time (+ (* cur-hour 60) cur-min))
560 (appt-comp-time (car (car (car appt-time-msg-list)))))
561
562 (while (and appt-time-msg-list (< appt-comp-time cur-comp-time))
a1506d29 563 (setq appt-time-msg-list (cdr appt-time-msg-list))
9c197f24
RS
564 (if appt-time-msg-list
565 (setq appt-comp-time (car (car (car appt-time-msg-list))))))))))
a1506d29 566
902a0e3c 567
902a0e3c 568(defun appt-sort-list (appt-list)
d073fa5b
DL
569 "Simple sort to put the appointments list APPT-LIST in order.
570Scan the list for the smallest element left in the list.
571Append the smallest element left into the new list, and remove
572it from the original list."
902a0e3c
JB
573 (let ((order-list nil))
574 (while appt-list
575 (let* ((element (car appt-list))
576 (element-time (car (car element)))
577 (tmp-list (cdr appt-list)))
578 (while tmp-list
579 (if (< element-time (car (car (car tmp-list))))
580 nil
581 (setq element (car tmp-list))
582 (setq element-time (car (car element))))
583 (setq tmp-list (cdr tmp-list)))
d073fa5b 584 (setq order-list (nconc order-list (list element)))
902a0e3c
JB
585 (setq appt-list (delq element appt-list))))
586 order-list))
587
588
589(defun appt-convert-time (time2conv)
3b42c185
TTN
590 "Convert hour:min[am/pm] format to minutes from midnight.
591Also try to accept the hour.min[am/pm] format."
902a0e3c
JB
592 (let ((conv-time 0)
593 (hr 0)
594 (min 0))
595
3b42c185 596 (string-match "[:.]\\([0-9][0-9]\\)" time2conv)
a1506d29 597 (setq min (string-to-int
d073fa5b 598 (match-string 1 time2conv)))
a1506d29 599
3b42c185 600 (string-match "[0-9]?[0-9][:.]" time2conv)
a1506d29 601 (setq hr (string-to-int
d073fa5b 602 (match-string 0 time2conv)))
a1506d29 603
902a0e3c 604 ;; convert the time appointment time into 24 hour time
a1506d29 605
85bbde63
GM
606 (cond ((and (string-match "pm" time2conv) (< hr 12))
607 (setq hr (+ 12 hr)))
608 ((and (string-match "am" time2conv) (= hr 12))
609 (setq hr 0)))
a1506d29 610
902a0e3c
JB
611 ;; convert the actual time
612 ;; into minutes for comparison
613 ;; against the actual time.
a1506d29 614
902a0e3c
JB
615 (setq conv-time (+ (* hr 60) min))
616 conv-time))
617
efa434d9
RS
618(defvar appt-timer nil
619 "Timer used for diary appointment notifications (`appt-check').")
902a0e3c 620
f3e7c0dc
KH
621(unless appt-timer
622 (setq appt-timer (run-at-time t 60 'appt-check)))
efa434d9
RS
623
624(or global-mode-string (setq global-mode-string '("")))
625(or (memq 'appt-mode-string global-mode-string)
626 (setq global-mode-string
627 (append global-mode-string '(appt-mode-string))))
5b586155 628
ab5796a9 629;;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347
efa434d9 630;;; appt.el ends here