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