Mercurial > emacs
annotate lisp/calendar/diary-lib.el @ 20192:bc27487e43bc
Added fix from Frank Ridderbusch <ridderbusch.pad@sni.de>,
an apostrophe was missing.
author | Oliver Seidel <os10000@seidel-space.de> |
---|---|
date | Tue, 28 Oct 1997 19:41:53 +0000 |
parents | 02a8fe146fa6 |
children | ca337d0a1553 |
rev | line source |
---|---|
13650 | 1 ;;; diary-lib.el --- diary functions. |
13053 | 2 |
14169 | 3 ;; Copyright (C) 1989, 1990, 1992, 1993, 1994, 1995 Free Software |
4 ;; Foundation, Inc. | |
13053 | 5 |
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
7 ;; Keywords: calendar | |
8 | |
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 | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
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. | |
13053 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This collection of functions implements the diary features as described | |
29 ;; in calendar.el. | |
30 | |
31 ;; Comments, corrections, and improvements should be sent to | |
32 ;; Edward M. Reingold Department of Computer Science | |
33 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
34 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
35 ;; Urbana, Illinois 61801 | |
36 | |
37 ;;; Code: | |
38 | |
39 (require 'calendar) | |
40 | |
41 ;;;###autoload | |
42 (defun diary (&optional arg) | |
43 "Generate the diary window for ARG days starting with the current date. | |
44 If no argument is provided, the number of days of diary entries is governed | |
45 by the variable `number-of-diary-entries'. This function is suitable for | |
46 execution in a `.emacs' file." | |
47 (interactive "P") | |
48 (let ((d-file (substitute-in-file-name diary-file)) | |
49 (date (calendar-current-date))) | |
50 (if (and d-file (file-exists-p d-file)) | |
51 (if (file-readable-p d-file) | |
52 (list-diary-entries | |
53 date | |
54 (cond | |
55 (arg (prefix-numeric-value arg)) | |
56 ((vectorp number-of-diary-entries) | |
57 (aref number-of-diary-entries (calendar-day-of-week date))) | |
58 (t number-of-diary-entries))) | |
59 (error "Your diary file is not readable!")) | |
60 (error "You don't have a diary file!")))) | |
61 | |
62 (defun view-diary-entries (arg) | |
63 "Prepare and display a buffer with diary entries. | |
64 Searches the file named in `diary-file' for entries that | |
65 match ARG days starting with the date indicated by the cursor position | |
66 in the displayed three-month calendar." | |
67 (interactive "p") | |
68 (let ((d-file (substitute-in-file-name diary-file))) | |
69 (if (and d-file (file-exists-p d-file)) | |
70 (if (file-readable-p d-file) | |
71 (list-diary-entries (calendar-cursor-to-date t) arg) | |
72 (error "Diary file is not readable!")) | |
73 (error "You don't have a diary file!")))) | |
74 | |
75 (defun view-other-diary-entries (arg diary-file) | |
76 "Prepare and display buffer of diary entries from an alternative diary file. | |
77 Prompts for a file name and searches that file for entries that match ARG | |
78 days starting with the date indicated by the cursor position in the displayed | |
79 three-month calendar." | |
80 (interactive | |
81 (list (cond ((null current-prefix-arg) 1) | |
82 ((listp current-prefix-arg) (car current-prefix-arg)) | |
83 (t current-prefix-arg)) | |
84 (setq diary-file (read-file-name "Enter diary file name: " | |
85 default-directory nil t)))) | |
86 (view-diary-entries arg)) | |
87 | |
88 (autoload 'check-calendar-holidays "holidays" | |
89 "Check the list of holidays for any that occur on DATE. | |
90 The value returned is a list of strings of relevant holiday descriptions. | |
91 The holidays are those in the list `calendar-holidays'." | |
92 t) | |
93 | |
94 (autoload 'calendar-holiday-list "holidays" | |
95 "Form the list of holidays that occur on dates in the calendar window. | |
96 The holidays are those in the list `calendar-holidays'." | |
97 t) | |
98 | |
99 (autoload 'diary-french-date "cal-french" | |
100 "French calendar equivalent of date diary entry." | |
101 t) | |
102 | |
103 (autoload 'diary-mayan-date "cal-mayan" | |
104 "Mayan calendar equivalent of date diary entry." | |
105 t) | |
106 | |
13688
88f14fa8e205
Autoload diary-iso-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13687
diff
changeset
|
107 (autoload 'diary-iso-date "cal-iso" |
88f14fa8e205
Autoload diary-iso-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13687
diff
changeset
|
108 "ISO calendar equivalent of date diary entry." |
88f14fa8e205
Autoload diary-iso-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13687
diff
changeset
|
109 t) |
88f14fa8e205
Autoload diary-iso-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13687
diff
changeset
|
110 |
13053 | 111 (autoload 'diary-julian-date "cal-julian" |
112 "Julian calendar equivalent of date diary entry." | |
113 t) | |
114 | |
115 (autoload 'diary-astro-day-number "cal-julian" | |
116 "Astronomical (Julian) day number diary entry." | |
117 t) | |
118 | |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
119 (autoload 'diary-chinese-date "cal-china" |
13053 | 120 "Chinese calendar equivalent of date diary entry." |
121 t) | |
122 | |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
123 (autoload 'diary-islamic-date "cal-islam" |
13053 | 124 "Islamic calendar equivalent of date diary entry." |
125 t) | |
126 | |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
127 (autoload 'list-islamic-diary-entries "cal-islam" |
13053 | 128 "Add any Islamic date entries from the diary file to `diary-entries-list'." |
129 t) | |
130 | |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
131 (autoload 'mark-islamic-diary-entries "cal-islam" |
13053 | 132 "Mark days in the calendar window that have Islamic date diary entries." |
133 t) | |
134 | |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
135 (autoload 'mark-islamic-calendar-date-pattern "cal-islam" |
13053 | 136 "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR." |
137 t) | |
138 | |
139 (autoload 'diary-hebrew-date "cal-hebrew" | |
140 "Hebrew calendar equivalent of date diary entry." | |
141 t) | |
142 | |
143 (autoload 'diary-omer "cal-hebrew" | |
144 "Omer count diary entry." | |
145 t) | |
146 | |
147 (autoload 'diary-yahrzeit "cal-hebrew" | |
148 "Yahrzeit diary entry--entry applies if date is yahrzeit or the day before." | |
149 t) | |
150 | |
151 (autoload 'diary-parasha "cal-hebrew" | |
152 "Parasha diary entry--entry applies if date is a Saturday." | |
153 t) | |
154 | |
155 (autoload 'diary-rosh-hodesh "cal-hebrew" | |
156 "Rosh Hodesh diary entry." | |
157 t) | |
158 | |
159 (autoload 'list-hebrew-diary-entries "cal-hebrew" | |
160 "Add any Hebrew date entries from the diary file to `diary-entries-list'." | |
161 t) | |
162 | |
163 (autoload 'mark-hebrew-diary-entries "cal-hebrew" | |
164 "Mark days in the calendar window that have Hebrew date diary entries." | |
165 t) | |
166 | |
167 (autoload 'mark-hebrew-calendar-date-pattern "cal-hebrew" | |
168 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR." | |
169 t) | |
170 | |
171 (autoload 'diary-coptic-date "cal-coptic" | |
172 "Coptic calendar equivalent of date diary entry." | |
173 t) | |
174 | |
175 (autoload 'diary-ethiopic-date "cal-coptic" | |
176 "Ethiopic calendar equivalent of date diary entry." | |
177 t) | |
178 | |
15258
ab5975df6164
Change autoload references from cal-persian to cal-persia.
Karl Heuer <kwzh@gnu.org>
parents:
14954
diff
changeset
|
179 (autoload 'diary-persian-date "cal-persia" |
14954
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
180 "Persian calendar equivalent of date diary entry." |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
181 t) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
182 |
13053 | 183 (autoload 'diary-phases-of-moon "lunar" "Moon phases diary entry." t) |
184 | |
185 (autoload 'diary-sunrise-sunset "solar" | |
186 "Local time of sunrise and sunset as a diary entry." | |
187 t) | |
188 | |
189 (autoload 'diary-sabbath-candles "solar" | |
190 "Local time of candle lighting diary entry--applies if date is a Friday. | |
191 No diary entry if there is no sunset on that date." | |
192 t) | |
193 | |
194 (defvar diary-syntax-table (copy-syntax-table (standard-syntax-table)) | |
195 "The syntax table used when parsing dates in the diary file. | |
196 It is the standard syntax table used in Fundamental mode, but with the | |
197 syntax of `*' changed to be a word constituent.") | |
198 | |
199 (modify-syntax-entry ?* "w" diary-syntax-table) | |
200 | |
201 (defun list-diary-entries (date number) | |
202 "Create and display a buffer containing the relevant lines in diary-file. | |
203 The arguments are DATE and NUMBER; the entries selected are those | |
204 for NUMBER days starting with date DATE. The other entries are hidden | |
205 using selective display. | |
206 | |
207 Returns a list of all relevant diary entries found, if any, in order by date. | |
208 The list entries have the form ((month day year) string). If the variable | |
209 `diary-list-include-blanks' is t, this list includes a dummy diary entry | |
210 \(consisting of the empty string) for a date with no diary entries. | |
211 | |
212 After the list is prepared, the hooks `nongregorian-diary-listing-hook', | |
213 `list-diary-entries-hook', `diary-display-hook', and `diary-hook' are run. | |
214 These hooks have the following distinct roles: | |
215 | |
216 `nongregorian-diary-listing-hook' can cull dates from the diary | |
217 and each included file. Usually used for Hebrew or Islamic | |
218 diary entries in files. Applied to *each* file. | |
219 | |
220 `list-diary-entries-hook' adds or manipulates diary entries from | |
221 external sources. Used, for example, to include diary entries | |
222 from other files or to sort the diary entries. Invoked *once* only, | |
223 before the display hook is run. | |
224 | |
225 `diary-display-hook' does the actual display of information. If this is | |
226 nil, simple-diary-display will be used. Use add-hook to set this to | |
227 fancy-diary-display, if desired. If you want no diary display, use | |
228 add-hook to set this to ignore. | |
229 | |
230 `diary-hook' is run last. This can be used for an appointment | |
231 notification function." | |
232 | |
233 (if (< 0 number) | |
234 (let* ((original-date date);; save for possible use in the hooks | |
235 (old-diary-syntax-table) | |
236 (diary-entries-list) | |
237 (date-string (calendar-date-string date)) | |
238 (d-file (substitute-in-file-name diary-file))) | |
239 (message "Preparing diary...") | |
240 (save-excursion | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
241 (let ((diary-buffer (find-buffer-visiting d-file))) |
16545
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
242 (if (not diary-buffer) |
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
243 (set-buffer (find-file-noselect d-file t)) |
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
244 (set-buffer diary-buffer) |
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
245 (or (verify-visited-file-modtime diary-buffer) |
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
246 (revert-buffer t t)))) |
13053 | 247 (setq selective-display t) |
248 (setq selective-display-ellipses nil) | |
249 (setq old-diary-syntax-table (syntax-table)) | |
250 (set-syntax-table diary-syntax-table) | |
251 (unwind-protect | |
252 (let ((buffer-read-only nil) | |
253 (diary-modified (buffer-modified-p)) | |
254 (mark (regexp-quote diary-nonmarking-symbol))) | |
255 (goto-char (1- (point-max))) | |
256 (if (not (looking-at "\^M\\|\n")) | |
257 (progn | |
258 (forward-char 1) | |
259 (insert-string "\^M"))) | |
260 (goto-char (point-min)) | |
261 (if (not (looking-at "\^M\\|\n")) | |
262 (insert-string "\^M")) | |
263 (subst-char-in-region (point-min) (point-max) ?\n ?\^M t) | |
264 (calendar-for-loop i from 1 to number do | |
265 (let ((d diary-date-forms) | |
266 (month (extract-calendar-month date)) | |
267 (day (extract-calendar-day date)) | |
268 (year (extract-calendar-year date)) | |
269 (entry-found (list-sexp-diary-entries date))) | |
270 (while d | |
271 (let* | |
272 ((date-form (if (equal (car (car d)) 'backup) | |
273 (cdr (car d)) | |
274 (car d))) | |
275 (backup (equal (car (car d)) 'backup)) | |
276 (dayname | |
277 (concat | |
278 (calendar-day-name date) "\\|" | |
279 (substring (calendar-day-name date) 0 3) ".?")) | |
280 (monthname | |
281 (concat | |
282 "\\*\\|" | |
283 (calendar-month-name month) "\\|" | |
284 (substring (calendar-month-name month) 0 3) ".?")) | |
285 (month (concat "\\*\\|0*" (int-to-string month))) | |
286 (day (concat "\\*\\|0*" (int-to-string day))) | |
287 (year | |
288 (concat | |
289 "\\*\\|0*" (int-to-string year) | |
290 (if abbreviated-calendar-year | |
291 (concat "\\|" (int-to-string (% year 100))) | |
292 ""))) | |
293 (regexp | |
294 (concat | |
295 "\\(\\`\\|\^M\\|\n\\)" mark "?\\(" | |
296 (mapconcat 'eval date-form "\\)\\(") | |
297 "\\)")) | |
298 (case-fold-search t)) | |
299 (goto-char (point-min)) | |
300 (while (re-search-forward regexp nil t) | |
301 (if backup (re-search-backward "\\<" nil t)) | |
302 (if (and (or (char-equal (preceding-char) ?\^M) | |
303 (char-equal (preceding-char) ?\n)) | |
304 (not (looking-at " \\|\^I"))) | |
305 ;; Diary entry that consists only of date. | |
306 (backward-char 1) | |
307 ;; Found a nonempty diary entry--make it visible and | |
308 ;; add it to the list. | |
309 (setq entry-found t) | |
310 (let ((entry-start (point)) | |
311 (date-start)) | |
312 (re-search-backward "\^M\\|\n\\|\\`") | |
313 (setq date-start (point)) | |
314 (re-search-forward "\^M\\|\n" nil t 2) | |
315 (while (looking-at " \\|\^I") | |
316 (re-search-forward "\^M\\|\n" nil t)) | |
317 (backward-char 1) | |
318 (subst-char-in-region date-start | |
319 (point) ?\^M ?\n t) | |
320 (add-to-diary-list | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
321 date |
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
322 (buffer-substring-no-properties |
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
323 entry-start (point))))))) |
13053 | 324 (setq d (cdr d))) |
325 (or entry-found | |
326 (not diary-list-include-blanks) | |
327 (setq diary-entries-list | |
328 (append diary-entries-list | |
329 (list (list date ""))))) | |
330 (setq date | |
331 (calendar-gregorian-from-absolute | |
332 (1+ (calendar-absolute-from-gregorian date)))) | |
333 (setq entry-found nil))) | |
334 (set-buffer-modified-p diary-modified)) | |
335 (set-syntax-table old-diary-syntax-table)) | |
336 (goto-char (point-min)) | |
337 (run-hooks 'nongregorian-diary-listing-hook | |
338 'list-diary-entries-hook) | |
339 (if diary-display-hook | |
340 (run-hooks 'diary-display-hook) | |
341 (simple-diary-display)) | |
342 (run-hooks 'diary-hook) | |
343 diary-entries-list)))) | |
344 | |
345 (defun include-other-diary-files () | |
346 "Include the diary entries from other diary files with those of diary-file. | |
347 This function is suitable for use in `list-diary-entries-hook'; | |
348 it enables you to use shared diary files together with your own. | |
349 The files included are specified in the diaryfile by lines of this form: | |
350 #include \"filename\" | |
351 This is recursive; that is, #include directives in diary files thus included | |
352 are obeyed. You can change the `#include' to some other string by | |
353 changing the variable `diary-include-string'." | |
354 (goto-char (point-min)) | |
355 (while (re-search-forward | |
356 (concat | |
357 "\\(\\`\\|\^M\\|\n\\)" | |
358 (regexp-quote diary-include-string) | |
359 " \"\\([^\"]*\\)\"") | |
360 nil t) | |
361 (let ((diary-file (substitute-in-file-name | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
362 (buffer-substring-no-properties |
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
363 (match-beginning 2) (match-end 2)))) |
13053 | 364 (diary-list-include-blanks nil) |
365 (list-diary-entries-hook 'include-other-diary-files) | |
366 (diary-display-hook 'ignore) | |
367 (diary-hook nil)) | |
368 (if (file-exists-p diary-file) | |
369 (if (file-readable-p diary-file) | |
370 (unwind-protect | |
371 (setq diary-entries-list | |
372 (append diary-entries-list | |
373 (list-diary-entries original-date number))) | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
374 (kill-buffer (find-buffer-visiting diary-file))) |
13053 | 375 (beep) |
376 (message "Can't read included diary file %s" diary-file) | |
377 (sleep-for 2)) | |
378 (beep) | |
379 (message "Can't find included diary file %s" diary-file) | |
380 (sleep-for 2)))) | |
381 (goto-char (point-min))) | |
382 | |
383 (defun simple-diary-display () | |
384 "Display the diary buffer if there are any relevant entries or holidays." | |
385 (let* ((holiday-list (if holidays-in-diary-buffer | |
386 (check-calendar-holidays original-date))) | |
387 (msg (format "No diary entries for %s %s" | |
388 (concat date-string (if holiday-list ":" "")) | |
389 (mapconcat 'identity holiday-list "; ")))) | |
390 (if (or (not diary-entries-list) | |
391 (and (not (cdr diary-entries-list)) | |
392 (string-equal (car (cdr (car diary-entries-list))) ""))) | |
393 (if (<= (length msg) (frame-width)) | |
14308
0ce52b2f2bb5
(simple-diary-display, fancy-diary-display): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
394 (message "%s" msg) |
13053 | 395 (set-buffer (get-buffer-create holiday-buffer)) |
396 (setq buffer-read-only nil) | |
397 (calendar-set-mode-line date-string) | |
398 (erase-buffer) | |
399 (insert (mapconcat 'identity holiday-list "\n")) | |
400 (goto-char (point-min)) | |
401 (set-buffer-modified-p nil) | |
402 (setq buffer-read-only t) | |
403 (display-buffer holiday-buffer) | |
404 (message "No diary entries for %s" date-string)) | |
405 (calendar-set-mode-line | |
406 (concat "Diary for " date-string | |
407 (if holiday-list ": " "") | |
408 (mapconcat 'identity holiday-list "; "))) | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
409 (display-buffer (find-buffer-visiting d-file)) |
13053 | 410 (message "Preparing diary...done")))) |
411 | |
412 (defun fancy-diary-display () | |
413 "Prepare a diary buffer with relevant entries in a fancy, noneditable form. | |
414 This function is provided for optional use as the `diary-display-hook'." | |
415 (save-excursion;; Turn off selective-display in the diary file's buffer. | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
416 (set-buffer (find-buffer-visiting (substitute-in-file-name diary-file))) |
13053 | 417 (let ((diary-modified (buffer-modified-p))) |
418 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t) | |
419 (setq selective-display nil) | |
420 (kill-local-variable 'mode-line-format) | |
421 (set-buffer-modified-p diary-modified))) | |
422 (if (or (not diary-entries-list) | |
423 (and (not (cdr diary-entries-list)) | |
424 (string-equal (car (cdr (car diary-entries-list))) ""))) | |
425 (let* ((holiday-list (if holidays-in-diary-buffer | |
426 (check-calendar-holidays original-date))) | |
427 (msg (format "No diary entries for %s %s" | |
428 (concat date-string (if holiday-list ":" "")) | |
429 (mapconcat 'identity holiday-list "; ")))) | |
430 (if (<= (length msg) (frame-width)) | |
14308
0ce52b2f2bb5
(simple-diary-display, fancy-diary-display): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
431 (message "%s" msg) |
13053 | 432 (set-buffer (get-buffer-create holiday-buffer)) |
433 (setq buffer-read-only nil) | |
434 (calendar-set-mode-line date-string) | |
435 (erase-buffer) | |
436 (insert (mapconcat 'identity holiday-list "\n")) | |
437 (goto-char (point-min)) | |
438 (set-buffer-modified-p nil) | |
439 (setq buffer-read-only t) | |
440 (display-buffer holiday-buffer) | |
441 (message "No diary entries for %s" date-string))) | |
442 (save-excursion;; Prepare the fancy diary buffer. | |
443 (set-buffer (make-fancy-diary-buffer)) | |
444 (setq buffer-read-only nil) | |
445 (let ((entry-list diary-entries-list) | |
446 (holiday-list) | |
447 (holiday-list-last-month 1) | |
448 (holiday-list-last-year 1) | |
449 (date (list 0 0 0))) | |
450 (while entry-list | |
451 (if (not (calendar-date-equal date (car (car entry-list)))) | |
452 (progn | |
453 (setq date (car (car entry-list))) | |
454 (and holidays-in-diary-buffer | |
455 (calendar-date-compare | |
456 (list (list holiday-list-last-month | |
457 (calendar-last-day-of-month | |
458 holiday-list-last-month | |
459 holiday-list-last-year) | |
460 holiday-list-last-year)) | |
461 (list date)) | |
462 ;; We need to get the holidays for the next 3 months. | |
463 (setq holiday-list-last-month | |
464 (extract-calendar-month date)) | |
465 (setq holiday-list-last-year | |
466 (extract-calendar-year date)) | |
467 (increment-calendar-month | |
468 holiday-list-last-month holiday-list-last-year 1) | |
469 (setq holiday-list | |
470 (let ((displayed-month holiday-list-last-month) | |
471 (displayed-year holiday-list-last-year)) | |
472 (calendar-holiday-list))) | |
473 (increment-calendar-month | |
474 holiday-list-last-month holiday-list-last-year 1)) | |
475 (let* ((date-string (calendar-date-string date)) | |
476 (date-holiday-list | |
477 (let ((h holiday-list) | |
478 (d)) | |
479 ;; Make a list of all holidays for date. | |
480 (while h | |
481 (if (calendar-date-equal date (car (car h))) | |
482 (setq d (append d (cdr (car h))))) | |
483 (setq h (cdr h))) | |
484 d))) | |
485 (insert (if (= (point) (point-min)) "" ?\n) date-string) | |
486 (if date-holiday-list (insert ": ")) | |
14954
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
487 (let* ((l (current-column)) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
488 (longest 0)) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
489 (insert (mapconcat '(lambda (x) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
490 (if (< longest (length x)) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
491 (setq longest (length x))) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
492 x) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
493 date-holiday-list |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
494 (concat "\n" (make-string l ? )))) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
495 (insert ?\n (make-string (+ l longest) ?=) ?\n))))) |
13053 | 496 (if (< 0 (length (car (cdr (car entry-list))))) |
497 (insert (car (cdr (car entry-list))) ?\n)) | |
498 (setq entry-list (cdr entry-list)))) | |
499 (set-buffer-modified-p nil) | |
500 (goto-char (point-min)) | |
501 (setq buffer-read-only t) | |
502 (display-buffer fancy-diary-buffer) | |
503 (message "Preparing diary...done")))) | |
504 | |
505 (defun make-fancy-diary-buffer () | |
506 "Create and return the initial fancy diary buffer." | |
507 (save-excursion | |
508 (set-buffer (get-buffer-create fancy-diary-buffer)) | |
509 (setq buffer-read-only nil) | |
510 (make-local-variable 'mode-line-format) | |
511 (calendar-set-mode-line "Diary Entries") | |
512 (erase-buffer) | |
513 (set-buffer-modified-p nil) | |
514 (setq buffer-read-only t) | |
515 (get-buffer fancy-diary-buffer))) | |
516 | |
517 (defun print-diary-entries () | |
518 "Print a hard copy of the diary display. | |
519 | |
520 If the simple diary display is being used, prepare a temp buffer with the | |
521 visible lines of the diary buffer, add a heading line composed from the mode | |
522 line, print the temp buffer, and destroy it. | |
523 | |
524 If the fancy diary display is being used, just print the buffer. | |
525 | |
526 The hooks given by the variable `print-diary-entries-hook' are called to do | |
527 the actual printing." | |
528 (interactive) | |
529 (if (bufferp (get-buffer fancy-diary-buffer)) | |
530 (save-excursion | |
531 (set-buffer (get-buffer fancy-diary-buffer)) | |
532 (run-hooks 'print-diary-entries-hook)) | |
533 (let ((diary-buffer | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
534 (find-buffer-visiting (substitute-in-file-name diary-file)))) |
13053 | 535 (if diary-buffer |
536 (let ((temp-buffer (get-buffer-create "*Printable Diary Entries*")) | |
537 (heading)) | |
538 (save-excursion | |
539 (set-buffer diary-buffer) | |
540 (setq heading | |
541 (if (not (stringp mode-line-format)) | |
542 "All Diary Entries" | |
543 (string-match "^-*\\([^-].*[^-]\\)-*$" mode-line-format) | |
544 (substring mode-line-format | |
545 (match-beginning 1) (match-end 1)))) | |
546 (copy-to-buffer temp-buffer (point-min) (point-max)) | |
547 (set-buffer temp-buffer) | |
548 (while (re-search-forward "\^M.*$" nil t) | |
549 (replace-match "")) | |
550 (goto-char (point-min)) | |
551 (insert heading "\n" | |
552 (make-string (length heading) ?=) "\n") | |
553 (run-hooks 'print-diary-entries-hook) | |
554 (kill-buffer temp-buffer))) | |
555 (error "You don't have a diary buffer!"))))) | |
556 | |
557 (defun show-all-diary-entries () | |
558 "Show all of the diary entries in the diary file. | |
559 This function gets rid of the selective display of the diary file so that | |
560 all entries, not just some, are visible. If there is no diary buffer, one | |
561 is created." | |
562 (interactive) | |
563 (let ((d-file (substitute-in-file-name diary-file))) | |
564 (if (and d-file (file-exists-p d-file)) | |
565 (if (file-readable-p d-file) | |
566 (save-excursion | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
567 (let ((diary-buffer (find-buffer-visiting d-file))) |
13053 | 568 (set-buffer (if diary-buffer |
569 diary-buffer | |
570 (find-file-noselect d-file t))) | |
571 (let ((buffer-read-only nil) | |
572 (diary-modified (buffer-modified-p))) | |
573 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t) | |
574 (setq selective-display nil) | |
575 (make-local-variable 'mode-line-format) | |
576 (setq mode-line-format default-mode-line-format) | |
577 (display-buffer (current-buffer)) | |
578 (set-buffer-modified-p diary-modified)))) | |
579 (error "Your diary file is not readable!")) | |
580 (error "You don't have a diary file!")))) | |
581 | |
582 (defun diary-name-pattern (string-array &optional fullname) | |
583 "Convert an STRING-ARRAY, an array of strings to a pattern. | |
584 The pattern will match any of the strings, either entirely or abbreviated | |
585 to three characters. An abbreviated form will match with or without a period; | |
586 If the optional FULLNAME is t, abbreviations will not match, just the full | |
587 name." | |
588 (let ((pattern "")) | |
589 (calendar-for-loop i from 0 to (1- (length string-array)) do | |
590 (setq pattern | |
591 (concat | |
592 pattern | |
593 (if (string-equal pattern "") "" "\\|") | |
594 (aref string-array i) | |
595 (if fullname | |
596 "" | |
597 (concat | |
598 "\\|" | |
599 (substring (aref string-array i) 0 3) ".?"))))) | |
600 pattern)) | |
601 | |
602 (defvar marking-diary-entries nil | |
603 "True during the marking of diary entries, nil otherwise.") | |
604 | |
605 (defvar marking-diary-entry nil | |
606 "True during the marking of diary entries, if current entry is marking.") | |
607 | |
608 (defun mark-diary-entries () | |
609 "Mark days in the calendar window that have diary entries. | |
610 Each entry in the diary file visible in the calendar window is marked. | |
611 After the entries are marked, the hooks `nongregorian-diary-marking-hook' and | |
612 `mark-diary-entries-hook' are run." | |
613 (interactive) | |
614 (setq mark-diary-entries-in-calendar t) | |
615 (let ((d-file (substitute-in-file-name diary-file)) | |
616 (marking-diary-entries t)) | |
617 (if (and d-file (file-exists-p d-file)) | |
618 (if (file-readable-p d-file) | |
619 (save-excursion | |
620 (message "Marking diary entries...") | |
621 (set-buffer (find-file-noselect d-file t)) | |
622 (let ((d diary-date-forms) | |
623 (old-diary-syntax-table)) | |
624 (setq old-diary-syntax-table (syntax-table)) | |
625 (set-syntax-table diary-syntax-table) | |
626 (while d | |
627 (let* | |
628 ((date-form (if (equal (car (car d)) 'backup) | |
629 (cdr (car d)) | |
630 (car d)));; ignore 'backup directive | |
631 (dayname (diary-name-pattern calendar-day-name-array)) | |
632 (monthname | |
633 (concat | |
634 (diary-name-pattern calendar-month-name-array) | |
635 "\\|\\*")) | |
636 (month "[0-9]+\\|\\*") | |
637 (day "[0-9]+\\|\\*") | |
638 (year "[0-9]+\\|\\*") | |
639 (l (length date-form)) | |
640 (d-name-pos (- l (length (memq 'dayname date-form)))) | |
641 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos))) | |
642 (m-name-pos (- l (length (memq 'monthname date-form)))) | |
643 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos))) | |
644 (d-pos (- l (length (memq 'day date-form)))) | |
645 (d-pos (if (/= l d-pos) (+ 2 d-pos))) | |
646 (m-pos (- l (length (memq 'month date-form)))) | |
647 (m-pos (if (/= l m-pos) (+ 2 m-pos))) | |
648 (y-pos (- l (length (memq 'year date-form)))) | |
649 (y-pos (if (/= l y-pos) (+ 2 y-pos))) | |
650 (regexp | |
651 (concat | |
652 "\\(\\`\\|\^M\\|\n\\)\\(" | |
653 (mapconcat 'eval date-form "\\)\\(") | |
654 "\\)")) | |
655 (case-fold-search t)) | |
656 (goto-char (point-min)) | |
657 (while (re-search-forward regexp nil t) | |
658 (let* ((dd-name | |
659 (if d-name-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
660 (buffer-substring-no-properties |
13053 | 661 (match-beginning d-name-pos) |
662 (match-end d-name-pos)))) | |
663 (mm-name | |
664 (if m-name-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
665 (buffer-substring-no-properties |
13053 | 666 (match-beginning m-name-pos) |
667 (match-end m-name-pos)))) | |
668 (mm (string-to-int | |
669 (if m-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
670 (buffer-substring-no-properties |
13053 | 671 (match-beginning m-pos) |
672 (match-end m-pos)) | |
673 ""))) | |
674 (dd (string-to-int | |
675 (if d-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
676 (buffer-substring-no-properties |
13053 | 677 (match-beginning d-pos) |
678 (match-end d-pos)) | |
679 ""))) | |
680 (y-str (if y-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
681 (buffer-substring-no-properties |
13053 | 682 (match-beginning y-pos) |
683 (match-end y-pos)))) | |
684 (yy (if (not y-str) | |
685 0 | |
686 (if (and (= (length y-str) 2) | |
687 abbreviated-calendar-year) | |
688 (let* ((current-y | |
689 (extract-calendar-year | |
690 (calendar-current-date))) | |
691 (y (+ (string-to-int y-str) | |
692 (* 100 | |
693 (/ current-y 100))))) | |
694 (if (> (- y current-y) 50) | |
695 (- y 100) | |
696 (if (> (- current-y y) 50) | |
697 (+ y 100) | |
698 y))) | |
699 (string-to-int y-str))))) | |
700 (if dd-name | |
701 (mark-calendar-days-named | |
702 (cdr (assoc (capitalize (substring dd-name 0 3)) | |
703 (calendar-make-alist | |
704 calendar-day-name-array | |
705 0 | |
706 '(lambda (x) (substring x 0 3)))))) | |
707 (if mm-name | |
708 (if (string-equal mm-name "*") | |
709 (setq mm 0) | |
710 (setq mm | |
711 (cdr (assoc | |
712 (capitalize | |
713 (substring mm-name 0 3)) | |
714 (calendar-make-alist | |
715 calendar-month-name-array | |
716 1 | |
717 '(lambda (x) (substring x 0 3))) | |
718 ))))) | |
719 (mark-calendar-date-pattern mm dd yy)))) | |
720 (setq d (cdr d)))) | |
721 (mark-sexp-diary-entries) | |
722 (run-hooks 'nongregorian-diary-marking-hook | |
723 'mark-diary-entries-hook) | |
724 (set-syntax-table old-diary-syntax-table) | |
725 (message "Marking diary entries...done"))) | |
726 (error "Your diary file is not readable!")) | |
727 (error "You don't have a diary file!")))) | |
728 | |
729 (defun mark-sexp-diary-entries () | |
730 "Mark days in the calendar window that have sexp diary entries. | |
731 Each entry in the diary file (or included files) visible in the calendar window | |
732 is marked. See the documentation for the function `list-sexp-diary-entries'." | |
733 (let* ((sexp-mark (regexp-quote sexp-diary-entry-symbol)) | |
734 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)\\(" | |
735 (regexp-quote sexp-mark) "(\\)\\|\\(" | |
736 (regexp-quote diary-nonmarking-symbol) | |
737 (regexp-quote sexp-mark) "(diary-remind\\)")) | |
738 (m) | |
739 (y) | |
740 (first-date) | |
741 (last-date)) | |
742 (save-excursion | |
743 (set-buffer calendar-buffer) | |
744 (setq m displayed-month) | |
745 (setq y displayed-year)) | |
746 (increment-calendar-month m y -1) | |
747 (setq first-date | |
748 (calendar-absolute-from-gregorian (list m 1 y))) | |
749 (increment-calendar-month m y 2) | |
750 (setq last-date | |
751 (calendar-absolute-from-gregorian | |
752 (list m (calendar-last-day-of-month m y) y))) | |
753 (goto-char (point-min)) | |
754 (while (re-search-forward s-entry nil t) | |
13075
8a67628f4574
(mark-sexp-diary-entries): Add \ for C-M-f's sake.
Richard M. Stallman <rms@gnu.org>
parents:
13053
diff
changeset
|
755 (if (char-equal (preceding-char) ?\() |
13053 | 756 (setq marking-diary-entry t) |
757 (setq marking-diary-entry nil)) | |
758 (re-search-backward "(") | |
759 (let ((sexp-start (point)) | |
760 (sexp) | |
761 (entry) | |
762 (entry-start) | |
763 (line-start)) | |
764 (forward-sexp) | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
765 (setq sexp (buffer-substring-no-properties sexp-start (point))) |
13053 | 766 (save-excursion |
767 (re-search-backward "\^M\\|\n\\|\\`") | |
768 (setq line-start (point))) | |
769 (forward-char 1) | |
770 (if (and (or (char-equal (preceding-char) ?\^M) | |
771 (char-equal (preceding-char) ?\n)) | |
772 (not (looking-at " \\|\^I"))) | |
773 (progn;; Diary entry consists only of the sexp | |
774 (backward-char 1) | |
775 (setq entry "")) | |
776 (setq entry-start (point)) | |
777 (re-search-forward "\^M\\|\n" nil t) | |
778 (while (looking-at " \\|\^I") | |
779 (re-search-forward "\^M\\|\n" nil t)) | |
780 (backward-char 1) | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
781 (setq entry (buffer-substring-no-properties entry-start (point))) |
13053 | 782 (while (string-match "[\^M]" entry) |
783 (aset entry (match-beginning 0) ?\n ))) | |
784 (calendar-for-loop date from first-date to last-date do | |
785 (if (diary-sexp-entry sexp entry | |
786 (calendar-gregorian-from-absolute date)) | |
787 (mark-visible-calendar-date | |
788 (calendar-gregorian-from-absolute date)))))))) | |
789 | |
790 (defun mark-included-diary-files () | |
791 "Mark the diary entries from other diary files with those of the diary file. | |
792 This function is suitable for use as the `mark-diary-entries-hook'; it enables | |
793 you to use shared diary files together with your own. The files included are | |
794 specified in the diary-file by lines of this form: | |
795 #include \"filename\" | |
796 This is recursive; that is, #include directives in diary files thus included | |
797 are obeyed. You can change the `#include' to some other string by | |
798 changing the variable `diary-include-string'." | |
799 (goto-char (point-min)) | |
800 (while (re-search-forward | |
801 (concat | |
802 "\\(\\`\\|\^M\\|\n\\)" | |
803 (regexp-quote diary-include-string) | |
804 " \"\\([^\"]*\\)\"") | |
805 nil t) | |
806 (let ((diary-file (substitute-in-file-name | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
807 (buffer-substring-no-properties |
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
808 (match-beginning 2) (match-end 2)))) |
13053 | 809 (mark-diary-entries-hook 'mark-included-diary-files)) |
810 (if (file-exists-p diary-file) | |
811 (if (file-readable-p diary-file) | |
812 (progn | |
813 (mark-diary-entries) | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
814 (kill-buffer (find-buffer-visiting diary-file))) |
13053 | 815 (beep) |
816 (message "Can't read included diary file %s" diary-file) | |
817 (sleep-for 2)) | |
818 (beep) | |
819 (message "Can't find included diary file %s" diary-file) | |
820 (sleep-for 2)))) | |
821 (goto-char (point-min))) | |
822 | |
823 (defun mark-calendar-days-named (dayname) | |
824 "Mark all dates in the calendar window that are day DAYNAME of the week. | |
825 0 means all Sundays, 1 means all Mondays, and so on." | |
826 (save-excursion | |
827 (set-buffer calendar-buffer) | |
828 (let ((prev-month displayed-month) | |
829 (prev-year displayed-year) | |
830 (succ-month displayed-month) | |
831 (succ-year displayed-year) | |
832 (last-day) | |
833 (day)) | |
834 (increment-calendar-month succ-month succ-year 1) | |
835 (increment-calendar-month prev-month prev-year -1) | |
836 (setq day (calendar-absolute-from-gregorian | |
837 (calendar-nth-named-day 1 dayname prev-month prev-year))) | |
838 (setq last-day (calendar-absolute-from-gregorian | |
839 (calendar-nth-named-day -1 dayname succ-month succ-year))) | |
840 (while (<= day last-day) | |
841 (mark-visible-calendar-date (calendar-gregorian-from-absolute day)) | |
842 (setq day (+ day 7)))))) | |
843 | |
844 (defun mark-calendar-date-pattern (month day year) | |
845 "Mark all dates in the calendar window that conform to MONTH/DAY/YEAR. | |
846 A value of 0 in any position is a wildcard." | |
847 (save-excursion | |
848 (set-buffer calendar-buffer) | |
849 (let ((m displayed-month) | |
850 (y displayed-year)) | |
851 (increment-calendar-month m y -1) | |
852 (calendar-for-loop i from 0 to 2 do | |
853 (mark-calendar-month m y month day year) | |
854 (increment-calendar-month m y 1))))) | |
855 | |
856 (defun mark-calendar-month (month year p-month p-day p-year) | |
857 "Mark dates in the MONTH/YEAR that conform to pattern P-MONTH/P_DAY/P-YEAR. | |
858 A value of 0 in any position of the pattern is a wildcard." | |
859 (if (or (and (= month p-month) | |
860 (or (= p-year 0) (= year p-year))) | |
861 (and (= p-month 0) | |
862 (or (= p-year 0) (= year p-year)))) | |
863 (if (= p-day 0) | |
864 (calendar-for-loop | |
865 i from 1 to (calendar-last-day-of-month month year) do | |
866 (mark-visible-calendar-date (list month i year))) | |
867 (mark-visible-calendar-date (list month p-day year))))) | |
868 | |
869 (defun sort-diary-entries () | |
870 "Sort the list of diary entries by time of day." | |
871 (setq diary-entries-list (sort diary-entries-list 'diary-entry-compare))) | |
872 | |
873 (defun diary-entry-compare (e1 e2) | |
874 "Returns t if E1 is earlier than E2." | |
875 (or (calendar-date-compare e1 e2) | |
876 (and (calendar-date-equal (car e1) (car e2)) | |
877 (< (diary-entry-time (car (cdr e1))) | |
878 (diary-entry-time (car (cdr e2))))))) | |
879 | |
880 (defun diary-entry-time (s) | |
881 "Time at the beginning of the string S in a military-style integer. | |
882 For example, returns 1325 for 1:25pm. Returns -9999 if no time is recognized. | |
883 The recognized forms are XXXX or X:XX or XX:XX (military time), XXam or XXpm, | |
884 and XX:XXam or XX:XXpm." | |
19324
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
885 (let ((case-fold-search nil)) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
886 (cond ((string-match;; Military time |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
887 "^[ \t]*\\([0-9]?[0-9]\\):?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)" s) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
888 (+ (* 100 (string-to-int |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
889 (substring s (match-beginning 1) (match-end 1)))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
890 (string-to-int (substring s (match-beginning 2) (match-end 2))))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
891 ((string-match;; Hour only XXam or XXpm |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
892 "^[ \t]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
893 (+ (* 100 (% (string-to-int |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
894 (substring s (match-beginning 1) (match-end 1))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
895 12)) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
896 (if (equal ?a (downcase (aref s (match-beginning 2)))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
897 0 1200))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
898 ((string-match;; Hour and minute XX:XXam or XX:XXpm |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
899 "^[ \t]*\\([0-9]?[0-9]\\):\\([0-9][0-9]\\)\\([ap]\\)m\\>" s) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
900 (+ (* 100 (% (string-to-int |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
901 (substring s (match-beginning 1) (match-end 1))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
902 12)) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
903 (string-to-int (substring s (match-beginning 2) (match-end 2))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
904 (if (equal ?a (downcase (aref s (match-beginning 3)))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
905 0 1200))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
906 (t -9999))));; Unrecognizable |
13053 | 907 |
908 (defun list-sexp-diary-entries (date) | |
909 "Add sexp entries for DATE from the diary file to `diary-entries-list'. | |
910 Also, Make them visible in the diary file. Returns t if any entries were | |
911 found. | |
912 | |
913 Sexp diary entries must be prefaced by a `sexp-diary-entry-symbol' (normally | |
914 `%%'). The form of a sexp diary entry is | |
915 | |
916 %%(SEXP) ENTRY | |
917 | |
918 Both ENTRY and DATE are globally available when the SEXP is evaluated. If the | |
919 SEXP yields the value nil, the diary entry does not apply. If it yields a | |
920 non-nil value, ENTRY will be taken to apply to DATE; if the non-nil value is a | |
921 string, that string will be the diary entry in the fancy diary display. | |
922 | |
923 For example, the following diary entry will apply to the 21st of the month | |
924 if it is a weekday and the Friday before if the 21st is on a weekend: | |
925 | |
926 &%%(let ((dayname (calendar-day-of-week date)) | |
927 (day (extract-calendar-day date))) | |
928 (or | |
929 (and (= day 21) (memq dayname '(1 2 3 4 5))) | |
930 (and (memq day '(19 20)) (= dayname 5))) | |
931 ) UIUC pay checks deposited | |
932 | |
933 A number of built-in functions are available for this type of diary entry: | |
934 | |
935 %%(diary-date MONTH DAY YEAR) text | |
936 Entry applies if date is MONTH, DAY, YEAR if | |
937 `european-calendar-style' is nil, and DAY, MONTH, YEAR if | |
938 `european-calendar-style' is t. DAY, MONTH, and YEAR | |
939 can be lists of integers, the constant t, or an integer. | |
940 The constant t means all values. | |
941 | |
17892
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
942 %%(diary-float MONTH DAYNAME N &optional DAY) text |
13053 | 943 Entry will appear on the Nth DAYNAME of MONTH. |
944 (DAYNAME=0 means Sunday, 1 means Monday, and so on; | |
945 if N is negative it counts backward from the end of | |
946 the month. MONTH can be a list of months, a single | |
17892
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
947 month, or t to specify all months. Optional DAY means |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
948 Nth DAYNAME of MONTH on or after/before DAY. DAY defaults |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
949 to 1 if N>0 and the last day of the month if N<0. |
13053 | 950 |
951 %%(diary-block M1 D1 Y1 M2 D2 Y2) text | |
952 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2, | |
953 inclusive. (If `european-calendar-style' is t, the | |
954 order of the parameters should be changed to D1, M1, Y1, | |
955 D2, M2, Y2.) | |
956 | |
957 %%(diary-anniversary MONTH DAY YEAR) text | |
958 Entry will appear on anniversary dates of MONTH DAY, YEAR. | |
959 (If `european-calendar-style' is t, the order of the | |
960 parameters should be changed to DAY, MONTH, YEAR.) Text | |
961 can contain %d or %d%s; %d will be replaced by the number | |
962 of years since the MONTH DAY, YEAR and %s will be replaced | |
963 by the ordinal ending of that number (that is, `st', `nd', | |
964 `rd' or `th', as appropriate. The anniversary of February | |
965 29 is considered to be March 1 in a non-leap year. | |
966 | |
967 %%(diary-cyclic N MONTH DAY YEAR) text | |
968 Entry will appear every N days, starting MONTH DAY, YEAR. | |
969 (If `european-calendar-style' is t, the order of the | |
970 parameters should be changed to N, DAY, MONTH, YEAR.) Text | |
971 can contain %d or %d%s; %d will be replaced by the number | |
972 of repetitions since the MONTH DAY, YEAR and %s will | |
973 be replaced by the ordinal ending of that number (that is, | |
974 `st', `nd', `rd' or `th', as appropriate. | |
975 | |
976 %%(diary-remind SEXP DAYS &optional MARKING) text | |
977 Entry is a reminder for diary sexp SEXP. DAYS is either a | |
978 single number or a list of numbers indicating the number(s) | |
979 of days before the event that the warning(s) should occur. | |
980 If the current date is (one of) DAYS before the event | |
981 indicated by EXPR, then a suitable message (as specified | |
982 by `diary-remind-message') appears. In addition to the | |
983 reminders beforehand, the diary entry also appears on | |
984 the date itself. If optional MARKING is non-nil then the | |
985 *reminders* are marked on the calendar. Marking of | |
986 reminders is independent of whether the entry *itself* is | |
987 a marking or nonmarking one. | |
988 | |
989 %%(diary-day-of-year) | |
990 Diary entries giving the day of the year and the number of | |
991 days remaining in the year will be made every day. Note | |
992 that since there is no text, it makes sense only if the | |
993 fancy diary display is used. | |
994 | |
995 %%(diary-iso-date) | |
996 Diary entries giving the corresponding ISO commercial date | |
997 will be made every day. Note that since there is no text, | |
998 it makes sense only if the fancy diary display is used. | |
999 | |
1000 %%(diary-french-date) | |
1001 Diary entries giving the corresponding French Revolutionary | |
1002 date will be made every day. Note that since there is no | |
1003 text, it makes sense only if the fancy diary display is used. | |
1004 | |
1005 %%(diary-islamic-date) | |
1006 Diary entries giving the corresponding Islamic date will be | |
1007 made every day. Note that since there is no text, it | |
1008 makes sense only if the fancy diary display is used. | |
1009 | |
1010 %%(diary-hebrew-date) | |
1011 Diary entries giving the corresponding Hebrew date will be | |
1012 made every day. Note that since there is no text, it | |
1013 makes sense only if the fancy diary display is used. | |
1014 | |
1015 %%(diary-astro-day-number) Diary entries giving the corresponding | |
1016 astronomical (Julian) day number will be made every day. | |
1017 Note that since there is no text, it makes sense only if the | |
1018 fancy diary display is used. | |
1019 | |
1020 %%(diary-julian-date) Diary entries giving the corresponding | |
1021 Julian date will be made every day. Note that since | |
1022 there is no text, it makes sense only if the fancy diary | |
1023 display is used. | |
1024 | |
1025 %%(diary-sunrise-sunset) | |
1026 Diary entries giving the local times of sunrise and sunset | |
1027 will be made every day. Note that since there is no text, | |
1028 it makes sense only if the fancy diary display is used. | |
1029 Floating point required. | |
1030 | |
1031 %%(diary-phases-of-moon) | |
1032 Diary entries giving the times of the phases of the moon | |
1033 will be when appropriate. Note that since there is no text, | |
1034 it makes sense only if the fancy diary display is used. | |
1035 Floating point required. | |
1036 | |
1037 %%(diary-yahrzeit MONTH DAY YEAR) text | |
1038 Text is assumed to be the name of the person; the date is | |
1039 the date of death on the *civil* calendar. The diary entry | |
1040 will appear on the proper Hebrew-date anniversary and on the | |
1041 day before. (If `european-calendar-style' is t, the order | |
1042 of the parameters should be changed to DAY, MONTH, YEAR.) | |
1043 | |
1044 %%(diary-rosh-hodesh) | |
1045 Diary entries will be made on the dates of Rosh Hodesh on | |
1046 the Hebrew calendar. Note that since there is no text, it | |
1047 makes sense only if the fancy diary display is used. | |
1048 | |
1049 %%(diary-parasha) | |
1050 Diary entries giving the weekly parasha will be made on | |
1051 every Saturday. Note that since there is no text, it | |
1052 makes sense only if the fancy diary display is used. | |
1053 | |
1054 %%(diary-omer) | |
1055 Diary entries giving the omer count will be made every day | |
13670
15c441f6d41a
(list-sexp-diary-entries): Doc fix.
Paul Eggert <eggert@twinsun.com>
parents:
13650
diff
changeset
|
1056 from Passover to Shavuot. Note that since there is no text, |
13053 | 1057 it makes sense only if the fancy diary display is used. |
1058 | |
1059 Marking these entries is *extremely* time consuming, so these entries are | |
1060 best if they are nonmarking." | |
1061 (let* ((mark (regexp-quote diary-nonmarking-symbol)) | |
1062 (sexp-mark (regexp-quote sexp-diary-entry-symbol)) | |
1063 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)" mark "?" sexp-mark "(")) | |
1064 (entry-found)) | |
1065 (goto-char (point-min)) | |
1066 (while (re-search-forward s-entry nil t) | |
1067 (backward-char 1) | |
1068 (let ((sexp-start (point)) | |
1069 (sexp) | |
1070 (entry) | |
1071 (entry-start) | |
1072 (line-start)) | |
1073 (forward-sexp) | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
1074 (setq sexp (buffer-substring-no-properties sexp-start (point))) |
13053 | 1075 (save-excursion |
1076 (re-search-backward "\^M\\|\n\\|\\`") | |
1077 (setq line-start (point))) | |
1078 (forward-char 1) | |
1079 (if (and (or (char-equal (preceding-char) ?\^M) | |
1080 (char-equal (preceding-char) ?\n)) | |
1081 (not (looking-at " \\|\^I"))) | |
1082 (progn;; Diary entry consists only of the sexp | |
1083 (backward-char 1) | |
1084 (setq entry "")) | |
1085 (setq entry-start (point)) | |
1086 (re-search-forward "\^M\\|\n" nil t) | |
1087 (while (looking-at " \\|\^I") | |
1088 (re-search-forward "\^M\\|\n" nil t)) | |
1089 (backward-char 1) | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
1090 (setq entry (buffer-substring-no-properties entry-start (point))) |
13053 | 1091 (while (string-match "[\^M]" entry) |
1092 (aset entry (match-beginning 0) ?\n ))) | |
1093 (let ((diary-entry (diary-sexp-entry sexp entry date))) | |
1094 (if diary-entry | |
1095 (subst-char-in-region line-start (point) ?\^M ?\n t)) | |
1096 (add-to-diary-list date diary-entry) | |
1097 (setq entry-found (or entry-found diary-entry))))) | |
1098 entry-found)) | |
1099 | |
1100 (defun diary-sexp-entry (sexp entry date) | |
1101 "Process a SEXP diary ENTRY for DATE." | |
1102 (let ((result (if calendar-debug-sexp | |
1103 (let ((stack-trace-on-error t)) | |
1104 (eval (car (read-from-string sexp)))) | |
1105 (condition-case nil | |
1106 (eval (car (read-from-string sexp))) | |
1107 (error | |
1108 (beep) | |
1109 (message "Bad sexp at line %d in %s: %s" | |
1110 (save-excursion | |
1111 (save-restriction | |
1112 (narrow-to-region 1 (point)) | |
1113 (goto-char (point-min)) | |
1114 (let ((lines 1)) | |
1115 (while (re-search-forward "\n\\|\^M" nil t) | |
1116 (setq lines (1+ lines))) | |
1117 lines))) | |
1118 diary-file sexp) | |
1119 (sleep-for 2)))))) | |
1120 (if (stringp result) | |
1121 result | |
1122 (if result | |
1123 entry | |
1124 nil)))) | |
1125 | |
1126 (defun diary-date (month day year) | |
1127 "Specific date(s) diary entry. | |
1128 Entry applies if date is MONTH, DAY, YEAR if `european-calendar-style' is nil, | |
1129 and DAY, MONTH, YEAR if `european-calendar-style' is t. DAY, MONTH, and YEAR | |
1130 can be lists of integers, the constant t, or an integer. The constant t means | |
1131 all values." | |
1132 (let* ((dd (if european-calendar-style | |
1133 month | |
1134 day)) | |
1135 (mm (if european-calendar-style | |
1136 day | |
1137 month)) | |
1138 (m (extract-calendar-month date)) | |
1139 (y (extract-calendar-year date)) | |
1140 (d (extract-calendar-day date))) | |
1141 (if (and | |
1142 (or (and (listp dd) (memq d dd)) | |
1143 (equal d dd) | |
1144 (eq dd t)) | |
1145 (or (and (listp mm) (memq m mm)) | |
1146 (equal m mm) | |
1147 (eq mm t)) | |
1148 (or (and (listp year) (memq y year)) | |
1149 (equal y year) | |
1150 (eq year t))) | |
1151 entry))) | |
1152 | |
1153 (defun diary-block (m1 d1 y1 m2 d2 y2) | |
1154 "Block diary entry. | |
1155 Entry applies if date is between two dates. Order of the parameters is | |
1156 M1, D1, Y1, M2, D2, Y2 `european-calendar-style' is nil, and | |
1157 D1, M1, Y1, D2, M2, Y2 if `european-calendar-style' is t." | |
1158 (let ((date1 (calendar-absolute-from-gregorian | |
1159 (if european-calendar-style | |
1160 (list d1 m1 y1) | |
1161 (list m1 d1 y1)))) | |
1162 (date2 (calendar-absolute-from-gregorian | |
1163 (if european-calendar-style | |
1164 (list d2 m2 y2) | |
1165 (list m2 d2 y2)))) | |
1166 (d (calendar-absolute-from-gregorian date))) | |
1167 (if (and (<= date1 d) (<= d date2)) | |
1168 entry))) | |
1169 | |
17892
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1170 (defun diary-float (month dayname n &optional day) |
13053 | 1171 "Floating diary entry--entry applies if date is the nth dayname of month. |
1172 Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant | |
1173 t, or an integer. The constant t means all months. If N is negative, count | |
17892
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1174 backward from the end of the month. |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1175 |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1176 An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY." |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1177 ;; This is messy because the diary entry may apply, but the date on which it |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1178 ;; is based can be in a different month/year. For example, asking for the |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1179 ;; first Monday after December 30. For large values of |n| the problem is |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1180 ;; more grotesque. |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1181 (and (= dayname (calendar-day-of-week date)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1182 (let* ((m (extract-calendar-month date)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1183 (d (extract-calendar-day date)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1184 (y (extract-calendar-year date)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1185 (limit; last (n>0) or first (n<0) possible base date for entry |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1186 (calendar-nth-named-absday (- n) dayname m y d)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1187 (last-abs (if (> n 0) limit (+ limit 6))) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1188 (first-abs (if (> n 0) (- limit 6) limit)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1189 (last (calendar-gregorian-from-absolute last-abs)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1190 (first (calendar-gregorian-from-absolute first-abs)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1191 ; m1, d1 is first possible base date |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1192 (m1 (extract-calendar-month first)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1193 (d1 (extract-calendar-day first)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1194 (y1 (extract-calendar-year first)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1195 ; m2, d2 is last possible base date |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1196 (m2 (extract-calendar-month last)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1197 (d2 (extract-calendar-day last)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1198 (y2 (extract-calendar-year last))) |
18590
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1199 (if (or (and (= m1 m2) ; only possible base dates in one month |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1200 (or (and (listp month) (memq m1 month)) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1201 (eq month t) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1202 (= m1 month)) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1203 (let ((d (or day (if (> n 0) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1204 1 |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1205 (calendar-last-day-of-month m1 y1))))) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1206 (and (<= d1 d) (<= d d2)))) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1207 ;; only possible base dates straddle two months |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1208 (and (< m1 m2) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1209 (or |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1210 ;; m1, d1 works is a base date |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1211 (and |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1212 (or (and (listp month) (memq m1 month)) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1213 (eq month t) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1214 (= m1 month)) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1215 (<= d1 (or day (if (> n 0) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1216 1 |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1217 (calendar-last-day-of-month m1 y1))))) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1218 ;; m2, d2 works is a base date |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1219 (and (or (and (listp month) (memq m2 month)) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1220 (eq month t) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1221 (= m2 month)) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1222 (<= (or day (if (> n 0) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1223 1 |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1224 (calendar-last-day-of-month m2 y2))) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1225 d2))))) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1226 entry)))) |
13053 | 1227 |
1228 (defun diary-anniversary (month day year) | |
1229 "Anniversary diary entry. | |
1230 Entry applies if date is the anniversary of MONTH, DAY, YEAR if | |
1231 `european-calendar-style' is nil, and DAY, MONTH, YEAR if | |
1232 `european-calendar-style' is t. Diary entry can contain `%d' or `%d%s'; the | |
1233 %d will be replaced by the number of years since the MONTH DAY, YEAR and the | |
1234 %s will be replaced by the ordinal ending of that number (that is, `st', `nd', | |
1235 `rd' or `th', as appropriate. The anniversary of February 29 is considered | |
1236 to be March 1 in non-leap years." | |
1237 (let* ((d (if european-calendar-style | |
1238 month | |
1239 day)) | |
1240 (m (if european-calendar-style | |
1241 day | |
1242 month)) | |
1243 (y (extract-calendar-year date)) | |
1244 (diff (- y year))) | |
1245 (if (and (= m 2) (= d 29) (not (calendar-leap-year-p y))) | |
1246 (setq m 3 | |
1247 d 1)) | |
1248 (if (and (> diff 0) (calendar-date-equal (list m d y) date)) | |
1249 (format entry diff (diary-ordinal-suffix diff))))) | |
1250 | |
1251 (defun diary-cyclic (n month day year) | |
1252 "Cycle diary entry--entry applies every N days starting at MONTH, DAY, YEAR. | |
1253 If `european-calendar-style' is t, parameters are N, DAY, MONTH, YEAR. | |
1254 ENTRY can contain `%d' or `%d%s'; the %d will be replaced by the number of | |
1255 years since the MONTH DAY, YEAR and the %s will be replaced by the ordinal | |
1256 ending of that number (that is, `st', `nd', `rd' or `th', as appropriate." | |
1257 (let* ((d (if european-calendar-style | |
1258 month | |
1259 day)) | |
1260 (m (if european-calendar-style | |
1261 day | |
1262 month)) | |
1263 (diff (- (calendar-absolute-from-gregorian date) | |
1264 (calendar-absolute-from-gregorian | |
1265 (list m d year)))) | |
1266 (cycle (/ diff n))) | |
1267 (if (and (>= diff 0) (zerop (% diff n))) | |
1268 (format entry cycle (diary-ordinal-suffix cycle))))) | |
1269 | |
1270 (defun diary-ordinal-suffix (n) | |
1271 "Ordinal suffix for N. (That is, `st', `nd', `rd', or `th', as appropriate.)" | |
1272 (if (or (memq (% n 100) '(11 12 13)) | |
1273 (< 3 (% n 10))) | |
1274 "th" | |
1275 (aref ["th" "st" "nd" "rd"] (% n 10)))) | |
1276 | |
1277 (defun diary-day-of-year () | |
1278 "Day of year and number of days remaining in the year of date diary entry." | |
1279 (calendar-day-of-year-string date)) | |
1280 | |
17626 | 1281 (defcustom diary-remind-message |
13053 | 1282 '("Reminder: Only " |
1283 (if (= 0 (% days 7)) | |
1284 (concat (int-to-string (/ days 7)) (if (= 7 days) " week" " weeks")) | |
1285 (concat (int-to-string days) (if (= 1 days) " day" " days"))) | |
1286 " until " | |
1287 diary-entry) | |
1288 "*Pseudo-pattern giving form of reminder messages in the fancy diary | |
1289 display. | |
1290 | |
1291 Used by the function `diary-remind', a pseudo-pattern is a list of | |
1292 expressions that can involve the keywords `days' (a number), `date' (a list of | |
17626 | 1293 month, day, year), and `diary-entry' (a string)." |
1294 :type 'sexp | |
1295 :group 'diary) | |
13053 | 1296 |
1297 (defun diary-remind (sexp days &optional marking) | |
1298 "Provide a reminder of a diary entry. | |
1299 SEXP is a diary-sexp. DAYS is either a single number or a list of numbers | |
1300 indicating the number(s) of days before the event that the warning(s) should | |
1301 occur on. If the current date is (one of) DAYS before the event indicated by | |
1302 SEXP, then a suitable message (as specified by `diary-remind-message' is | |
1303 returned. | |
1304 | |
1305 In addition to the reminders beforehand, the diary entry also appears on | |
1306 the date itself. | |
1307 | |
1308 If optional parameter MARKING is non-nil then the reminders are marked on the | |
1309 calendar. Marking of reminders is independent of whether the entry itself is | |
1310 a marking or nonmarking one." | |
1311 (let ((diary-entry)) | |
1312 (if (or (not marking-diary-entries) marking) | |
1313 (cond | |
1314 ((integerp days) | |
1315 (let ((date (calendar-gregorian-from-absolute | |
1316 (+ (calendar-absolute-from-gregorian date) days)))) | |
1317 (if (setq diary-entry (eval sexp)) | |
1318 (setq diary-entry (mapconcat 'eval diary-remind-message ""))))) | |
1319 ((and (listp days) days) | |
1320 (setq diary-entry (diary-remind sexp (car days) marking)) | |
1321 (if (not diary-entry) | |
1322 (setq diary-entry (diary-remind sexp (cdr days) marking)))))) | |
1323 (or diary-entry | |
1324 (and (or (not marking-diary-entries) marking-diary-entry) | |
1325 (eval sexp))))) | |
1326 | |
1327 (defun add-to-diary-list (date string) | |
1328 "Add the entry (DATE STRING) to `diary-entries-list'. | |
1329 Do nothing if DATE or STRING is nil." | |
1330 (and date string | |
1331 (setq diary-entries-list | |
1332 (append diary-entries-list (list (list date string)))))) | |
1333 | |
1334 (defun make-diary-entry (string &optional nonmarking file) | |
1335 "Insert a diary entry STRING which may be NONMARKING in FILE. | |
1336 If omitted, NONMARKING defaults to nil and FILE defaults to diary-file." | |
1337 (find-file-other-window | |
1338 (substitute-in-file-name (if file file diary-file))) | |
1339 (goto-char (point-max)) | |
1340 (insert | |
1341 (if (bolp) "" "\n") | |
1342 (if nonmarking diary-nonmarking-symbol "") | |
1343 string " ")) | |
1344 | |
1345 (defun insert-diary-entry (arg) | |
1346 "Insert a diary entry for the date indicated by point. | |
1347 Prefix arg will make the entry nonmarking." | |
1348 (interactive "P") | |
1349 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t t) | |
1350 arg)) | |
1351 | |
1352 (defun insert-weekly-diary-entry (arg) | |
1353 "Insert a weekly diary entry for the day of the week indicated by point. | |
1354 Prefix arg will make the entry nonmarking." | |
1355 (interactive "P") | |
1356 (make-diary-entry (calendar-day-name (calendar-cursor-to-date t)) | |
1357 arg)) | |
1358 | |
1359 (defun insert-monthly-diary-entry (arg) | |
1360 "Insert a monthly diary entry for the day of the month indicated by point. | |
1361 Prefix arg will make the entry nonmarking." | |
1362 (interactive "P") | |
1363 (let* ((calendar-date-display-form | |
1364 (if european-calendar-style | |
1365 '(day " * ") | |
1366 '("* " day)))) | |
1367 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t) | |
1368 arg))) | |
1369 | |
1370 (defun insert-yearly-diary-entry (arg) | |
1371 "Insert an annual diary entry for the day of the year indicated by point. | |
1372 Prefix arg will make the entry nonmarking." | |
1373 (interactive "P") | |
1374 (let* ((calendar-date-display-form | |
1375 (if european-calendar-style | |
1376 '(day " " monthname) | |
1377 '(monthname " " day)))) | |
1378 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t) | |
1379 arg))) | |
1380 | |
1381 (defun insert-anniversary-diary-entry (arg) | |
1382 "Insert an anniversary diary entry for the date given by point. | |
1383 Prefix arg will make the entry nonmarking." | |
1384 (interactive "P") | |
1385 (let* ((calendar-date-display-form | |
1386 (if european-calendar-style | |
1387 '(day " " month " " year) | |
1388 '(month " " day " " year)))) | |
1389 (make-diary-entry | |
1390 (format "%s(diary-anniversary %s)" | |
1391 sexp-diary-entry-symbol | |
1392 (calendar-date-string (calendar-cursor-to-date t) nil t)) | |
1393 arg))) | |
1394 | |
1395 (defun insert-block-diary-entry (arg) | |
1396 "Insert a block diary entry for the days between the point and marked date. | |
1397 Prefix arg will make the entry nonmarking." | |
1398 (interactive "P") | |
1399 (let* ((calendar-date-display-form | |
1400 (if european-calendar-style | |
1401 '(day " " month " " year) | |
1402 '(month " " day " " year))) | |
1403 (cursor (calendar-cursor-to-date t)) | |
1404 (mark (or (car calendar-mark-ring) | |
1405 (error "No mark set in this buffer"))) | |
1406 (start) | |
1407 (end)) | |
1408 (if (< (calendar-absolute-from-gregorian mark) | |
1409 (calendar-absolute-from-gregorian cursor)) | |
1410 (setq start mark | |
1411 end cursor) | |
1412 (setq start cursor | |
1413 end mark)) | |
1414 (make-diary-entry | |
1415 (format "%s(diary-block %s %s)" | |
1416 sexp-diary-entry-symbol | |
1417 (calendar-date-string start nil t) | |
1418 (calendar-date-string end nil t)) | |
1419 arg))) | |
1420 | |
1421 (defun insert-cyclic-diary-entry (arg) | |
1422 "Insert a cyclic diary entry starting at the date given by point. | |
1423 Prefix arg will make the entry nonmarking." | |
1424 (interactive "P") | |
1425 (let* ((calendar-date-display-form | |
1426 (if european-calendar-style | |
1427 '(day " " month " " year) | |
1428 '(month " " day " " year)))) | |
1429 (make-diary-entry | |
1430 (format "%s(diary-cyclic %d %s)" | |
1431 sexp-diary-entry-symbol | |
1432 (calendar-read "Repeat every how many days: " | |
1433 '(lambda (x) (> x 0))) | |
1434 (calendar-date-string (calendar-cursor-to-date t) nil t)) | |
1435 arg))) | |
1436 | |
13650 | 1437 (provide 'diary-lib) |
13053 | 1438 |
13650 | 1439 ;;; diary-lib.el ends here |