annotate lisp/calendar/appt.el @ 118:7d55a9ba150c r20-1b11

Import from CVS: tag r20-1b11
author cvs
date Mon, 13 Aug 2007 09:24:17 +0200
parents 9f59509498e1
children 9b50b4588a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; appt.el --- appointment notification functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Keywords: calendar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; -*- Mode:Emacs-Lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Appointment notification functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Copyright (C) 1989, 1990, 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; 29-nov-89 created by Neil Mager <neilm@juliet.ll.mit.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; 23-feb-91 hacked upon by Jamie Zawinski <jwz@lucid.com>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; 1-apr-91 some more.
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
27 ;;; 12-jul-95 updated for XEmacs 19.12 by Greg Veres
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
28 ;;; <gveres@cgl.uwaterloo.ca>
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
29 ;;; 21-mar-97 better support for fancy diary display by Tomasz J. Cholewo
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
30 ;;; <t.cholewo@ieee.org>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; appt.el - visible and/or audible notification of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; appointments from ~/diary file generated from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; Edward M. Reingold's calendar.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; Version 2.1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; Comments, corrections, and improvements should be sent to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; Neil M. Mager
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; Net <neilm@juliet.ll.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Voice (617) 981-4803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; Thanks to Edward M. Reingold for much help and many suggestions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; And to many others for bug fixes and suggestions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; This functions in this file will alert the user of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; pending appointment based on their diary file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; ******* It is necessary to invoke 'display-time' and ********
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; ******* 'appt-initialize' for this to work properly. ********
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; A message will be displayed in the mode line of the emacs buffer and (if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; the user desires) the terminal will beep and display a message from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; diary in the mini-buffer, or the user may select to have a message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; displayed in a new buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; Variables of note:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; appt-issue-message If this variable is nil, then the code in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; file does nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; appt-msg-countdown-list Specifies how much warning you want before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; appointments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; appt-audible Whether to beep when it's notification-time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; appt-display-mode-line Whether to display a countdown to the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; appointment in the mode-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; appt-announce-method The function used to do the notifications.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; 'appt-window-announce do it in a pop-up window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; 'appt-frame-announce do it in a pop-up frame (v19 only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; 'appt-message-announce do it in the echo area.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; 'appt-persistent-message-announce do it in the echo area, but make the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; messages not go away at the next keystroke.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; appt-display-duration If appt-announce-method is set to the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; 'appt-window-announce, this specifies how many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; seconds the pop-up window should stick around.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; In order to use this, create a diary file, and add the following to your
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; .emacs file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;; (require 'appt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; (display-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; (appt-initialize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; If you wish to see a list of appointments, or a full calendar, when emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; starts up, you can add a call to (diary) or (calendar) after this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; This is an example of what can be in your diary file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; Monday
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; 9:30am Coffee break
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;; 12:00pm Lunch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;; Based upon the above lines in your .emacs and diary files, the calendar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; and/or diary will be displayed when you enter emacs and your appointments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;; list will automatically be created. You will then be reminded at 9:20am
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;; about your coffee break and at 11:50am to go to lunch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;; In order to interactively add or delete items from today's list, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;; Meta-x appt-add and Meta-x appt-delete. (This does not modify your
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;; diary file, so these will be forgotten when you exit emacs.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;; Additionally, the appointments list is recreated automatically at 12:01am
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; for those who do not logout every day or are programming late.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;; You can have special appointments which execute arbitrary code rather than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;; simply notifying you -- sort of like the unix "cron" facility. The syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;; for this is borrowed from the Calendar's special-date format. If you have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;; a diary entry like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; Monday
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;; 3:00am %%(save-all-modified-buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;; then on monday at 3AM, the function `save-all-modified-buffers' will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;; invoked. (Presumably this function is defined in your .emacs file.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; There will be no notification that these "special" appointments are being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; triggered, unless the form evaluated produces a notification.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; It is necessary for the entire list after the "%%" to be on one line in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; your .diary file -- there may not be embedded newlines in it. This is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;; bit of a misfeature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;; This also interacts correctly with Benjamin Pierce's reportmail.el package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
123 ;;; Brief internal description - Skip this if you are not interested!
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;;; The function appt-initialize invokes 'diary' to get a list of today's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;; appointments, and parses the lines beginning with date descriptions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;; This list is cached away. 'diary' is invoked in such a way so as to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;;; not pop up a window displaying the diary buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;; The function appt-check is run from the 'loadst' process (or the 'wakeup'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;; process in emacs 18.57 or newer) which is started by invoking display-time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;; It checks this cached list, and announces as appropriate. At midnight,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;;; appt-initialize is called again to rebuild this list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;; display-time-filter is modified to invoke appt-check.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;; TO DO:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
139 ;;; o multiple adjacent appointments are not handled gracefully. If there
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;;; is an appointment at 3:30 and another at 3:35, and you have set things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;;; up so that you get a notification twenty minutes before each appt,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;; then a notification should come at 3:10 for the first appt, and at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;; 3:15 for the second. Currently, no notifications are generated for an
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
144 ;;; appointment until all preceding appointments have completely expired.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;;; o If there are two appointments at the same time, all but the first are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;;; ignored (not announced.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;; o Appointments which are early enough in the morning that their
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;;; announcements should begin before midnight are not announced until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;;; midnight.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;;; o There should be some way to mark certain appointments as "important,"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;; so that you will be harassed about them even after they have expired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (require 'calendar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (require 'diary-lib)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (defvar appt-issue-message t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 "*If T, the diary buffer is checked for appointments. For an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 appointment warning to be made, the time must be the first thing on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 the line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defvar appt-msg-countdown-list '(20 15 10 5 3 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "*A list of the intervals in minutes before the appointment when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 the warnings will be given. That is, if this were the list '(5 3 1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 then a notification would be given five minutes, three minutes, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 one minute before the appointment.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defvar appt-check-time-syntax nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "*Whether all diary entries are intended to beging with time specifications.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 Appt will beep and issue a warning message when encountering unparsable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 lines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defvar appt-audible t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "*Controls whether appointment announcements should beep.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 Appt uses two sound-types for beeps: `appt' and `appt-final'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 If this is a number, then that many beeps will occur.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 If this is a cons, the car is how many beeps, and the cdr is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 delay between them (a float, fraction of a second to sleep.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 See also the variable `appt-msg-countdown-list'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (defvar appt-display-mode-line t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "*Controls if minutes-to-appointment should be displayed on the mode line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defvar appt-announce-method 'appt-window-announce
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "*The name of the function used to notify the user of an impending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 appointment. This is called with two arguments, the number of minutes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 until the appointment, and the appointment description list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 Reasonable values for this variable are 'appt-window-announce,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 'appt-message-announce, or 'appt-persistent-message-announce.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defvar appt-time-msg-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "The list of appointments for today. Use appt-add and appt-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 to add and delete appointments from list. The original list is generated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 from the today's diary-entries-list. The number before each time/message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 is the time in minutes after midnight.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defconst max-time 1439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 "11:59pm in minutes - number of minutes in a day minus 1.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defconst appt-check-tick -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defvar appt-disp-frame nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 "If non-nil, frame to display appointments in.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (defvaralias 'appt-disp-screen 'appt-disp-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;;; Announcement methods
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (defun appt-message-announce (min-to-app appt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 "Set appt-announce-method to the name of this function to cause appointment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 notifications to be given via messages in the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (message (if (eq min-to-app 0) "App't NOW."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (format "App't in %d minute%s -- %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 min-to-app
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if (eq 1 min-to-app) "" "s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (car (cdr appt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (defun appt-persistent-message-announce (min-to-app appt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 "Set appt-announce-method to the name of this function to cause appointment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 notifications to be given via messages in the minibuffer, but have those
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 messages stay around even if you type something (unlike normal messages)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (let ((str (if (eq min-to-app 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (format "App't NOW -- %s" (car (cdr appt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (format "App't in %d minute%s -- %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 min-to-app
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (if (eq 1 min-to-app) "" "s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (car (cdr appt)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (in-echo-area-already (eq (selected-window) (minibuffer-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (if (not in-echo-area-already)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; don't stomp the echo-area-buffer if reading from the minibuffer now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (select-window (minibuffer-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (insert str))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; if we're reading from the echo-area, and all we were going to do is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; clear the thing, like, don't bother, that's annoying.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if (and in-echo-area-already (string= "" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (message "%s" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (defvar appt-display-duration 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 "*The number of seconds an appointment message is displayed in its own
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 window if appt-announce-method is 'appt-window-announce.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (defun appt-window-announce (min-to-app appt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 "Set appt-announce-method to the name of this function to cause appointment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 notifications to be given via messages in a pop-up window. The variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 appt-display-duration controls how long this window should be left up."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (require 'electric)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;; Make sure we're not in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; before splitting the window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (if (window-minibuffer-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (select-window (frame-lowest-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (split-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (let (appt-disp-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (setq appt-disp-buf (set-buffer (get-buffer-create "*appt-buf*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; set the mode-line of the pop-up window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (setq modeline-format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (concat "-------------------- Appointment "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (if (eq min-to-app 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 "NOW"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (concat "in " min-to-app
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if (eq min-to-app 1) " minute" " minutes")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ". ("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (let ((h (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (substring (current-time-string) 11 13))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (concat (if (> h 12) (- h 12) h) ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (substring (current-time-string) 14 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (if (< h 12) "am" "pm")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ") %-"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (pop-to-buffer appt-disp-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (insert (car (cdr appt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (shrink-window-if-larger-than-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (get-buffer-window appt-disp-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (sit-for appt-display-duration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (and appt-disp-buf (kill-buffer appt-disp-buf)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (defvar appt-frame-defaults nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (defvaralias 'appt-screen-defaults 'appt-frame-defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (defun appt-frame-announce (min-to-app appt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 "Set appt-announce-method to the name of this function to cause appointment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 notifications to be given via messages in a pop-up frame."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (let ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (set-buffer (get-buffer-create "*appt-buf*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; set the mode-line of the pop-up window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (setq modeline-format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (concat "-------------------- Appointment "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (if (eq min-to-app 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "NOW"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (concat "in " min-to-app
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (if (eq min-to-app 1) " minute" " minutes")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ". ("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (let ((h (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (substring (current-time-string) 11 13))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (concat (if (> h 12) (- h 12) h) ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (substring (current-time-string) 14 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (if (< h 12) "am" "pm")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ") %-"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (insert (car (cdr appt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (let ((height (max 10 (min 20 (+ 2 (count-lines (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (point-max)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ;; If we already have a frame constructed, use it. If not, or it has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;; been deleted, then make a new one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (if (and appt-disp-frame (frame-live-p appt-disp-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (let ((s (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (select-frame appt-disp-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (make-frame-visible appt-disp-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (set-frame-height appt-disp-frame height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (select-frame s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq appt-disp-frame (make-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (set-frame-height appt-disp-frame height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (defalias 'appt-screen-announce 'appt-frame-announce)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;;; To display stuff in the mode line, we use a new variable instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ;;; just adding stuff to the display-time-string -- this causes less
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;;; flicker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (defvar appt-mode-line-string ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 "*The string displayed in the mode line by the appointment package.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (defun appt-display-mode-line (min-to-app)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 "Add an appointment annotation to the mode line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (setq appt-mode-line-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (if (and appt-display-mode-line min-to-app)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (if (eq 0 min-to-app)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 "App't NOW "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (concat "App't in " min-to-app
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (if (eq 1 min-to-app) " minute " " minutes ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ;; make sure our variable is visible in global-mode-string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (cond ((not appt-display-mode-line) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ((null global-mode-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (setq global-mode-string (list "" 'appt-mode-line-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ((stringp global-mode-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (setq global-mode-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (list global-mode-string 'appt-mode-line-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ((not (memq 'appt-mode-line-string global-mode-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (setq global-mode-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (append global-mode-string (list 'appt-mode-line-string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; force mode line updates - from time.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (save-excursion (set-buffer (other-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (set-buffer-modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (sit-for 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;;; Internal stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (defun appt-convert-time (time2conv)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
375 "Convert hour:min[am/pm] format to minutes from midnight."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (cond ((string-match "^[ \t]*midni\\(ght\\|te\\)[ \t]*\\'" time2conv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ((string-match "^[ \t]*noon[ \t]*\\'" time2conv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (* 12 60))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (let ((hr 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (min 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (or (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 "\\`[ \t]*\\([0-9][0-9]?\\)[ \t]*\\(:[ \t]*\\([0-9][0-9]\\)\\)?[ \t]*\\(am\\|pm\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 time2conv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (error "unparsable time \"%s\"" time2conv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (setq hr (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (substring time2conv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (match-beginning 1) (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (if (match-beginning 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (setq min (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (substring time2conv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (match-beginning 3) (match-end 3)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ;; convert the time appointment time into 24 hour time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (if (match-beginning 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (if (or (= hr 0) (> hr 12))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (error "mixing 12hr and 24 hr time! %s" time2conv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (if (string-match "am"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (substring time2conv (match-beginning 4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (if (= hr 12) (setq hr 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (if (< hr 12) (setq hr (+ 12 hr))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (if (> min 59) (error "minutes outa bounds - %s" time2conv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (+ (* hr 60) min)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
407 (defun appt-current-time-in-minutes ()
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
408 "Returns the current time in minutes since midnight."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (let* ((str (current-time-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (hour (string-to-int (substring str 11 13)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (min (string-to-int (substring str 14 16))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (+ (* hour 60) min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defun appt-sort-list (appt-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (sort (copy-sequence appt-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (function (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (< (car (car x)) (car (car y)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defun appt-diary-entries ()
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
421 "Return an updated list of appointments for today."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (let ((list-diary-entries-hook '(appt-make-list))
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
423 (diary-display-hook 'ignore)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (diary-list-include-blanks nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; this will set appt-time-msg-list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (diary 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 appt-time-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (defun appt-initialize ()
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
430 "Read your `diary-file' and remember today's appointments. Call this from
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 your .emacs file, or any time you want your .diary file re-read (this happens
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
432 automatically at midnight to notice the next day's appointments).
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 The time must be at the beginning of a line for it to be put in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 appointments list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 02/23/89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 12:00pm lunch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 Wednesday
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 10:00am group meeting"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (install-display-time-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (let ((n (length (appt-diary-entries))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (cond ((= n 0) (message "no appointments today."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ((= n 1) (message "1 appointment today."))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
444 (t (message "%d appointments today." n)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (defun appt-make-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 "Don't call this directly; call appt-initialize or appt-diary-entries."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (setq appt-time-msg-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (if diary-entries-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;; Cycle through the entry-list (diary-entries-list) looking for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ;; entries beginning with a time. If the entry begins with a time,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ;; add it to the appt-time-msg-list. Then sort the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (let ((entry-list diary-entries-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (new-appts '()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (while (and entry-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (calendar-date-equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (calendar-current-date) (car (car entry-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (let ((time-string (car (cdr (car entry-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (while (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 "\\`[ \t\n]*\\([0-9]?[0-9]\\(:[0-9][0-9]\\)?[ \t]*\\(am\\|pm\\)?\\|noon\\|midnight\\|midnite\\).*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 time-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (let* ((eol (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (appt-time-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (substring time-string (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (appt-msg-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (substring time-string (match-end 1) eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (appt-time (list (appt-convert-time appt-time-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (setq time-string (substring time-string eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 new-appts (cons (cons appt-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (list (concat appt-time-string ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 appt-msg-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 new-appts))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (if appt-check-time-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (while (string-match "\n*\\([^\n]+\\)$" time-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (message "Unparsable time: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (substring time-string (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (sit-for 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (setq time-string (substring time-string (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (setq entry-list (cdr entry-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (setq appt-time-msg-list ; seems we can't nconc this list...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (append (nreverse new-appts) appt-time-msg-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
490 ;; Get the current time and convert it to minutes from midnight, i.e.,
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
491 ;; 12:01am = 1, midnight = 0, so that the elements in the list that
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
492 ;; are earlier than the present time can be removed.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
494 (let ((cur-comp-time (appt-current-time-in-minutes))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (appt-comp-time (car (car (car appt-time-msg-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (while (and appt-time-msg-list (< appt-comp-time cur-comp-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (setq appt-time-msg-list (cdr appt-time-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (if appt-time-msg-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (setq appt-comp-time (car (car (car appt-time-msg-list)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 appt-time-msg-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (defun appt-beep (&optional final-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (cond ((null appt-audible) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ((numberp appt-audible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (let ((i appt-audible))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (while (> i 0) (beep) (setq i (1- i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ((consp appt-audible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (let ((i (car appt-audible))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (j (cdr appt-audible)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (if (consp j) (setq j (car j)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (while (> i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (if (fboundp 'play-sound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (beep nil (if final-p 'appt-final 'appt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (sleep-for j)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (setq i (1- i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (t (beep))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (defun appt-check ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 "Check for an appointment and update the mode line and minibuffer if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 desired. Note: the time must be the first thing in the line in the diary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 for a warning to be issued.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 The format of the time can be either 24 hour or am/pm. Example:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 02/23/89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 18:00 Dinner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 Thursday
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 11:45am Lunch meeting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 The following variables control the action of the notification:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 appt-issue-message If this variable is nil, then the code in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 file does nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 appt-msg-countdown-list Specifies how much warning you want before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 appointments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 appt-audible Whether to beep when it's notification-time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 appt-display-mode-line Whether to display a countdown to the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 appointment in the mode-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 appt-announce-method The function used to do the notifications.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 'appt-window-announce to do it in a pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 window, 'appt-message-announce or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 'appt-persistent-message-announce to do it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 in the echo-area.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 appt-display-duration If appt-announce-method is set to the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 'appt-window-announce, this specifies how many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 seconds the pop-up window should stick around.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 This function is run from the `loadst' or `wakeup' process for display-time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 Therefore, you need to have (display-time) in your .emacs file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (if appt-issue-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (let ((min-to-app -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;; Get the current time and convert it to minutes
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
555 ;; from midnight, i.e., 12:01am = 1, midnight = 0.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
556 (let* ((cur-comp-time (appt-current-time-in-minutes))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;; If the current time is the same as the tick, just return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ;; This means that this function has been called more than once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ;; in the current minute, which is not useful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (shut-up-this-time (= cur-comp-time appt-check-tick))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (turnover-p (> appt-check-tick cur-comp-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (setq appt-check-tick cur-comp-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ;; If it is now the next day (we have crossed midnight since the last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 ;; time this was called) then we should update our appointments to
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
566 ;; today's list. Show the diary entries (tjc).
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
567 (if turnover-p (diary 1))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 ;; Get the first time off of the list and calculate the number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ;; of minutes until the appointment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (if appt-time-msg-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (let ((appt-comp-time (car (car (car appt-time-msg-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (setq min-to-app (- appt-comp-time cur-comp-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (while (and appt-time-msg-list (< appt-comp-time cur-comp-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (setq appt-time-msg-list (cdr appt-time-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (if appt-time-msg-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (setq appt-comp-time (car (car (car appt-time-msg-list))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; If we have an appointment between midnight and warning-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 ;; minutes after midnight, we must begin to issue a message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ;; before midnight. Midnight is considered 0 minutes and 11:59pm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 ;; is 1439 minutes. Therefore we must recalculate the minutes to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 ;; appointment variable. It is equal to the number of minutes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 ;; before midnight plus the number of minutes after midnight our
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ;; appointment is.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;; ## I don't think this does anything -- it would if it were
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 ;; (for example) a 12:01am appt on the list at 11:55pm, but that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 ;; can't ever happen, because the applicable 12:01am appt is for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ;; tomorrow, not today, and we only have today's diary list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ;; It's not simply a matter of concatenating two days together,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;; either, because then tuesday's appts would be signalled on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ;; monday. We have to do a real one-day lookahead -- keep a list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 ;; of tomorrow's appts, and check it when near midnight.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (if (and (< appt-comp-time (apply 'max appt-msg-countdown-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (> (+ cur-comp-time (apply 'max appt-msg-countdown-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 max-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (setq min-to-app (+ (- (1+ max-time) cur-comp-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 appt-comp-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 ;; issue warning if the appointment time is within warning-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 ;; if there should not be any notifications in the mode-line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ;; clear it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ((> min-to-app (apply 'max appt-msg-countdown-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (appt-display-mode-line nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 ;; do nothing if this is the second time this minute we've
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ;; gotten here, of if we shouldn't be notifying right now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ((or shut-up-this-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (and (not (= min-to-app 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (not (memq min-to-app appt-msg-countdown-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 ((and (= min-to-app 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (string-match "%%(" (nth 1 (car appt-time-msg-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 ;; If this is a magic evaluating-notification, evaluate it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 ;; these kinds of notifications aren't subject to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 ;; appt-msg-countdown-list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (let* ((list-string (substring (nth 1 (car appt-time-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (1- (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (form (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (read list-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (message "Appt: error reading from \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (nth 1 (car appt-time-msg-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (sit-for 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (eval form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 ((and (<= min-to-app (apply 'max appt-msg-countdown-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (>= min-to-app 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;; produce a notification.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (appt-beep (= min-to-app 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (funcall appt-announce-method min-to-app
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (car appt-time-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;; update mode line and expire if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (appt-display-mode-line min-to-app)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 ;; if it's expired, remove it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (if (= min-to-app 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (setq appt-time-msg-list (cdr appt-time-msg-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 ;; else we're not near any appointment, or there are no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 ;; apointments; make sure mode line is clear.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (appt-display-mode-line nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (appt-display-mode-line nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 ;;; Interactively adding and deleting appointments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (defun appt-add (new-appt-time new-appt-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 "Adds an appointment to the list of appointments for the day at TIME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 and issue MESSAGE. The time should be in either 24 hour format or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 am/pm format. "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (interactive "sTime (hh:mm[am/pm]): \nsMessage: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (if (string-match "[0-9]?[0-9]:[0-9][0-9]\\(am\\|pm\\)?" new-appt-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (error "Unacceptable time-string"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (let* ((appt-time-string (concat new-appt-time " " new-appt-msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (appt-time (list (appt-convert-time new-appt-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (time-msg (cons appt-time (list appt-time-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (setq appt-time-msg-list (append appt-time-msg-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (list time-msg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (defun appt-delete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 "Deletes an appointment from the list of appointments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (let* ((tmp-msg-list appt-time-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (while tmp-msg-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (let* ((element (car tmp-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (prompt-string (concat "Delete "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (prin1-to-string (car (cdr element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 " from list? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (test-input (y-or-n-p prompt-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (setq tmp-msg-list (cdr tmp-msg-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (if test-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (setq appt-time-msg-list (delq element appt-time-msg-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (message "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ;;; Patching in to existing time code to install our hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (defvar display-time-hook-installed nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (defun install-display-time-hook ()
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
695 (unless display-time-hook-installed ; only do this stuff once!
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
696 (unless (boundp 'display-time-hook) ; Need to wrapper it.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
697 (defvar display-time-hook nil
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
698 "*List of functions to be called when the time is updated on the mode line.")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
699 (let ((old-fn (if (or (featurep 'reportmail)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
700 ;; old reportmail without a provide statement
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
701 (and (fboundp 'display-time-filter-18-55)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
702 (fboundp 'display-time-filter-18-57)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
703 (if (and (featurep 'itimer) ; XEmacs reportmail.el
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
704 (fboundp 'display-time-timer-function))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
705 'display-time-timer-function
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
706 ;; older reportmail, or no timer.el.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
707 (if (string-match "18\\.5[0-5]" (emacs-version))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
708 'display-time-filter-18-55
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
709 'display-time-filter-18-57))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
710 ;; othewise, time.el
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
711 (if (and (featurep 'itimer)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
712 (fboundp 'display-time-function)) ; XEmacs
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
713 'display-time-function
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
714 'display-time-filter))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ;; we're about to redefine it...
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
716 (fset 'old-display-time-filter (symbol-function old-fn))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
717 (fset old-fn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
718 '(lambda (&rest args) ;; ...here's the revised definition
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
719 "Revised version of the original function: this version calls a hook."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
720 (apply 'old-display-time-filter args)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
721 (run-hooks 'display-time-hook)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
722 (setq display-time-hook-installed t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
723 (if (fboundp 'add-hook)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
724 (add-hook 'display-time-hook 'appt-check)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
725 (setq display-time-hook (cons appt-check display-time-hook)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
726 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (provide 'appt)