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