Mercurial > emacs
annotate lisp/=diary-lib.el @ 783:59dc833c4e0c
*** empty log message ***
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Wed, 15 Jul 1992 18:48:42 +0000 |
parents | cd00bdacc17b |
children | c693d56ef36d |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; diary.el --- diary functions. |
732 | 2 ;; Copyright (C) 1989, 1990 Free Software Foundation, Inc. |
406 | 3 |
4 ;; This file is part of GNU Emacs. | |
5 | |
6 ;; GNU Emacs is distributed in the hope that it will be useful, | |
7 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
8 ;; accepts responsibility to anyone for the consequences of using it | |
9 ;; or for whether it serves any particular purpose or works at all, | |
10 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
11 ;; License for full details. | |
12 | |
13 ;; Everyone is granted permission to copy, modify and redistribute | |
14 ;; GNU Emacs, but only under the conditions described in the | |
15 ;; GNU Emacs General Public License. A copy of this license is | |
16 ;; supposed to have been given to you along with GNU Emacs so you | |
17 ;; can know your rights and responsibilities. It should be in a | |
18 ;; file named COPYING. Among other things, the copyright notice | |
19 ;; and this notice must be preserved on all copies. | |
20 | |
21 ;; This collection of functions implements the diary features as described | |
22 ;; in calendar.el. | |
23 | |
24 ;; Comments, corrections, and improvements should be sent to | |
25 ;; Edward M. Reingold Department of Computer Science | |
26 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
27 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
28 ;; Urbana, Illinois 61801 | |
29 | |
30 (require 'calendar) | |
732 | 31 |
32 ;;;###autoload | |
406 | 33 (defun diary (&optional arg) |
34 "Generate the diary window for ARG days starting with the current date. | |
35 If no argument is provided, the number of days of diary entries is governed | |
36 by the variable `number-of-diary-entries'. This function is suitable for | |
37 execution in a .emacs file." | |
38 (interactive "P") | |
39 (let ((d-file (substitute-in-file-name diary-file)) | |
40 (date (calendar-current-date))) | |
41 (if (and d-file (file-exists-p d-file)) | |
42 (if (file-readable-p d-file) | |
43 (list-diary-entries | |
44 date | |
45 (cond | |
46 (arg (prefix-numeric-value arg)) | |
47 ((vectorp number-of-diary-entries) | |
48 (aref number-of-diary-entries (calendar-day-of-week date))) | |
49 (t number-of-diary-entries))) | |
50 (error "Your diary file is not readable!")) | |
51 (error "You don't have a diary file!")))) | |
52 | |
53 (defun view-diary-entries (arg) | |
54 "Prepare and display a buffer with diary entries. | |
55 Searches the file diary-file for entries that match ARG days starting with | |
56 the date indicated by the cursor position in the displayed three-month | |
57 calendar." | |
58 (interactive "p") | |
59 (let ((d-file (substitute-in-file-name diary-file))) | |
60 (if (and d-file (file-exists-p d-file)) | |
61 (if (file-readable-p d-file) | |
62 (list-diary-entries (or (calendar-cursor-to-date) | |
63 (error "Cursor is not on a date!")) | |
64 arg) | |
65 (error "Your diary file is not readable!")) | |
66 (error "You don't have a diary file!")))) | |
67 | |
68 (autoload 'check-calendar-holidays "holidays" | |
69 "Check the list of holidays for any that occur on DATE. | |
70 The value returned is a list of strings of relevant holiday descriptions. | |
71 The holidays are those in the list calendar-holidays.") | |
72 | |
73 (autoload 'calendar-holiday-list "holidays" | |
74 "Form the list of holidays that occur on dates in the calendar window. | |
75 The holidays are those in the list calendar-holidays.") | |
76 | |
77 (defvar diary-syntax-table | |
78 (standard-syntax-table) | |
79 "The syntax table used when parsing dates in the diary file. | |
80 It is the standard syntax table used in Fundamental mode, but with the | |
81 syntax of `*' changed to be a word constituent.") | |
82 | |
83 (modify-syntax-entry ?* "w" diary-syntax-table) | |
84 | |
85 (defun list-diary-entries (date number) | |
86 "Create and display a buffer containing the relevant lines in diary-file. | |
87 All lines that apply to DATE and the next NUMBER-1 days are included. | |
88 | |
89 Makes all diary entries in the diary file invisible (using selective display), | |
90 *except* those that are relevant. | |
91 | |
92 Returns a list of all relevant diary entries found, if any, in order by date. | |
93 The list entries have the form ((month day year) string). If the variable | |
94 `diary-list-include-blanks' is t, this list will include a dummy diary entry | |
95 \(consisting of the empty string\) for a date with no diary entries. | |
96 | |
97 After the list is prepared, the hooks `nongregorian-diary-listing-hook', | |
98 `list-diary-entries-hook', and `diary-display-hook' are run. These hooks | |
99 have the following distinct roles: | |
100 | |
101 `nongregorian-diary-listing-hook' can cull dates from the diary | |
102 and each included file. Usually used for Hebrew or Islamic | |
103 diary entries in files. Applied to *each* file. | |
104 | |
105 `list-diary-entries-hook' adds or manipulates diary entries from | |
106 external sources. Used, for example, to include diary entries | |
107 from other files or to sort the diary entries. Invoked *once* only. | |
108 | |
109 `diary-display-hook' does the actual display of information. Could be | |
110 used also for an appointment notification function." | |
111 | |
112 (if (< 0 number) | |
113 (let* ((original-date date);; save for possible use in the hooks | |
114 (old-diary-syntax-table) | |
115 (diary-entries-list) | |
116 (date-string (calendar-date-string date)) | |
117 (d-file (substitute-in-file-name diary-file))) | |
118 (message "Preparing diary...") | |
119 (save-excursion | |
120 (let ((diary-buffer (get-file-buffer d-file))) | |
121 (set-buffer (if diary-buffer | |
122 diary-buffer | |
123 (find-file-noselect d-file t)))) | |
124 (setq selective-display t) | |
125 (setq selective-display-ellipses nil) | |
126 (setq old-diary-syntax-table (syntax-table)) | |
127 (set-syntax-table diary-syntax-table) | |
128 (unwind-protect | |
129 (let ((buffer-read-only nil) | |
130 (diary-modified (buffer-modified-p)) | |
131 (mark (regexp-quote diary-nonmarking-symbol))) | |
132 (goto-char (1- (point-max))) | |
133 (if (not (looking-at "\^M\\|\n")) | |
134 (progn | |
135 (forward-char 1) | |
136 (insert-string "\^M"))) | |
137 (goto-char (point-min)) | |
138 (if (not (looking-at "\^M\\|\n")) | |
139 (insert-string "\^M")) | |
140 (subst-char-in-region (point-min) (point-max) ?\n ?\^M t) | |
141 (calendar-for-loop i from 1 to number do | |
142 (let ((d diary-date-forms) | |
143 (month (extract-calendar-month date)) | |
144 (day (extract-calendar-day date)) | |
145 (year (extract-calendar-year date)) | |
146 (entry-found (list-sexp-diary-entries date))) | |
147 (while d | |
148 (let* | |
149 ((date-form (if (equal (car (car d)) 'backup) | |
150 (cdr (car d)) | |
151 (car d))) | |
152 (backup (equal (car (car d)) 'backup)) | |
153 (dayname | |
154 (concat | |
155 (calendar-day-name date) "\\|" | |
156 (substring (calendar-day-name date) 0 3) ".?")) | |
157 (monthname | |
158 (concat | |
159 "\\*\\|" | |
160 (calendar-month-name month) "\\|" | |
161 (substring (calendar-month-name month) 0 3) ".?")) | |
162 (month (concat "\\*\\|0*" (int-to-string month))) | |
163 (day (concat "\\*\\|0*" (int-to-string day))) | |
164 (year | |
165 (concat | |
166 "\\*\\|0*" (int-to-string year) | |
167 (if abbreviated-calendar-year | |
168 (concat "\\|" (int-to-string (% year 100))) | |
169 ""))) | |
170 (regexp | |
171 (concat | |
172 "\\(\\`\\|\^M\\|\n\\)" mark "?\\(" | |
173 (mapconcat 'eval date-form "\\)\\(") | |
174 "\\)")) | |
175 (case-fold-search t)) | |
176 (goto-char (point-min)) | |
177 (while (re-search-forward regexp nil t) | |
178 (if backup (re-search-backward "\\<" nil t)) | |
179 (if (and (or (char-equal (preceding-char) ?\^M) | |
180 (char-equal (preceding-char) ?\n)) | |
181 (not (looking-at " \\|\^I"))) | |
182 ;; Diary entry that consists only of date. | |
183 (backward-char 1) | |
184 ;; Found a nonempty diary entry--make it visible and | |
185 ;; add it to the list. | |
186 (setq entry-found t) | |
187 (let ((entry-start (point)) | |
188 (date-start)) | |
189 (re-search-backward "\^M\\|\n\\|\\`") | |
190 (setq date-start (point)) | |
191 (re-search-forward "\^M\\|\n" nil t 2) | |
192 (while (looking-at " \\|\^I") | |
193 (re-search-forward "\^M\\|\n" nil t)) | |
194 (backward-char 1) | |
195 (subst-char-in-region date-start | |
196 (point) ?\^M ?\n t) | |
197 (add-to-diary-list | |
198 date (buffer-substring entry-start (point))))))) | |
199 (setq d (cdr d))) | |
200 (or entry-found | |
201 (not diary-list-include-blanks) | |
202 (setq diary-entries-list | |
203 (append diary-entries-list | |
204 (list (list date ""))))) | |
205 (setq date | |
206 (calendar-gregorian-from-absolute | |
207 (1+ (calendar-absolute-from-gregorian date)))) | |
208 (setq entry-found nil))) | |
209 (set-buffer-modified-p diary-modified)) | |
210 (set-syntax-table old-diary-syntax-table)) | |
211 (goto-char (point-min)) | |
212 (run-hooks 'nongregorian-diary-listing-hook | |
213 'list-diary-entries-hook | |
214 'diary-display-hook) | |
215 diary-entries-list)))) | |
216 | |
217 (defun include-other-diary-files () | |
218 "Include the diary entries from other diary files with those of diary-file. | |
219 This function is suitable for use just before fancy-diary-display as the | |
220 list-diary-entries-hook; it enables you to use shared diary files together | |
221 with your own. The files included are specified in the diary-file by lines of | |
222 the form | |
223 #include \"filename\" | |
224 This is recursive; that is, #include directives in diary files thus included | |
225 are obeyed. You can change the \"#include\" to some other string by | |
226 changing the variable `diary-include-string'." | |
227 (goto-char (point-min)) | |
228 (while (re-search-forward | |
229 (concat | |
230 "\\(\\`\\|\^M\\|\n\\)" | |
231 (regexp-quote diary-include-string) | |
232 " \"\\([^\"]*\\)\"") | |
233 nil t) | |
234 (let ((diary-file (substitute-in-file-name | |
235 (buffer-substring (match-beginning 2) (match-end 2)))) | |
236 (diary-list-include-blanks nil) | |
237 (list-diary-entries-hook 'include-other-diary-files) | |
238 (diary-display-hook nil)) | |
239 (if (file-exists-p diary-file) | |
240 (if (file-readable-p diary-file) | |
241 (unwind-protect | |
242 (setq diary-entries-list | |
243 (append diary-entries-list | |
244 (list-diary-entries original-date number))) | |
245 (kill-buffer (get-file-buffer diary-file))) | |
246 (beep) | |
247 (message "Can't read included diary file %s" diary-file) | |
248 (sleep-for 2)) | |
249 (beep) | |
250 (message "Can't find included diary file %s" diary-file) | |
251 (sleep-for 2)))) | |
252 (goto-char (point-min))) | |
253 | |
254 (defun simple-diary-display () | |
255 "Display the diary buffer if there are any relevant entries or holidays." | |
256 (let* ((holiday-list (if holidays-in-diary-buffer | |
257 (check-calendar-holidays original-date))) | |
258 (msg (format "No diary entries for %s %s" | |
259 (concat date-string (if holiday-list ":" "")) | |
260 (mapconcat 'identity holiday-list "; ")))) | |
261 (if (or (not diary-entries-list) | |
262 (and (not (cdr diary-entries-list)) | |
263 (string-equal (car (cdr (car diary-entries-list))) ""))) | |
778 | 264 (if (<= (length msg) (frame-width)) |
406 | 265 (message msg) |
266 (set-buffer (get-buffer-create holiday-buffer)) | |
267 (setq buffer-read-only nil) | |
268 (setq mode-line-format | |
269 (format "--------------------------%s%%-" date-string)) | |
270 (erase-buffer) | |
271 (insert (mapconcat 'identity holiday-list "\n")) | |
272 (goto-char (point-min)) | |
273 (set-buffer-modified-p nil) | |
274 (setq buffer-read-only t) | |
275 (display-buffer holiday-buffer) | |
276 (message "No diary entries for %s" date-string)) | |
277 (setq mode-line-format | |
278 (format "%%*--%sDiary %s %s%s%s%%-" | |
279 (if holiday-list "" "---------------") | |
280 (if holiday-list "for" "entries for") | |
281 date-string | |
282 (if holiday-list ": " "") | |
283 (mapconcat 'identity holiday-list "; "))) | |
284 (display-buffer (get-file-buffer d-file)) | |
285 (message "Preparing diary...done")))) | |
286 | |
287 (defun fancy-diary-display () | |
288 "Prepare a diary buffer with relevant entries in a fancy, noneditable form. | |
289 This function is provided for optional use as the `list-diary-entries-hook'." | |
290 (if (or (not diary-entries-list) | |
291 (and (not (cdr diary-entries-list)) | |
292 (string-equal (car (cdr (car diary-entries-list))) ""))) | |
293 (let* ((holiday-list (if holidays-in-diary-buffer | |
294 (check-calendar-holidays original-date))) | |
295 (msg (format "No diary entries for %s %s" | |
296 (concat date-string (if holiday-list ":" "")) | |
297 (mapconcat 'identity holiday-list "; ")))) | |
778 | 298 (if (<= (length msg) (frame-width)) |
406 | 299 (message msg) |
300 (set-buffer (get-buffer-create holiday-buffer)) | |
301 (setq buffer-read-only nil) | |
302 (setq mode-line-format | |
303 (format "--------------------------%s%%-" date-string)) | |
304 (erase-buffer) | |
305 (insert (mapconcat 'identity holiday-list "\n")) | |
306 (goto-char (point-min)) | |
307 (set-buffer-modified-p nil) | |
308 (setq buffer-read-only t) | |
309 (display-buffer holiday-buffer) | |
310 (message "No diary entries for %s" date-string))) | |
311 (save-excursion;; Turn off selective-display in the diary file's buffer. | |
312 (set-buffer (get-file-buffer (substitute-in-file-name diary-file))) | |
313 (let ((diary-modified (buffer-modified-p))) | |
314 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t) | |
315 (setq selective-display nil) | |
316 (kill-local-variable 'mode-line-format) | |
317 (set-buffer-modified-p diary-modified))) | |
318 (save-excursion;; Prepare the fancy diary buffer. | |
319 (set-buffer (get-buffer-create fancy-diary-buffer)) | |
320 (setq buffer-read-only nil) | |
321 (make-local-variable 'mode-line-format) | |
322 (setq mode-line-format "---------------------------Diary Entries%-") | |
323 (erase-buffer) | |
324 (let ((entry-list diary-entries-list) | |
325 (holiday-list) | |
326 (holiday-list-last-month 1) | |
327 (holiday-list-last-year 1) | |
328 (date (list 0 0 0))) | |
329 (while entry-list | |
330 (if (not (calendar-date-equal date (car (car entry-list)))) | |
331 (progn | |
332 (setq date (car (car entry-list))) | |
333 (and holidays-in-diary-buffer | |
334 (calendar-date-compare | |
335 (list (list holiday-list-last-month | |
336 (calendar-last-day-of-month | |
337 holiday-list-last-month | |
338 holiday-list-last-year) | |
339 holiday-list-last-year)) | |
340 (list date)) | |
341 ;; We need to get the holidays for the next 3 months. | |
342 (setq holiday-list-last-month | |
343 (extract-calendar-month date)) | |
344 (setq holiday-list-last-year | |
345 (extract-calendar-year date)) | |
346 (increment-calendar-month | |
347 holiday-list-last-month holiday-list-last-year 1) | |
348 (setq holiday-list | |
349 (let ((displayed-month holiday-list-last-month) | |
350 (displayed-year holiday-list-last-year)) | |
351 (calendar-holiday-list))) | |
352 (increment-calendar-month | |
353 holiday-list-last-month holiday-list-last-year 1)) | |
354 (let* ((date-string (calendar-date-string date)) | |
355 (date-holiday-list | |
356 (let ((h holiday-list) | |
357 (d)) | |
358 ;; Make a list of all holidays for date. | |
359 (while h | |
360 (if (calendar-date-equal date (car (car h))) | |
361 (setq d (append d (cdr (car h))))) | |
362 (setq h (cdr h))) | |
363 d))) | |
364 (insert (if (= (point) (point-min)) "" ?\n) date-string) | |
365 (if date-holiday-list (insert ": ")) | |
366 (let ((l (current-column))) | |
367 (insert (mapconcat 'identity date-holiday-list | |
368 (concat "\n" (make-string l ? ))))) | |
369 (let ((l (current-column))) | |
370 (insert ?\n (make-string l ?=) ?\n))))) | |
371 (if (< 0 (length (car (cdr (car entry-list))))) | |
372 (insert (car (cdr (car entry-list))) ?\n)) | |
373 (setq entry-list (cdr entry-list)))) | |
374 (set-buffer-modified-p nil) | |
375 (goto-char (point-min)) | |
376 (setq buffer-read-only t) | |
377 (display-buffer fancy-diary-buffer) | |
378 (message "Preparing diary...done")))) | |
379 | |
380 (defun print-diary-entries () | |
381 "Print a hard copy of the entries visible in the diary window. | |
382 The hooks given by the variable `print-diary-entries-hook' are called after | |
383 the temporary buffer of visible diary entries is prepared; it is the hooks | |
384 that do the actual printing and kill the buffer." | |
385 (interactive) | |
386 (let ((diary-buffer (get-file-buffer (substitute-in-file-name diary-file)))) | |
387 (if diary-buffer | |
388 (let ((temp-buffer (get-buffer-create "*Printable Diary Entries*"))) | |
389 (save-excursion | |
390 (set-buffer diary-buffer) | |
391 (copy-to-buffer temp-buffer (point-min) (point-max)) | |
392 (set-buffer temp-buffer) | |
393 (while (re-search-forward "\^M.*$" nil t) | |
394 (replace-match "")) | |
395 (run-hooks 'print-diary-entries-hook))) | |
396 (error "You don't have a diary buffer!")))) | |
397 | |
398 (defun add-diary-heading () | |
399 "Add a heading to the diary entries for printing. | |
400 The heading is formed from the mode line of the diary buffer. This function | |
401 is used in the default value of the variable `print-diary-entry-hooks'." | |
402 (save-excursion | |
403 (let ((heading)) | |
404 (set-buffer diary-buffer) | |
405 (setq heading mode-line-format) | |
406 (string-match "%\\*-*\\([^-].*\\)%-$" heading) | |
407 (setq heading | |
408 (substring heading (match-beginning 1) (match-end 1))) | |
409 (set-buffer temp-buffer) | |
410 (goto-char (point-min)) | |
411 (insert heading "\n" | |
412 (make-string (length heading) ?=) "\n")))) | |
413 | |
414 (defun show-all-diary-entries () | |
415 "Show all of the diary entries in the diary-file. | |
416 This function gets rid of the selective display of the diary-file so that | |
417 all entries, not just some, are visible. If there is no diary buffer, one | |
418 is created." | |
419 (interactive) | |
420 (let ((d-file (substitute-in-file-name diary-file))) | |
421 (if (and d-file (file-exists-p d-file)) | |
422 (if (file-readable-p d-file) | |
423 (save-excursion | |
424 (let ((diary-buffer (get-file-buffer d-file))) | |
425 (set-buffer (if diary-buffer | |
426 diary-buffer | |
427 (find-file-noselect d-file t))) | |
428 (let ((buffer-read-only nil) | |
429 (diary-modified (buffer-modified-p))) | |
430 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t) | |
431 (setq selective-display nil) | |
432 (make-local-variable 'mode-line-format) | |
433 (setq mode-line-format | |
434 "%*---------------------------All Diary Entries%-") | |
435 (display-buffer (current-buffer)) | |
436 (set-buffer-modified-p diary-modified)))) | |
437 (error "Your diary file is not readable!")) | |
438 (error "You don't have a diary file!")))) | |
439 | |
440 (defun diary-name-pattern (string-array &optional fullname) | |
441 "Convert an STRING-ARRAY, an array of strings to a pattern. | |
442 The pattern will match any of the strings, either entirely or abbreviated | |
443 to three characters. An abbreviated form will match with or without a period; | |
444 If the optional FULLNAME is t, abbreviations will not match, just the full | |
445 name." | |
446 (let ((pattern "")) | |
447 (calendar-for-loop i from 0 to (1- (length string-array)) do | |
448 (setq pattern | |
449 (concat | |
450 pattern | |
451 (if (string-equal pattern "") "" "\\|") | |
452 (aref string-array i) | |
453 (if fullname | |
454 "" | |
455 (concat | |
456 "\\|" | |
457 (substring (aref string-array i) 0 3) ".?"))))) | |
458 pattern)) | |
459 | |
460 (defun mark-diary-entries () | |
461 "Mark days in the calendar window that have diary entries. | |
462 Each entry in diary-file visible in the calendar window is marked. After the | |
463 entries are marked, the hooks `nongregorian-diary-marking-hook' and | |
464 `mark-diary-entries-hook' are run." | |
465 (interactive) | |
466 (setq mark-diary-entries-in-calendar t) | |
467 (let ((d-file (substitute-in-file-name diary-file))) | |
468 (if (and d-file (file-exists-p d-file)) | |
469 (if (file-readable-p d-file) | |
470 (save-excursion | |
471 (message "Marking diary entries...") | |
472 (set-buffer (find-file-noselect d-file t)) | |
473 (let ((d diary-date-forms) | |
474 (old-diary-syntax-table)) | |
475 (setq old-diary-syntax-table (syntax-table)) | |
476 (set-syntax-table diary-syntax-table) | |
477 (while d | |
478 (let* | |
479 ((date-form (if (equal (car (car d)) 'backup) | |
480 (cdr (car d)) | |
481 (car d)));; ignore 'backup directive | |
482 (dayname (diary-name-pattern calendar-day-name-array)) | |
483 (monthname | |
484 (concat | |
485 (diary-name-pattern calendar-month-name-array) | |
486 "\\|\\*")) | |
487 (month "[0-9]+\\|\\*") | |
488 (day "[0-9]+\\|\\*") | |
489 (year "[0-9]+\\|\\*") | |
490 (l (length date-form)) | |
491 (d-name-pos (- l (length (memq 'dayname date-form)))) | |
492 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos))) | |
493 (m-name-pos (- l (length (memq 'monthname date-form)))) | |
494 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos))) | |
495 (d-pos (- l (length (memq 'day date-form)))) | |
496 (d-pos (if (/= l d-pos) (+ 2 d-pos))) | |
497 (m-pos (- l (length (memq 'month date-form)))) | |
498 (m-pos (if (/= l m-pos) (+ 2 m-pos))) | |
499 (y-pos (- l (length (memq 'year date-form)))) | |
500 (y-pos (if (/= l y-pos) (+ 2 y-pos))) | |
501 (regexp | |
502 (concat | |
503 "\\(\\`\\|\^M\\|\n\\)\\(" | |
504 (mapconcat 'eval date-form "\\)\\(") | |
505 "\\)")) | |
506 (case-fold-search t)) | |
507 (goto-char (point-min)) | |
508 (while (re-search-forward regexp nil t) | |
509 (let* ((dd-name | |
510 (if d-name-pos | |
511 (buffer-substring | |
512 (match-beginning d-name-pos) | |
513 (match-end d-name-pos)))) | |
514 (mm-name | |
515 (if m-name-pos | |
516 (buffer-substring | |
517 (match-beginning m-name-pos) | |
518 (match-end m-name-pos)))) | |
519 (mm (string-to-int | |
520 (if m-pos | |
521 (buffer-substring | |
522 (match-beginning m-pos) | |
523 (match-end m-pos)) | |
524 ""))) | |
525 (dd (string-to-int | |
526 (if d-pos | |
527 (buffer-substring | |
528 (match-beginning d-pos) | |
529 (match-end d-pos)) | |
530 ""))) | |
531 (y-str (if y-pos | |
532 (buffer-substring | |
533 (match-beginning y-pos) | |
534 (match-end y-pos)))) | |
535 (yy (if (not y-str) | |
536 0 | |
537 (if (and (= (length y-str) 2) | |
538 abbreviated-calendar-year) | |
539 (let* ((current-y | |
540 (extract-calendar-year | |
541 (calendar-current-date))) | |
542 (y (+ (string-to-int y-str) | |
543 (* 100 | |
544 (/ current-y 100))))) | |
545 (if (> (- y current-y) 50) | |
546 (- y 100) | |
547 (if (> (- current-y y) 50) | |
548 (+ y 100) | |
549 y))) | |
550 (string-to-int y-str))))) | |
551 (if dd-name | |
552 (mark-calendar-days-named | |
553 (cdr (assoc (capitalize (substring dd-name 0 3)) | |
554 (calendar-make-alist | |
555 calendar-day-name-array | |
556 0 | |
557 '(lambda (x) (substring x 0 3)))))) | |
558 (if mm-name | |
559 (if (string-equal mm-name "*") | |
560 (setq mm 0) | |
561 (setq mm | |
562 (cdr (assoc | |
563 (capitalize | |
564 (substring mm-name 0 3)) | |
565 (calendar-make-alist | |
566 calendar-month-name-array | |
567 1 | |
568 '(lambda (x) (substring x 0 3))) | |
569 ))))) | |
570 (mark-calendar-date-pattern mm dd yy)))) | |
571 (setq d (cdr d)))) | |
572 (mark-sexp-diary-entries) | |
573 (run-hooks 'nongregorian-diary-marking-hook | |
574 'mark-diary-entries-hook) | |
575 (set-syntax-table old-diary-syntax-table) | |
576 (message "Marking diary entries...done"))) | |
577 (error "Your diary file is not readable!")) | |
578 (error "You don't have a diary file!")))) | |
579 | |
580 (defun mark-sexp-diary-entries () | |
581 "Mark days in the calendar window that have sexp diary entries. | |
582 Each entry in diary-file (or included files) visible in the calendar window | |
583 is marked. See the documentation for the function `list-sexp-diary-entries'." | |
584 (let* ((sexp-mark (regexp-quote sexp-diary-entry-symbol)) | |
585 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)" sexp-mark "(")) | |
586 (m) | |
587 (y) | |
588 (first-date) | |
589 (last-date)) | |
590 (save-excursion | |
591 (set-buffer calendar-buffer) | |
592 (setq m displayed-month) | |
593 (setq y displayed-year)) | |
594 (increment-calendar-month m y -1) | |
595 (setq first-date | |
596 (calendar-absolute-from-gregorian (list m 1 y))) | |
597 (increment-calendar-month m y 2) | |
598 (setq last-date | |
599 (calendar-absolute-from-gregorian | |
600 (list m (calendar-last-day-of-month m y) y))) | |
601 (goto-char (point-min)) | |
602 (while (re-search-forward s-entry nil t) | |
603 (backward-char 1) | |
604 (let ((sexp-start (point)) | |
605 (sexp) | |
606 (entry) | |
607 (entry-start) | |
608 (line-start)) | |
609 (forward-sexp) | |
610 (setq sexp (buffer-substring sexp-start (point))) | |
611 (save-excursion | |
612 (re-search-backward "\^M\\|\n\\|\\`") | |
613 (setq line-start (point))) | |
614 (forward-char 1) | |
615 (if (and (or (char-equal (preceding-char) ?\^M) | |
616 (char-equal (preceding-char) ?\n)) | |
617 (not (looking-at " \\|\^I"))) | |
618 (progn;; Diary entry consists only of the sexp | |
619 (backward-char 1) | |
620 (setq entry "")) | |
621 (setq entry-start (point)) | |
622 (re-search-forward "\^M\\|\n" nil t) | |
623 (while (looking-at " \\|\^I") | |
624 (re-search-forward "\^M\\|\n" nil t)) | |
625 (backward-char 1) | |
626 (setq entry (buffer-substring entry-start (point))) | |
627 (while (string-match "[\^M]" entry) | |
628 (aset entry (match-beginning 0) ?\n ))) | |
629 (calendar-for-loop date from first-date to last-date do | |
630 (if (diary-sexp-entry sexp entry | |
631 (calendar-gregorian-from-absolute date)) | |
632 (mark-visible-calendar-date | |
633 (calendar-gregorian-from-absolute date)))))))) | |
634 | |
635 (defun mark-included-diary-files () | |
636 "Mark the diary entries from other diary files with those of diary-file. | |
637 This function is suitable for use as the mark-diary-entries-hook; it enables | |
638 you to use shared diary files together with your own. The files included are | |
639 specified in the diary-file by lines of the form | |
640 #include \"filename\" | |
641 This is recursive; that is, #include directives in diary files thus included | |
642 are obeyed. You can change the \"#include\" to some other string by | |
643 changing the variable `diary-include-string'." | |
644 (goto-char (point-min)) | |
645 (while (re-search-forward | |
646 (concat | |
647 "\\(\\`\\|\^M\\|\n\\)" | |
648 (regexp-quote diary-include-string) | |
649 " \"\\([^\"]*\\)\"") | |
650 nil t) | |
651 (let ((diary-file (substitute-in-file-name | |
652 (buffer-substring (match-beginning 2) (match-end 2)))) | |
653 (mark-diary-entries-hook 'mark-included-diary-files)) | |
654 (if (file-exists-p diary-file) | |
655 (if (file-readable-p diary-file) | |
656 (progn | |
657 (mark-diary-entries) | |
658 (kill-buffer (get-file-buffer diary-file))) | |
659 (beep) | |
660 (message "Can't read included diary file %s" diary-file) | |
661 (sleep-for 2)) | |
662 (beep) | |
663 (message "Can't find included diary file %s" diary-file) | |
664 (sleep-for 2)))) | |
665 (goto-char (point-min))) | |
666 | |
667 (defun mark-calendar-days-named (dayname) | |
668 "Mark all dates in the calendar window that are day DAYNAME of the week. | |
669 0 means all Sundays, 1 means all Mondays, and so on." | |
670 (save-excursion | |
671 (set-buffer calendar-buffer) | |
672 (let ((prev-month displayed-month) | |
673 (prev-year displayed-year) | |
674 (succ-month displayed-month) | |
675 (succ-year displayed-year) | |
676 (last-day) | |
677 (day)) | |
678 (increment-calendar-month succ-month succ-year 1) | |
679 (increment-calendar-month prev-month prev-year -1) | |
680 (setq day (calendar-absolute-from-gregorian | |
681 (calendar-nth-named-day 1 dayname prev-month prev-year))) | |
682 (setq last-day (calendar-absolute-from-gregorian | |
683 (calendar-nth-named-day -1 dayname succ-month succ-year))) | |
684 (while (<= day last-day) | |
685 (mark-visible-calendar-date (calendar-gregorian-from-absolute day)) | |
686 (setq day (+ day 7)))))) | |
687 | |
688 (defun mark-calendar-date-pattern (month day year) | |
689 "Mark all dates in the calendar window that conform to MONTH/DAY/YEAR. | |
690 A value of 0 in any position is a wild-card." | |
691 (save-excursion | |
692 (set-buffer calendar-buffer) | |
693 (let ((m displayed-month) | |
694 (y displayed-year)) | |
695 (increment-calendar-month m y -1) | |
696 (calendar-for-loop i from 0 to 2 do | |
697 (mark-calendar-month m y month day year) | |
698 (increment-calendar-month m y 1))))) | |
699 | |
700 (defun mark-calendar-month (month year p-month p-day p-year) | |
701 "Mark dates in the MONTH/YEAR that conform to pattern P-MONTH/P_DAY/P-YEAR. | |
702 A value of 0 in any position of the pattern is a wild-card." | |
703 (if (or (and (= month p-month) | |
704 (or (= p-year 0) (= year p-year))) | |
705 (and (= p-month 0) | |
706 (or (= p-year 0) (= year p-year)))) | |
707 (if (= p-day 0) | |
708 (calendar-for-loop | |
709 i from 1 to (calendar-last-day-of-month month year) do | |
710 (mark-visible-calendar-date (list month i year))) | |
711 (mark-visible-calendar-date (list month p-day year))))) | |
712 | |
713 (defun diary-entry-compare (e1 e2) | |
714 "Returns t if E1 is earlier than E2." | |
715 (or (calendar-date-compare e1 e2) | |
716 (and (calendar-date-equal (car e1) (car e2)) | |
717 (< (diary-entry-time (car (cdr e1))) | |
718 (diary-entry-time (car (cdr e2))))))) | |
719 | |
720 (defun diary-entry-time (s) | |
721 "Time at the beginning of the string S in a military-style integer. | |
722 For example, returns 1325 for 1:25pm. Returns -9999 if no time is recognized. | |
723 The recognized forms are XXXX or X:XX or XX:XX (military time), XXam or XXpm, | |
724 and XX:XXam or XX:XXpm." | |
725 (cond ((string-match;; Military time | |
726 "^ *\\([0-9]?[0-9]\\):?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)" s) | |
727 (+ (* 100 (string-to-int | |
728 (substring s (match-beginning 1) (match-end 1)))) | |
729 (string-to-int (substring s (match-beginning 2) (match-end 2))))) | |
730 ((string-match;; Hour only XXam or XXpm | |
731 "^ *\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s) | |
732 (+ (* 100 (% (string-to-int | |
733 (substring s (match-beginning 1) (match-end 1))) | |
734 12)) | |
735 (if (string-equal "a" | |
736 (substring s (match-beginning 2) (match-end 2))) | |
737 0 1200))) | |
738 ((string-match;; Hour and minute XX:XXam or XX:XXpm | |
739 "^ *\\([0-9]?[0-9]\\):\\([0-9][0-9]\\)\\([ap]\\)m\\>" s) | |
740 (+ (* 100 (% (string-to-int | |
741 (substring s (match-beginning 1) (match-end 1))) | |
742 12)) | |
743 (string-to-int (substring s (match-beginning 2) (match-end 2))) | |
744 (if (string-equal "a" | |
745 (substring s (match-beginning 3) (match-end 3))) | |
746 0 1200))) | |
747 (t -9999)));; Unrecognizable | |
748 | |
749 (defun list-hebrew-diary-entries () | |
750 "Add any Hebrew date entries from the diary-file to diary-entries-list. | |
751 Hebrew date diary entries must be prefaced by a hebrew-diary-entry-symbol | |
752 \(normally an `H'\). The same diary-date-forms govern the style of the Hebrew | |
753 calendar entries, except that the Hebrew month names must be spelled in full. | |
754 The Hebrew months are numbered from 1 to 13 with Nisan being 1, 12 being | |
755 Adar I and 13 being Adar II; you must use `Adar I' if you want Adar of a | |
756 common Hebrew year. If a Hebrew date diary entry begins with a | |
757 diary-nonmarking-symbol the entry will appear in the diary listing, but will | |
758 not be marked in the calendar. This function is provided for use with the | |
759 nongregorian-diary-listing-hook." | |
760 (if (< 0 number) | |
761 (let ((buffer-read-only nil) | |
762 (diary-modified (buffer-modified-p)) | |
763 (gdate original-date) | |
764 (mark (regexp-quote diary-nonmarking-symbol))) | |
765 (calendar-for-loop i from 1 to number do | |
766 (let* ((d diary-date-forms) | |
767 (hdate (calendar-hebrew-from-absolute | |
768 (calendar-absolute-from-gregorian gdate))) | |
769 (month (extract-calendar-month hdate)) | |
770 (day (extract-calendar-day hdate)) | |
771 (year (extract-calendar-year hdate))) | |
772 (while d | |
773 (let* | |
774 ((date-form (if (equal (car (car d)) 'backup) | |
775 (cdr (car d)) | |
776 (car d))) | |
777 (backup (equal (car (car d)) 'backup)) | |
778 (dayname | |
779 (concat | |
780 (calendar-day-name gdate) "\\|" | |
781 (substring (calendar-day-name gdate) 0 3) ".?")) | |
782 (calendar-month-name-array | |
783 calendar-hebrew-month-name-array-leap-year) | |
784 (monthname | |
785 (concat | |
786 "\\*\\|" | |
787 (calendar-month-name month))) | |
788 (month (concat "\\*\\|0*" (int-to-string month))) | |
789 (day (concat "\\*\\|0*" (int-to-string day))) | |
790 (year | |
791 (concat | |
792 "\\*\\|0*" (int-to-string year) | |
793 (if abbreviated-calendar-year | |
794 (concat "\\|" (int-to-string (% year 100))) | |
795 ""))) | |
796 (regexp | |
797 (concat | |
798 "\\(\\`\\|\^M\\|\n\\)" mark "?" | |
799 (regexp-quote hebrew-diary-entry-symbol) | |
800 "\\(" | |
801 (mapconcat 'eval date-form "\\)\\(") | |
802 "\\)")) | |
803 (case-fold-search t)) | |
804 (goto-char (point-min)) | |
805 (while (re-search-forward regexp nil t) | |
806 (if backup (re-search-backward "\\<" nil t)) | |
807 (if (and (or (char-equal (preceding-char) ?\^M) | |
808 (char-equal (preceding-char) ?\n)) | |
809 (not (looking-at " \\|\^I"))) | |
810 ;; Diary entry that consists only of date. | |
811 (backward-char 1) | |
812 ;; Found a nonempty diary entry--make it visible and | |
813 ;; add it to the list. | |
814 (let ((entry-start (point)) | |
815 (date-start)) | |
816 (re-search-backward "\^M\\|\n\\|\\`") | |
817 (setq date-start (point)) | |
818 (re-search-forward "\^M\\|\n" nil t 2) | |
819 (while (looking-at " \\|\^I") | |
820 (re-search-forward "\^M\\|\n" nil t)) | |
821 (backward-char 1) | |
822 (subst-char-in-region date-start (point) ?\^M ?\n t) | |
823 (add-to-diary-list | |
824 gdate (buffer-substring entry-start (point))))))) | |
825 (setq d (cdr d)))) | |
826 (setq gdate | |
827 (calendar-gregorian-from-absolute | |
828 (1+ (calendar-absolute-from-gregorian gdate))))) | |
829 (set-buffer-modified-p diary-modified)) | |
830 (goto-char (point-min)))) | |
831 | |
832 (defun mark-hebrew-diary-entries () | |
833 "Mark days in the calendar window that have Hebrew date diary entries. | |
834 Each entry in diary-file (or included files) visible in the calendar window | |
835 is marked. Hebrew date entries are prefaced by a hebrew-diary-entry-symbol | |
836 \(normally an `H'\). The same diary-date-forms govern the style of the Hebrew | |
837 calendar entries, except that the Hebrew month names must be spelled in full. | |
838 The Hebrew months are numbered from 1 to 13 with Nisan being 1, 12 being | |
839 Adar I and 13 being Adar II; you must use `Adar I' if you want Adar of a | |
840 common Hebrew year. Hebrew date diary entries that begin with a | |
841 diary-nonmarking symbol will not be marked in the calendar. This function | |
842 is provided for use as part of the nongregorian-diary-marking-hook." | |
843 (let ((d diary-date-forms)) | |
844 (while d | |
845 (let* | |
846 ((date-form (if (equal (car (car d)) 'backup) | |
847 (cdr (car d)) | |
848 (car d)));; ignore 'backup directive | |
849 (dayname (diary-name-pattern calendar-day-name-array)) | |
850 (monthname | |
851 (concat | |
852 (diary-name-pattern calendar-hebrew-month-name-array-leap-year t) | |
853 "\\|\\*")) | |
854 (month "[0-9]+\\|\\*") | |
855 (day "[0-9]+\\|\\*") | |
856 (year "[0-9]+\\|\\*") | |
857 (l (length date-form)) | |
858 (d-name-pos (- l (length (memq 'dayname date-form)))) | |
859 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos))) | |
860 (m-name-pos (- l (length (memq 'monthname date-form)))) | |
861 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos))) | |
862 (d-pos (- l (length (memq 'day date-form)))) | |
863 (d-pos (if (/= l d-pos) (+ 2 d-pos))) | |
864 (m-pos (- l (length (memq 'month date-form)))) | |
865 (m-pos (if (/= l m-pos) (+ 2 m-pos))) | |
866 (y-pos (- l (length (memq 'year date-form)))) | |
867 (y-pos (if (/= l y-pos) (+ 2 y-pos))) | |
868 (regexp | |
869 (concat | |
870 "\\(\\`\\|\^M\\|\n\\)" | |
871 (regexp-quote hebrew-diary-entry-symbol) | |
872 "\\(" | |
873 (mapconcat 'eval date-form "\\)\\(") | |
874 "\\)")) | |
875 (case-fold-search t)) | |
876 (goto-char (point-min)) | |
877 (while (re-search-forward regexp nil t) | |
878 (let* ((dd-name | |
879 (if d-name-pos | |
880 (buffer-substring | |
881 (match-beginning d-name-pos) | |
882 (match-end d-name-pos)))) | |
883 (mm-name | |
884 (if m-name-pos | |
885 (buffer-substring | |
886 (match-beginning m-name-pos) | |
887 (match-end m-name-pos)))) | |
888 (mm (string-to-int | |
889 (if m-pos | |
890 (buffer-substring | |
891 (match-beginning m-pos) | |
892 (match-end m-pos)) | |
893 ""))) | |
894 (dd (string-to-int | |
895 (if d-pos | |
896 (buffer-substring | |
897 (match-beginning d-pos) | |
898 (match-end d-pos)) | |
899 ""))) | |
900 (y-str (if y-pos | |
901 (buffer-substring | |
902 (match-beginning y-pos) | |
903 (match-end y-pos)))) | |
904 (yy (if (not y-str) | |
905 0 | |
906 (if (and (= (length y-str) 2) | |
907 abbreviated-calendar-year) | |
908 (let* ((current-y | |
909 (extract-calendar-year | |
910 (calendar-hebrew-from-absolute | |
911 (calendar-absolute-from-gregorian | |
912 (calendar-current-date))))) | |
913 (y (+ (string-to-int y-str) | |
914 (* 100 (/ current-y 100))))) | |
915 (if (> (- y current-y) 50) | |
916 (- y 100) | |
917 (if (> (- current-y y) 50) | |
918 (+ y 100) | |
919 y))) | |
920 (string-to-int y-str))))) | |
921 (if dd-name | |
922 (mark-calendar-days-named | |
923 (cdr (assoc (capitalize (substring dd-name 0 3)) | |
924 (calendar-make-alist | |
925 calendar-day-name-array | |
926 0 | |
927 '(lambda (x) (substring x 0 3)))))) | |
928 (if mm-name | |
929 (if (string-equal mm-name "*") | |
930 (setq mm 0) | |
931 (setq | |
932 mm | |
933 (cdr | |
934 (assoc | |
935 (capitalize mm-name) | |
936 (calendar-make-alist | |
937 calendar-hebrew-month-name-array-leap-year)))))) | |
938 (mark-hebrew-calendar-date-pattern mm dd yy))))) | |
939 (setq d (cdr d))))) | |
940 | |
941 (defun mark-hebrew-calendar-date-pattern (month day year) | |
942 "Mark all dates in the calendar window that conform to the Hebrew date | |
943 MONTH/DAY/YEAR. A value of 0 in any position is a wild-card." | |
944 (save-excursion | |
945 (set-buffer calendar-buffer) | |
946 (if (and (/= 0 month) (/= 0 day)) | |
947 (if (/= 0 year) | |
948 ;; Fully specified Hebrew date. | |
949 (let ((date (calendar-gregorian-from-absolute | |
950 (calendar-absolute-from-hebrew | |
951 (list month day year))))) | |
952 (if (calendar-date-is-visible-p date) | |
953 (mark-visible-calendar-date date))) | |
954 ;; Month and day in any year--this taken from the holiday stuff. | |
955 (if (memq displayed-month;; This test is only to speed things up a | |
956 (list ;; bit; it works fine without the test too. | |
957 (if (< 11 month) (- month 11) (+ month 1)) | |
958 (if (< 10 month) (- month 10) (+ month 2)) | |
959 (if (< 9 month) (- month 9) (+ month 3)) | |
960 (if (< 8 month) (- month 8) (+ month 4)) | |
961 (if (< 7 month) (- month 7) (+ month 5)))) | |
962 (let ((m1 displayed-month) | |
963 (y1 displayed-year) | |
964 (m2 displayed-month) | |
965 (y2 displayed-year) | |
966 (year)) | |
967 (increment-calendar-month m1 y1 -1) | |
968 (increment-calendar-month m2 y2 1) | |
969 (let* ((start-date (calendar-absolute-from-gregorian | |
970 (list m1 1 y1))) | |
971 (end-date (calendar-absolute-from-gregorian | |
972 (list m2 | |
973 (calendar-last-day-of-month m2 y2) | |
974 y2))) | |
975 (hebrew-start | |
976 (calendar-hebrew-from-absolute start-date)) | |
977 (hebrew-end (calendar-hebrew-from-absolute end-date)) | |
978 (hebrew-y1 (extract-calendar-year hebrew-start)) | |
979 (hebrew-y2 (extract-calendar-year hebrew-end))) | |
980 (setq year (if (< 6 month) hebrew-y2 hebrew-y1)) | |
981 (let ((date (calendar-gregorian-from-absolute | |
982 (calendar-absolute-from-hebrew | |
983 (list month day year))))) | |
984 (if (calendar-date-is-visible-p date) | |
985 (mark-visible-calendar-date date))))))) | |
986 ;; Not one of the simple cases--check all visible dates for match. | |
987 ;; Actually, the following code takes care of ALL of the cases, but | |
988 ;; it's much too slow to be used for the simple (common) cases. | |
989 (let ((m displayed-month) | |
990 (y displayed-year) | |
991 (first-date) | |
992 (last-date)) | |
993 (increment-calendar-month m y -1) | |
994 (setq first-date | |
995 (calendar-absolute-from-gregorian | |
996 (list m 1 y))) | |
997 (increment-calendar-month m y 2) | |
998 (setq last-date | |
999 (calendar-absolute-from-gregorian | |
1000 (list m (calendar-last-day-of-month m y) y))) | |
1001 (calendar-for-loop date from first-date to last-date do | |
1002 (let* ((h-date (calendar-hebrew-from-absolute date)) | |
1003 (h-month (extract-calendar-month h-date)) | |
1004 (h-day (extract-calendar-day h-date)) | |
1005 (h-year (extract-calendar-year h-date))) | |
1006 (and (or (zerop month) | |
1007 (= month h-month)) | |
1008 (or (zerop day) | |
1009 (= day h-day)) | |
1010 (or (zerop year) | |
1011 (= year h-year)) | |
1012 (mark-visible-calendar-date | |
1013 (calendar-gregorian-from-absolute date))))))))) | |
1014 | |
1015 (defun list-sexp-diary-entries (date) | |
1016 "Add any sexp entries for DATE from the diary-file to diary-entries-list | |
1017 and make them visible in the diary file. Returns t if any entries were found. | |
1018 | |
1019 Sexp diary entries must be prefaced by a sexp-diary-entry-symbol (normally | |
1020 `%%'). The form of a sexp diary entry is | |
1021 | |
1022 %%(SEXP) ENTRY | |
1023 | |
1024 Both ENTRY and DATE are globally available when the SEXP is evaluated. If the | |
1025 SEXP yields the value nil, the diary entry does not apply. If it yields a | |
1026 non-nil value, ENTRY will be taken to apply to DATE; if the non-nil value is a | |
1027 string, that string will be the diary entry in the fancy diary display. | |
1028 | |
1029 For example, the following diary entry will apply to the 21st of the month | |
1030 if it is a weekday and the Friday before if the 21st is on a weekend: | |
1031 | |
1032 &%%(let ((dayname (calendar-day-of-week date)) | |
1033 (day (extract-calendar-day date))) | |
1034 (or | |
1035 (and (= day 21) (memq dayname '(1 2 3 4 5))) | |
1036 (and (memq day '(19 20)) (= dayname 5))) | |
1037 ) UIUC pay checks deposited | |
1038 | |
1039 A number of built-in functions are available for this type of diary entry: | |
1040 | |
1041 %%(diary-float MONTH DAYNAME N) text | |
1042 Entry will appear on the Nth DAYNAME of MONTH. | |
1043 (DAYNAME=0 means Sunday, 1 means Monday, and so on; | |
1044 if N is negative it counts backward from the end of | |
1045 the month. MONTH can be a list of months, a single | |
1046 month, or t to specify all months. | |
1047 | |
1048 %%(diary-block M1 D1 Y1 M2 D2 Y2) text | |
1049 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2, | |
1050 inclusive. (If `european-calendar-style' is t, the | |
1051 order of the parameters should be changed to D1, M1, Y1, | |
1052 D2, M2, Y2.) | |
1053 | |
1054 %%(diary-anniversary MONTH DAY YEAR) text | |
1055 Entry will appear on anniversary dates of MONTH DAY, YEAR. | |
1056 (If `european-calendar-style' is t, the order of the | |
1057 parameters should be changed to DAY, MONTH, YEAR.) Text | |
1058 can contain %d or %d%s; %d will be replaced by the number | |
1059 of years since the MONTH DAY, YEAR and %s will be replaced | |
1060 by the ordinal ending of that number (that is, `st', `nd', | |
1061 `rd' or `th', as appropriate. The anniversary of February | |
1062 29 is considered to be March 1 in a non-leap year. | |
1063 | |
1064 %%(diary-cyclic N MONTH DAY YEAR) text | |
1065 Entry will appear every N days, starting MONTH DAY, YEAR. | |
1066 (If `european-calendar-style' is t, the order of the | |
1067 parameters should be changed to N, DAY, MONTH, YEAR.) Text | |
1068 can contain %d or %d%s; %d will be replaced by the number | |
1069 of repetitions since the MONTH DAY, YEAR and %s will | |
1070 be replaced by the ordinal ending of that number (that is, | |
1071 `st', `nd', `rd' or `th', as appropriate. | |
1072 | |
1073 %%(diary-day-of-year) | |
1074 Diary entries giving the day of the year and the number of | |
1075 days remaining in the year will be made every day. Note | |
1076 that since there is no text, it makes sense only if the | |
1077 fancy diary display is used. | |
1078 | |
1079 %%(diary-iso-date) | |
1080 Diary entries giving the corresponding ISO commercial date | |
1081 will be made every day. Note that since there is no text, | |
1082 it makes sense only if the fancy diary display is used. | |
1083 | |
1084 %%(diary-french-date) | |
1085 Diary entries giving the corresponding French Revolutionary | |
1086 date will be made every day. Note that since there is no | |
1087 text, it makes sense only if the fancy diary display is used. | |
1088 | |
1089 %%(diary-islamic-date) | |
1090 Diary entries giving the corresponding Islamic date will be | |
1091 made every day. Note that since there is no text, it | |
1092 makes sense only if the fancy diary display is used. | |
1093 | |
1094 %%(diary-hebrew-date) | |
1095 Diary entries giving the corresponding Hebrew date will be | |
1096 made every day. Note that since there is no text, it | |
1097 makes sense only if the fancy diary display is used. | |
1098 | |
1099 %%(diary-yahrzeit MONTH DAY YEAR) text | |
1100 Text is assumed to be the name of the person; the date is | |
1101 the date of death on the *civil* calendar. The diary entry | |
1102 will appear on the proper Hebrew-date anniversary and on the | |
1103 day before. (If `european-calendar-style' is t, the order | |
1104 of the parameters should be changed to DAY, MONTH, YEAR.) | |
1105 | |
1106 %%(diary-rosh-hodesh) | |
1107 Diary entries will be made on the dates of Rosh Hodesh on | |
1108 the Hebrew calendar. Note that since there is no text, it | |
1109 makes sense only if the fancy diary display is used. | |
1110 | |
1111 %%(diary-parasha) | |
1112 Diary entries giving the weekly parasha will be made on | |
1113 every Saturday. Note that since there is no text, it | |
1114 makes sense only if the fancy diary display is used. | |
1115 | |
1116 %%(diary-omer) | |
1117 Diary entries giving the omer count will be made every day | |
1118 from Passover to Shavuoth. Note that since there is no text, | |
1119 it makes sense only if the fancy diary display is used. | |
1120 | |
1121 Marking these entries is *extremely* time consuming, so these entries are | |
1122 best if they are nonmarking." | |
1123 (let* ((mark (regexp-quote diary-nonmarking-symbol)) | |
1124 (sexp-mark (regexp-quote sexp-diary-entry-symbol)) | |
1125 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)" mark "?" sexp-mark "(")) | |
1126 (entry-found)) | |
1127 (goto-char (point-min)) | |
1128 (while (re-search-forward s-entry nil t) | |
1129 (backward-char 1) | |
1130 (let ((sexp-start (point)) | |
1131 (sexp) | |
1132 (entry) | |
1133 (entry-start) | |
1134 (line-start)) | |
1135 (forward-sexp) | |
1136 (setq sexp (buffer-substring sexp-start (point))) | |
1137 (save-excursion | |
1138 (re-search-backward "\^M\\|\n\\|\\`") | |
1139 (setq line-start (point))) | |
1140 (forward-char 1) | |
1141 (if (and (or (char-equal (preceding-char) ?\^M) | |
1142 (char-equal (preceding-char) ?\n)) | |
1143 (not (looking-at " \\|\^I"))) | |
1144 (progn;; Diary entry consists only of the sexp | |
1145 (backward-char 1) | |
1146 (setq entry "")) | |
1147 (setq entry-start (point)) | |
1148 (re-search-forward "\^M\\|\n" nil t) | |
1149 (while (looking-at " \\|\^I") | |
1150 (re-search-forward "\^M\\|\n" nil t)) | |
1151 (backward-char 1) | |
1152 (setq entry (buffer-substring entry-start (point))) | |
1153 (while (string-match "[\^M]" entry) | |
1154 (aset entry (match-beginning 0) ?\n ))) | |
1155 (let ((diary-entry (diary-sexp-entry sexp entry date))) | |
1156 (if diary-entry | |
1157 (subst-char-in-region line-start (point) ?\^M ?\n t)) | |
1158 (add-to-diary-list date diary-entry) | |
1159 (setq entry-found (or entry-found diary-entry))))) | |
1160 entry-found)) | |
1161 | |
1162 (defun diary-sexp-entry (sexp entry date) | |
1163 "Process a SEXP diary ENTRY for DATE." | |
1164 (let ((result (condition-case nil | |
1165 (eval (car (read-from-string sexp))) | |
1166 (error | |
1167 (beep) | |
1168 (message "Bad sexp at line %d in %s: %s" | |
1169 (save-excursion | |
1170 (save-restriction | |
1171 (narrow-to-region 1 (point)) | |
1172 (goto-char (point-min)) | |
1173 (let ((lines 1)) | |
1174 (while (re-search-forward "\n\\|\^M" nil t) | |
1175 (setq lines (1+ lines))) | |
1176 lines))) | |
1177 diary-file sexp) | |
1178 (sleep-for 2))))) | |
1179 (if (stringp result) | |
1180 result | |
1181 (if result | |
1182 entry | |
1183 nil)))) | |
1184 | |
1185 (defun diary-block (m1 d1 y1 m2 d2 y2) | |
1186 "Block diary entry--entry applies if date is between two dates. Order of | |
1187 the parameters is M1, D1, Y1, M2, D2, Y2 `european-calendar-style' is nil, and | |
1188 D1, M1, Y1, D2, M2, Y2 if `european-calendar-style' is t." | |
1189 (let ((date1 (calendar-absolute-from-gregorian | |
1190 (if european-calendar-style | |
1191 (list d1 m1 y1) | |
1192 (list m1 d1 y1)))) | |
1193 (date2 (calendar-absolute-from-gregorian | |
1194 (if european-calendar-style | |
1195 (list d2 m2 y2) | |
1196 (list m2 d2 y2)))) | |
1197 (d (calendar-absolute-from-gregorian date))) | |
1198 (if (and (<= date1 d) (<= d date2)) | |
1199 entry))) | |
1200 | |
1201 (defun diary-float (month dayname n) | |
1202 "Floating diary entry--entry applies if date is the nth dayname of month. | |
1203 Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant | |
1204 t, or an integer. The constant t means all months. If N is negative, count | |
1205 backward from the end of the month." | |
1206 (let ((m (extract-calendar-month date)) | |
1207 (y (extract-calendar-year date))) | |
1208 (if (and | |
1209 (or (and (listp month) (memq m month)) | |
1210 (equal m month) | |
1211 (eq month t)) | |
1212 (calendar-date-equal date (calendar-nth-named-day n dayname m y))) | |
1213 entry))) | |
1214 | |
1215 (defun diary-anniversary (month day year) | |
1216 "Anniversary diary entry--entry applies if date is the anniversary of | |
1217 MONTH, DAY, YEAR if `european-calendar-style' is nil, and DAY, MONTH, YEAR | |
1218 if `european-calendar-style' is t. Diary entry can contain `%d' or `%d%s'; the | |
1219 %d will be replaced by the number of years since the MONTH DAY, YEAR and the | |
1220 %s will be replaced by the ordinal ending of that number (that is, `st', `nd', | |
1221 `rd' or `th', as appropriate. The anniversary of February 29 is considered | |
1222 to be March 1 in non-leap years." | |
1223 (let* ((d (if european-calendar-style | |
1224 month | |
1225 day)) | |
1226 (m (if european-calendar-style | |
1227 day | |
1228 month)) | |
1229 (y (extract-calendar-year date)) | |
1230 (diff (- y year))) | |
1231 (if (and (= m 2) (= d 29) (not (calendar-leap-year-p y))) | |
1232 (setq m 3 | |
1233 d 1)) | |
1234 (if (and (> diff 0) (calendar-date-equal (list m d y) date)) | |
1235 (format entry diff (diary-ordinal-suffix diff))))) | |
1236 | |
1237 (defun diary-cyclic (n month day year) | |
1238 "Cycle diary entry--entry applies every N days starting at MONTH, DAY, YEAR. | |
1239 If `european-calendar-style' is t, parameters are N, DAY, MONTH, YEAR. | |
1240 ENTRY can contain `%d' or `%d%s'; the %d will be replaced by the number of | |
1241 years since the MONTH DAY, YEAR and the %s will be replaced by the ordinal | |
1242 ending of that number (that is, `st', `nd', `rd' or `th', as appropriate." | |
1243 (let* ((d (if european-calendar-style | |
1244 month | |
1245 day)) | |
1246 (m (if european-calendar-style | |
1247 day | |
1248 month)) | |
1249 (diff (- (calendar-absolute-from-gregorian date) | |
1250 (calendar-absolute-from-gregorian | |
1251 (list m d year)))) | |
1252 (cycle (/ diff n))) | |
1253 (if (and (>= diff 0) (zerop (% diff n))) | |
1254 (format entry cycle (diary-ordinal-suffix cycle))))) | |
1255 | |
1256 (defun diary-ordinal-suffix (n) | |
1257 "Ordinal suffix for N. (That is, `st', `nd', `rd', or `th', as appropriate.)" | |
732 | 1258 (if (or (memq (% n 100) '(11 12 13)) |
1259 (< 3 (% n 10))) | |
406 | 1260 "th" |
1261 (aref ["th" "st" "nd" "rd"] (% n 10)))) | |
1262 | |
1263 (defun diary-day-of-year () | |
1264 "Day of year and number of days remaining in the year of date diary entry." | |
1265 (let* ((year (extract-calendar-year date)) | |
1266 (day (calendar-day-number date)) | |
1267 (days-remaining (- (calendar-day-number (list 12 31 year)) day))) | |
1268 (format "Day %d of %d; %d day%s remaining in the year" | |
1269 day year days-remaining (if (= days-remaining 1) "" "s")))) | |
1270 | |
1271 (defun diary-iso-date () | |
1272 "ISO calendar equivalent of date diary entry." | |
1273 (let ((day (% (calendar-absolute-from-gregorian date) 7)) | |
1274 (iso-date (calendar-iso-from-absolute | |
1275 (calendar-absolute-from-gregorian date)))) | |
1276 (format "ISO date: Day %s of week %d of %d." | |
1277 (if (zerop day) 7 day) | |
1278 (extract-calendar-month iso-date) | |
1279 (extract-calendar-year iso-date)))) | |
1280 | |
1281 (defun diary-islamic-date () | |
1282 "Islamic calendar equivalent of date diary entry." | |
1283 (let* ((calendar-date-display-form | |
1284 (if european-calendar-style | |
1285 '(day " " monthname " " year) | |
1286 '(monthname " " day ", " year))) | |
1287 (i-date (calendar-islamic-from-absolute | |
1288 (calendar-absolute-from-gregorian date))) | |
1289 (calendar-month-name-array calendar-islamic-month-name-array)) | |
1290 (if (>= (extract-calendar-year i-date) 1) | |
1291 (format "Islamic date: %s" (calendar-date-string i-date))))) | |
1292 | |
1293 (defun diary-hebrew-date () | |
1294 "Hebrew calendar equivalent of date diary entry." | |
1295 (let* ((calendar-date-display-form | |
1296 (if european-calendar-style | |
1297 '(day " " monthname " " year) | |
1298 '(monthname " " day ", " year))) | |
1299 (h-date (calendar-hebrew-from-absolute | |
1300 (calendar-absolute-from-gregorian date))) | |
1301 (calendar-month-name-array | |
1302 (if (hebrew-calendar-leap-year-p | |
1303 (extract-calendar-year h-date)) | |
1304 calendar-hebrew-month-name-array-leap-year | |
1305 calendar-hebrew-month-name-array-common-year))) | |
1306 (format "Hebrew date: %s" (calendar-date-string h-date)))) | |
1307 | |
1308 (defun diary-french-date () | |
1309 "French calendar equivalent of date diary entry." | |
1310 (let* ((french-date (calendar-french-from-absolute | |
1311 (calendar-absolute-from-gregorian date))) | |
1312 (y (extract-calendar-year french-date)) | |
1313 (m (extract-calendar-month french-date)) | |
1314 (d (extract-calendar-day french-date))) | |
1315 (if (> y 0) | |
1316 (if (= m 13) | |
1317 (format "Jour %s de l'Annee %d de la Revolution" | |
1318 (aref french-calendar-special-days-array (1- d)) | |
1319 y) | |
1320 (format "Decade %s, %s de %s de l'Annee %d de la Revolution" | |
1321 (make-string (1+ (/ (1- d) 10)) ?I) | |
1322 (aref french-calendar-day-name-array (% (1- d) 10)) | |
1323 (aref french-calendar-month-name-array (1- m)) | |
1324 y))))) | |
1325 | |
1326 (defun diary-omer () | |
1327 "Omer count diary entry--entry applies if date is within 50 days after | |
1328 Passover." | |
1329 (let* ((passover | |
1330 (calendar-absolute-from-hebrew | |
1331 (list 1 15 (+ (extract-calendar-year date) 3760)))) | |
1332 (omer (- (calendar-absolute-from-gregorian date) passover)) | |
1333 (week (/ omer 7)) | |
1334 (day (% omer 7))) | |
1335 (if (and (> omer 0) (< omer 50)) | |
1336 (format "Day %d%s of the omer (until sunset)" | |
1337 omer | |
1338 (if (zerop week) | |
1339 "" | |
1340 (format ", that is, %d week%s%s" | |
1341 week | |
1342 (if (= week 1) "" "s") | |
1343 (if (zerop day) | |
1344 "" | |
1345 (format " and %d day%s" | |
1346 day (if (= day 1) "" "s"))))))))) | |
1347 | |
1348 (defun diary-yahrzeit (death-month death-day death-year) | |
1349 "Yahrzeit diary entry--entry applies if date is yahrzeit or the day before. | |
1350 Parameters are DEATH-MONTH, DEATH-DAY, DEATH-YEAR; the diary entry is assumed | |
1351 to be the name of the person. Date of death is on the *civil* calendar; | |
1352 although the date of death is specified by the civil calendar, the proper | |
1353 Hebrew calendar yahrzeit is determined. If european-calendar-style is t, the | |
1354 order of the parameters is changed to DEATH-DAY, DEATH-MONTH, DEATH-YEAR." | |
1355 (let* ((h-date (calendar-hebrew-from-absolute | |
1356 (calendar-absolute-from-gregorian | |
1357 (if european-calendar-style | |
1358 (list death-day death-month death-year) | |
1359 (list death-month death-day death-year))))) | |
1360 (h-month (extract-calendar-month h-date)) | |
1361 (h-day (extract-calendar-day h-date)) | |
1362 (h-year (extract-calendar-year h-date)) | |
1363 (d (calendar-absolute-from-gregorian date)) | |
1364 (yr (extract-calendar-year (calendar-hebrew-from-absolute d))) | |
1365 (diff (- yr h-year)) | |
1366 (y (hebrew-calendar-yahrzeit h-date yr))) | |
1367 (if (and (> diff 0) (or (= y d) (= y (1+ d)))) | |
1368 (format "Yahrzeit of %s%s: %d%s anniversary" | |
1369 entry | |
1370 (if (= y d) "" " (evening)") | |
1371 diff | |
1372 (cond ((= (% diff 10) 1) "st") | |
1373 ((= (% diff 10) 2) "nd") | |
1374 ((= (% diff 10) 3) "rd") | |
1375 (t "th")))))) | |
1376 | |
1377 (defun diary-rosh-hodesh () | |
732 | 1378 "Rosh Hodesh diary entry--entry applies if date is Rosh Hodesh, the day |
1379 before, or the Saturday before." | |
406 | 1380 (let* ((d (calendar-absolute-from-gregorian date)) |
1381 (h-date (calendar-hebrew-from-absolute d)) | |
1382 (h-month (extract-calendar-month h-date)) | |
1383 (h-day (extract-calendar-day h-date)) | |
1384 (h-year (extract-calendar-year h-date)) | |
1385 (leap-year (hebrew-calendar-leap-year-p h-year)) | |
1386 (last-day (hebrew-calendar-last-day-of-month h-month h-year)) | |
1387 (h-month-names | |
1388 (if leap-year | |
1389 calendar-hebrew-month-name-array-leap-year | |
1390 calendar-hebrew-month-name-array-common-year)) | |
1391 (this-month (aref h-month-names (1- h-month))) | |
1392 (h-yesterday (extract-calendar-day | |
1393 (calendar-hebrew-from-absolute (1- d))))) | |
1394 (if (or (= h-day 30) (and (= h-day 1) (/= h-month 7))) | |
1395 (format | |
1396 "Rosh Hodesh %s" | |
1397 (if (= h-day 30) | |
1398 (format | |
1399 "%s (first day)" | |
1400 ;; next month must be in the same year since this | |
1401 ;; month can't be the last month of the year since | |
1402 ;; it has 30 days | |
1403 (aref h-month-names h-month)) | |
1404 (if (= h-yesterday 30) | |
1405 (format "%s (second day)" this-month) | |
1406 this-month))) | |
1407 (if (= (mod d 7) 6);; Saturday--check for Shabbat Mevarhim | |
1408 (cond ((and (> h-day 22) (/= h-month 6) (= 29 last-day)) | |
1409 (format "Mevarhim Rosh Hodesh %s (%s)" | |
1410 (aref h-month-names | |
1411 (if (= h-month | |
1412 (hebrew-calendar-last-month-of-year | |
1413 h-year)) | |
1414 0 h-month)) | |
1415 (aref calendar-day-name-array (- 29 h-day)))) | |
1416 ((and (< h-day 30) (> h-day 22) (= 30 last-day)) | |
1417 (format "Mevarhim Rosh Hodesh %s (%s-%s)" | |
1418 (aref h-month-names h-month) | |
732 | 1419 (if (= h-day 29) |
1420 "tomorrow" | |
1421 (aref calendar-day-name-array (- 29 h-day))) | |
406 | 1422 (aref calendar-day-name-array |
732 | 1423 (mod (- 30 h-day) 7))))) |
1424 (if (and (= h-day 29) (/= h-month 6)) | |
1425 (format "Erev Rosh Hodesh %s" | |
1426 (aref h-month-names | |
1427 (if (= h-month | |
1428 (hebrew-calendar-last-month-of-year | |
1429 h-year)) | |
1430 0 h-month)))))))) | |
406 | 1431 |
1432 (defun diary-parasha () | |
1433 "Parasha diary entry--entry applies if date is a Saturday." | |
1434 (let ((d (calendar-absolute-from-gregorian date))) | |
1435 (if (= (% d 7) 6);; Saturday | |
1436 (let* | |
1437 ((h-year (extract-calendar-year | |
1438 (calendar-hebrew-from-absolute d))) | |
1439 (rosh-hashannah | |
1440 (calendar-absolute-from-hebrew (list 7 1 h-year))) | |
1441 (passover | |
1442 (calendar-absolute-from-hebrew (list 1 15 h-year))) | |
1443 (rosh-hashannah-day | |
1444 (aref calendar-day-name-array (% rosh-hashannah 7))) | |
1445 (passover-day | |
1446 (aref calendar-day-name-array (% passover 7))) | |
1447 (long-h (hebrew-calendar-long-heshvan-p h-year)) | |
1448 (short-k (hebrew-calendar-short-kislev-p h-year)) | |
1449 (type (cond ((and long-h (not short-k)) "complete") | |
1450 ((and (not long-h) short-k) "incomplete") | |
1451 (t "regular"))) | |
1452 (year-format | |
1453 (symbol-value | |
1454 (intern (format "hebrew-calendar-year-%s-%s-%s";; keviah | |
1455 rosh-hashannah-day type passover-day)))) | |
1456 (first-saturday;; of Hebrew year | |
1457 (calendar-dayname-on-or-before 6 (+ 6 rosh-hashannah))) | |
1458 (saturday;; which Saturday of the Hebrew year | |
1459 (/ (- d first-saturday) 7)) | |
1460 (parasha (aref year-format saturday))) | |
1461 (if parasha | |
1462 (format | |
1463 "Parashat %s" | |
1464 (if (listp parasha);; Israel differs from diaspora | |
1465 (if (car parasha) | |
1466 (format "%s (diaspora), %s (Israel)" | |
1467 (hebrew-calendar-parasha-name (car parasha)) | |
1468 (hebrew-calendar-parasha-name (cdr parasha))) | |
1469 (format "%s (Israel)" | |
1470 (hebrew-calendar-parasha-name (cdr parasha)))) | |
1471 (hebrew-calendar-parasha-name parasha)))))))) | |
1472 | |
1473 (defun add-to-diary-list (date string) | |
1474 "Add the entry (DATE STRING) to the diary-entries-list. | |
1475 Do nothing if DATE or STRING is nil." | |
1476 (and date string | |
1477 (setq diary-entries-list | |
1478 (append diary-entries-list (list (list date string)))))) | |
1479 | |
1480 (defconst hebrew-calendar-parashiot-names | |
1481 ["Bereshith" "Noah" "Lech L'cha" "Vayera" "Hayei Sarah" "Toledoth" | |
1482 "Vayetze" "Vayishlah" "Vayeshev" "Mikketz" "Vayiggash" "Vayhi" | |
1483 "Shemoth" "Vaera" "Bo" "Beshallah" "Yithro" "Mishpatim" | |
1484 "Terumah" "Tetzavveh" "Ki Tissa" "Vayakhel" "Pekudei" "Vayikra" | |
1485 "Tzav" "Shemini" "Tazria" "Metzora" "Aharei Moth" "Kedoshim" | |
1486 "Emor" "Behar" "Behukkotai" "Bemidbar" "Naso" "Behaalot'cha" | |
1487 "Shelah L'cha" "Korah" "Hukkath" "Balak" "Pinhas" "Mattoth" | |
1488 "Masei" "Devarim" "Vaethanan" "Ekev" "Reeh" "Shofetim" | |
1489 "Ki Tetze" "Ki Tavo" "Nitzavim" "Vayelech" "Haazinu"] | |
1490 "The names of the parashiot in the Torah.") | |
1491 | |
1492 ;; The seven ordinary year types (keviot) | |
1493 | |
1494 (defconst hebrew-calendar-year-Saturday-incomplete-Sunday | |
1495 [nil 52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22] | |
1496 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42] | |
1497 43 44 45 46 47 48 49 50] | |
1498 "The structure of the parashiot in a Hebrew year that starts on Saturday, | |
1499 is `incomplete' (Heshvan and Kislev each have 29 days), and has Passover | |
1500 start on Sunday.") | |
1501 | |
1502 (defconst hebrew-calendar-year-Saturday-complete-Tuesday | |
1503 [nil 52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22] | |
1504 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42] | |
1505 43 44 45 46 47 48 49 [50 51]] | |
1506 "The structure of the parashiot in a Hebrew year that starts on Saturday, | |
1507 is `complete' (Heshvan and Kislev each have 30 days), and has Passover | |
1508 start on Tuesday.") | |
1509 | |
1510 (defconst hebrew-calendar-year-Monday-incomplete-Tuesday | |
1511 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22] | |
1512 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42] | |
1513 43 44 45 46 47 48 49 [50 51]] | |
1514 "The structure of the parashiot in a Hebrew year that starts on Monday, | |
1515 is `incomplete' (Heshvan and Kislev each have 29 days), and has Passover | |
1516 start on Tuesday.") | |
1517 | |
1518 (defconst hebrew-calendar-year-Monday-complete-Thursday | |
1519 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22] | |
1520 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 (nil . 34) (34.35) (35.36) | |
1521 (36.37) (37.38) ([38 39].39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]] | |
1522 "The structure of the parashiot in a Hebrew year that starts on Monday, | |
1523 is `complete' (Heshvan and Kislev each have 30 days), and has Passover | |
1524 start on Thursday.") | |
1525 | |
1526 (defconst hebrew-calendar-year-Tuesday-regular-Thursday | |
1527 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22] | |
1528 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 (nil . 34) (34.35) (35.36) | |
1529 (36.37) (37.38) ([38 39].39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]] | |
1530 "The structure of the parashiot in a Hebrew year that starts on Tuesday, | |
1531 is `regular' (Heshvan has 29 days and Kislev has 30 days), and has Passover | |
1532 start on Thursday.") | |
1533 | |
1534 (defconst hebrew-calendar-year-Thursday-regular-Saturday | |
1535 [52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21 22] | |
1536 23 24 nil (nil . 25) (25.[26 27]) ([26 27].[28 29]) ([28 29].30) (30.31) | |
1537 ([31 32].32) 33 34 35 36 37 38 39 40 [41 42] | |
1538 43 44 45 46 47 48 49 50] | |
1539 "The structure of the parashiot in a Hebrew year that starts on Thursday, | |
1540 is `regular' (Heshvan has 29 days and Kislev has 30 days), and has Passover | |
1541 start on Saturday.") | |
1542 | |
1543 (defconst hebrew-calendar-year-Thursday-complete-Sunday | |
1544 [52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1545 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42] | |
1546 43 44 45 46 47 48 49 50] | |
1547 "The structure of the parashiot in a Hebrew year that starts on Thursday, | |
1548 is `complete' (Heshvan and Kislev each have 30 days), and has Passover | |
1549 start on Sunday.") | |
1550 | |
1551 ;; The seven leap year types (keviot) | |
1552 | |
1553 (defconst hebrew-calendar-year-Saturday-incomplete-Tuesday | |
1554 [nil 52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1555 23 24 25 26 27 nil 28 29 30 31 32 33 34 35 36 37 38 39 40 [41 42] | |
1556 43 44 45 46 47 48 49 [50 51]] | |
1557 "The structure of the parashiot in a Hebrew year that starts on Saturday, | |
1558 is `incomplete' (Heshvan and Kislev each have 29 days), and has Passover | |
1559 start on Tuesday.") | |
1560 | |
1561 (defconst hebrew-calendar-year-Saturday-complete-Thursday | |
1562 [nil 52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1563 23 24 25 26 27 nil 28 29 30 31 32 33 (nil . 34) (34.35) (35.36) (36.37) | |
1564 (37.38) ([38 39].39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]] | |
1565 "The structure of the parashiot in a Hebrew year that starts on Saturday, | |
1566 is `complete' (Heshvan and Kislev each have 30 days), and has Passover | |
1567 start on Thursday.") | |
1568 | |
1569 (defconst hebrew-calendar-year-Monday-incomplete-Thursday | |
1570 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1571 23 24 25 26 27 nil 28 29 30 31 32 33 (nil . 34) (34.35) (35.36) (36.37) | |
1572 (37.38) ([38 39].39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]] | |
1573 "The structure of the parashiot in a Hebrew year that starts on Monday, | |
1574 is `incomplete' (Heshvan and Kislev each have 29 days), and has Passover | |
1575 start on Thursday.") | |
1576 | |
1577 (defconst hebrew-calendar-year-Monday-complete-Saturday | |
1578 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1579 23 24 25 26 27 nil (nil . 28) (28.29) (29.30) (30.31) (31.32) (32.33) | |
1580 (33.34) (34.35) (35.36) (36.37) (37.38) (38.39) (39.40) (40.41) ([41 42].42) | |
1581 43 44 45 46 47 48 49 50] | |
1582 "The structure of the parashiot in a Hebrew year that starts on Monday, | |
1583 is `complete' (Heshvan and Kislev each have 30 days), and has Passover | |
1584 start on Saturday.") | |
1585 | |
1586 (defconst hebrew-calendar-year-Tuesday-regular-Saturday | |
1587 [51 52 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1588 23 24 25 26 27 nil (nil . 28) (28.29) (29.30) (30.31) (31.32) (32.33) | |
1589 (33.34) (34.35) (35.36) (36.37) (37.38) (38.39) (39.40) (40.41) ([41 42].42) | |
1590 43 44 45 46 47 48 49 50] | |
1591 "The structure of the parashiot in a Hebrew year that starts on Tuesday, | |
1592 is `regular' (Heshvan has 29 days and Kislev has 30 days), and has Passover | |
1593 start on Saturday.") | |
1594 | |
1595 (defconst hebrew-calendar-year-Thursday-incomplete-Sunday | |
1596 [52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1597 23 24 25 26 27 28 nil 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
1598 43 44 45 46 47 48 49 50] | |
1599 "The structure of the parashiot in a Hebrew year that starts on Thursday, | |
1600 is `incomplete' (Heshvan and Kislev both have 29 days), and has Passover | |
1601 start on Sunday.") | |
1602 | |
1603 (defconst hebrew-calendar-year-Thursday-complete-Tuesday | |
1604 [52 nil nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1605 23 24 25 26 27 28 nil 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
1606 43 44 45 46 47 48 49 [50 51]] | |
1607 "The structure of the parashiot in a Hebrew year that starts on Thursday, | |
1608 is `complete' (Heshvan and Kislev both have 30 days), and has Passover | |
1609 start on Tuesday.") | |
1610 | |
1611 (defun hebrew-calendar-parasha-name (p) | |
1612 "Name(s) corresponding to parasha P." | |
1613 (if (arrayp p);; combined parasha | |
1614 (format "%s/%s" | |
1615 (aref hebrew-calendar-parashiot-names (aref p 0)) | |
1616 (aref hebrew-calendar-parashiot-names (aref p 1))) | |
1617 (aref hebrew-calendar-parashiot-names p))) | |
1618 | |
1619 (defun list-islamic-diary-entries () | |
1620 "Add any Islamic date entries from the diary-file to diary-entries-list. | |
1621 Islamic date diary entries must be prefaced by an islamic-diary-entry-symbol | |
1622 \(normally an `I'\). The same diary-date-forms govern the style of the Islamic | |
1623 calendar entries, except that the Islamic month names must be spelled in full. | |
1624 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being | |
1625 Dhu al-Hijjah. If an Islamic date diary entry begins with a | |
1626 diary-nonmarking-symbol the entry will appear in the diary listing, but will | |
1627 not be marked in the calendar. This function is provided for use with the | |
1628 nongregorian-diary-listing-hook." | |
1629 (if (< 0 number) | |
1630 (let ((buffer-read-only nil) | |
1631 (diary-modified (buffer-modified-p)) | |
1632 (gdate original-date) | |
1633 (mark (regexp-quote diary-nonmarking-symbol))) | |
1634 (calendar-for-loop i from 1 to number do | |
1635 (let* ((d diary-date-forms) | |
1636 (idate (calendar-islamic-from-absolute | |
1637 (calendar-absolute-from-gregorian gdate))) | |
1638 (month (extract-calendar-month idate)) | |
1639 (day (extract-calendar-day idate)) | |
1640 (year (extract-calendar-year idate))) | |
1641 (while d | |
1642 (let* | |
1643 ((date-form (if (equal (car (car d)) 'backup) | |
1644 (cdr (car d)) | |
1645 (car d))) | |
1646 (backup (equal (car (car d)) 'backup)) | |
1647 (dayname | |
1648 (concat | |
1649 (calendar-day-name gdate) "\\|" | |
1650 (substring (calendar-day-name gdate) 0 3) ".?")) | |
1651 (calendar-month-name-array | |
1652 calendar-islamic-month-name-array) | |
1653 (monthname | |
1654 (concat | |
1655 "\\*\\|" | |
1656 (calendar-month-name month))) | |
1657 (month (concat "\\*\\|0*" (int-to-string month))) | |
1658 (day (concat "\\*\\|0*" (int-to-string day))) | |
1659 (year | |
1660 (concat | |
1661 "\\*\\|0*" (int-to-string year) | |
1662 (if abbreviated-calendar-year | |
1663 (concat "\\|" (int-to-string (% year 100))) | |
1664 ""))) | |
1665 (regexp | |
1666 (concat | |
1667 "\\(\\`\\|\^M\\|\n\\)" mark "?" | |
1668 (regexp-quote islamic-diary-entry-symbol) | |
1669 "\\(" | |
1670 (mapconcat 'eval date-form "\\)\\(") | |
1671 "\\)")) | |
1672 (case-fold-search t)) | |
1673 (goto-char (point-min)) | |
1674 (while (re-search-forward regexp nil t) | |
1675 (if backup (re-search-backward "\\<" nil t)) | |
1676 (if (and (or (char-equal (preceding-char) ?\^M) | |
1677 (char-equal (preceding-char) ?\n)) | |
1678 (not (looking-at " \\|\^I"))) | |
1679 ;; Diary entry that consists only of date. | |
1680 (backward-char 1) | |
1681 ;; Found a nonempty diary entry--make it visible and | |
1682 ;; add it to the list. | |
1683 (let ((entry-start (point)) | |
1684 (date-start)) | |
1685 (re-search-backward "\^M\\|\n\\|\\`") | |
1686 (setq date-start (point)) | |
1687 (re-search-forward "\^M\\|\n" nil t 2) | |
1688 (while (looking-at " \\|\^I") | |
1689 (re-search-forward "\^M\\|\n" nil t)) | |
1690 (backward-char 1) | |
1691 (subst-char-in-region date-start (point) ?\^M ?\n t) | |
1692 (add-to-diary-list | |
1693 gdate (buffer-substring entry-start (point))))))) | |
1694 (setq d (cdr d)))) | |
1695 (setq gdate | |
1696 (calendar-gregorian-from-absolute | |
1697 (1+ (calendar-absolute-from-gregorian gdate))))) | |
1698 (set-buffer-modified-p diary-modified)) | |
1699 (goto-char (point-min)))) | |
1700 | |
1701 (defun mark-islamic-diary-entries () | |
1702 "Mark days in the calendar window that have Islamic date diary entries. | |
1703 Each entry in diary-file (or included files) visible in the calendar window | |
1704 is marked. Islamic date entries are prefaced by a islamic-diary-entry-symbol | |
1705 \(normally an `I'\). The same diary-date-forms govern the style of the Islamic | |
1706 calendar entries, except that the Islamic month names must be spelled in full. | |
1707 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being | |
1708 Dhu al-Hijjah. Islamic date diary entries that begin with a | |
1709 diary-nonmarking-symbol will not be marked in the calendar. This function is | |
1710 provided for use as part of the nongregorian-diary-marking-hook." | |
1711 (let ((d diary-date-forms)) | |
1712 (while d | |
1713 (let* | |
1714 ((date-form (if (equal (car (car d)) 'backup) | |
1715 (cdr (car d)) | |
1716 (car d)));; ignore 'backup directive | |
1717 (dayname (diary-name-pattern calendar-day-name-array)) | |
1718 (monthname | |
1719 (concat | |
1720 (diary-name-pattern calendar-islamic-month-name-array t) | |
1721 "\\|\\*")) | |
1722 (month "[0-9]+\\|\\*") | |
1723 (day "[0-9]+\\|\\*") | |
1724 (year "[0-9]+\\|\\*") | |
1725 (l (length date-form)) | |
1726 (d-name-pos (- l (length (memq 'dayname date-form)))) | |
1727 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos))) | |
1728 (m-name-pos (- l (length (memq 'monthname date-form)))) | |
1729 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos))) | |
1730 (d-pos (- l (length (memq 'day date-form)))) | |
1731 (d-pos (if (/= l d-pos) (+ 2 d-pos))) | |
1732 (m-pos (- l (length (memq 'month date-form)))) | |
1733 (m-pos (if (/= l m-pos) (+ 2 m-pos))) | |
1734 (y-pos (- l (length (memq 'year date-form)))) | |
1735 (y-pos (if (/= l y-pos) (+ 2 y-pos))) | |
1736 (regexp | |
1737 (concat | |
1738 "\\(\\`\\|\^M\\|\n\\)" | |
1739 (regexp-quote islamic-diary-entry-symbol) | |
1740 "\\(" | |
1741 (mapconcat 'eval date-form "\\)\\(") | |
1742 "\\)")) | |
1743 (case-fold-search t)) | |
1744 (goto-char (point-min)) | |
1745 (while (re-search-forward regexp nil t) | |
1746 (let* ((dd-name | |
1747 (if d-name-pos | |
1748 (buffer-substring | |
1749 (match-beginning d-name-pos) | |
1750 (match-end d-name-pos)))) | |
1751 (mm-name | |
1752 (if m-name-pos | |
1753 (buffer-substring | |
1754 (match-beginning m-name-pos) | |
1755 (match-end m-name-pos)))) | |
1756 (mm (string-to-int | |
1757 (if m-pos | |
1758 (buffer-substring | |
1759 (match-beginning m-pos) | |
1760 (match-end m-pos)) | |
1761 ""))) | |
1762 (dd (string-to-int | |
1763 (if d-pos | |
1764 (buffer-substring | |
1765 (match-beginning d-pos) | |
1766 (match-end d-pos)) | |
1767 ""))) | |
1768 (y-str (if y-pos | |
1769 (buffer-substring | |
1770 (match-beginning y-pos) | |
1771 (match-end y-pos)))) | |
1772 (yy (if (not y-str) | |
1773 0 | |
1774 (if (and (= (length y-str) 2) | |
1775 abbreviated-calendar-year) | |
1776 (let* ((current-y | |
1777 (extract-calendar-year | |
1778 (calendar-islamic-from-absolute | |
1779 (calendar-absolute-from-gregorian | |
1780 (calendar-current-date))))) | |
1781 (y (+ (string-to-int y-str) | |
1782 (* 100 (/ current-y 100))))) | |
1783 (if (> (- y current-y) 50) | |
1784 (- y 100) | |
1785 (if (> (- current-y y) 50) | |
1786 (+ y 100) | |
1787 y))) | |
1788 (string-to-int y-str))))) | |
1789 (if dd-name | |
1790 (mark-calendar-days-named | |
1791 (cdr (assoc (capitalize (substring dd-name 0 3)) | |
1792 (calendar-make-alist | |
1793 calendar-day-name-array | |
1794 0 | |
1795 '(lambda (x) (substring x 0 3)))))) | |
1796 (if mm-name | |
1797 (if (string-equal mm-name "*") | |
1798 (setq mm 0) | |
1799 (setq mm | |
1800 (cdr (assoc | |
1801 (capitalize mm-name) | |
1802 (calendar-make-alist | |
1803 calendar-islamic-month-name-array)))))) | |
1804 (mark-islamic-calendar-date-pattern mm dd yy))))) | |
1805 (setq d (cdr d))))) | |
1806 | |
1807 (defun mark-islamic-calendar-date-pattern (month day year) | |
1808 "Mark all dates in the calendar window that conform to the Islamic date | |
1809 MONTH/DAY/YEAR. A value of 0 in any position is a wild-card." | |
1810 (save-excursion | |
1811 (set-buffer calendar-buffer) | |
1812 (if (and (/= 0 month) (/= 0 day)) | |
1813 (if (/= 0 year) | |
1814 ;; Fully specified Islamic date. | |
1815 (let ((date (calendar-gregorian-from-absolute | |
1816 (calendar-absolute-from-islamic | |
1817 (list month day year))))) | |
1818 (if (calendar-date-is-visible-p date) | |
1819 (mark-visible-calendar-date date))) | |
1820 ;; Month and day in any year--this taken from the holiday stuff. | |
1821 (let* ((islamic-date (calendar-islamic-from-absolute | |
1822 (calendar-absolute-from-gregorian | |
1823 (list displayed-month 15 displayed-year)))) | |
1824 (m (extract-calendar-month islamic-date)) | |
1825 (y (extract-calendar-year islamic-date)) | |
1826 (date)) | |
1827 (if (< m 1) | |
1828 nil;; Islamic calendar doesn't apply. | |
1829 (increment-calendar-month m y (- 10 month)) | |
1830 (if (> m 7);; Islamic date might be visible | |
1831 (let ((date (calendar-gregorian-from-absolute | |
1832 (calendar-absolute-from-islamic | |
1833 (list month day y))))) | |
1834 (if (calendar-date-is-visible-p date) | |
1835 (mark-visible-calendar-date date))))))) | |
1836 ;; Not one of the simple cases--check all visible dates for match. | |
1837 ;; Actually, the following code takes care of ALL of the cases, but | |
1838 ;; it's much too slow to be used for the simple (common) cases. | |
1839 (let ((m displayed-month) | |
1840 (y displayed-year) | |
1841 (first-date) | |
1842 (last-date)) | |
1843 (increment-calendar-month m y -1) | |
1844 (setq first-date | |
1845 (calendar-absolute-from-gregorian | |
1846 (list m 1 y))) | |
1847 (increment-calendar-month m y 2) | |
1848 (setq last-date | |
1849 (calendar-absolute-from-gregorian | |
1850 (list m (calendar-last-day-of-month m y) y))) | |
1851 (calendar-for-loop date from first-date to last-date do | |
1852 (let* ((i-date (calendar-islamic-from-absolute date)) | |
1853 (i-month (extract-calendar-month i-date)) | |
1854 (i-day (extract-calendar-day i-date)) | |
1855 (i-year (extract-calendar-year i-date))) | |
1856 (and (or (zerop month) | |
1857 (= month i-month)) | |
1858 (or (zerop day) | |
1859 (= day i-day)) | |
1860 (or (zerop year) | |
1861 (= year i-year)) | |
1862 (mark-visible-calendar-date | |
1863 (calendar-gregorian-from-absolute date))))))))) | |
1864 | |
1865 (defun make-diary-entry (string &optional nonmarking file) | |
1866 "Insert a diary entry STRING which may be NONMARKING in FILE. | |
1867 If omitted, NONMARKING defaults to nil and FILE defaults to diary-file." | |
1868 (find-file-other-window | |
1869 (substitute-in-file-name (if file file diary-file))) | |
1870 (goto-char (point-max)) | |
1871 (insert | |
1872 (if (bolp) "" "\n") | |
1873 (if nonmarking diary-nonmarking-symbol "") | |
1874 string " ")) | |
1875 | |
1876 (defun insert-diary-entry (arg) | |
1877 "Insert a diary entry for the date indicated by point. | |
1878 Prefix arg will make the entry nonmarking." | |
1879 (interactive "P") | |
1880 (let* ((calendar-date-display-form | |
1881 (if european-calendar-style | |
1882 '(day " " monthname " " year) | |
1883 '(monthname " " day ", " year)))) | |
1884 (make-diary-entry | |
1885 (calendar-date-string | |
1886 (or (calendar-cursor-to-date) | |
1887 (error "Cursor is not on a date!")) | |
1888 t) | |
1889 arg))) | |
1890 | |
1891 (defun insert-weekly-diary-entry (arg) | |
1892 "Insert a weekly diary entry for the day of the week indicated by point. | |
1893 Prefix arg will make the entry nonmarking." | |
1894 (interactive "P") | |
1895 (make-diary-entry | |
1896 (calendar-day-name | |
1897 (or (calendar-cursor-to-date) | |
1898 (error "Cursor is not on a date!"))) | |
1899 arg)) | |
1900 | |
1901 (defun insert-monthly-diary-entry (arg) | |
1902 "Insert a monthly diary entry for the day of the month indicated by point. | |
1903 Prefix arg will make the entry nonmarking." | |
1904 (interactive "P") | |
1905 (let* ((calendar-date-display-form | |
1906 (if european-calendar-style | |
1907 '(day " * ") | |
1908 '("* " day)))) | |
1909 (make-diary-entry | |
1910 (calendar-date-string | |
1911 (or (calendar-cursor-to-date) | |
1912 (error "Cursor is not on a date!")) | |
1913 t) | |
1914 arg))) | |
1915 | |
1916 (defun insert-yearly-diary-entry (arg) | |
1917 "Insert an annual diary entry for the day of the year indicated by point. | |
1918 Prefix arg will make the entry nonmarking." | |
1919 (interactive "P") | |
1920 (let* ((calendar-date-display-form | |
1921 (if european-calendar-style | |
1922 '(day " " monthname) | |
1923 '(monthname " " day)))) | |
1924 (make-diary-entry | |
1925 (calendar-date-string | |
1926 (or (calendar-cursor-to-date) | |
1927 (error "Cursor is not on a date!")) | |
1928 t) | |
1929 arg))) | |
1930 | |
1931 (defun insert-anniversary-diary-entry (arg) | |
1932 "Insert an anniversary diary entry for the date given by point. | |
1933 Prefix arg will make the entry nonmarking." | |
1934 (interactive "P") | |
1935 (let* ((calendar-date-display-form | |
1936 (if european-calendar-style | |
1937 '(day " " month " " year) | |
1938 '(month " " day " " year)))) | |
1939 (make-diary-entry | |
1940 (format "%s(diary-anniversary %s)" | |
1941 sexp-diary-entry-symbol | |
1942 (calendar-date-string | |
1943 (or (calendar-cursor-to-date) | |
1944 (error "Cursor is not on a date!")))) | |
1945 arg))) | |
1946 | |
1947 (defun insert-block-diary-entry (arg) | |
1948 "Insert a block diary entry for the days between the point and marked date. | |
1949 Prefix arg will make the entry nonmarking." | |
1950 (interactive "P") | |
1951 (let* ((calendar-date-display-form | |
1952 (if european-calendar-style | |
1953 '(day " " month " " year) | |
1954 '(month " " day " " year))) | |
1955 (cursor (or (calendar-cursor-to-date) | |
1956 (error "Cursor is not on a date!"))) | |
1957 (mark (or (car calendar-mark-ring) | |
1958 (error "No mark set in this buffer"))) | |
1959 (start) | |
1960 (end)) | |
1961 (if (< (calendar-absolute-from-gregorian mark) | |
1962 (calendar-absolute-from-gregorian cursor)) | |
1963 (setq start mark | |
1964 end cursor) | |
1965 (setq start cursor | |
1966 end mark)) | |
1967 (make-diary-entry | |
1968 (format "%s(diary-block %s %s)" | |
1969 sexp-diary-entry-symbol | |
1970 (calendar-date-string start) | |
1971 (calendar-date-string end)) | |
1972 arg))) | |
1973 | |
1974 (defun insert-cyclic-diary-entry (arg) | |
1975 "Insert a cyclic diary entry starting at the date given by point. | |
1976 Prefix arg will make the entry nonmarking." | |
1977 (interactive "P") | |
1978 (let* ((calendar-date-display-form | |
1979 (if european-calendar-style | |
1980 '(day " " month " " year) | |
1981 '(month " " day " " year)))) | |
1982 (make-diary-entry | |
1983 (format "%s(diary-cyclic %d %s)" | |
1984 sexp-diary-entry-symbol | |
1985 (calendar-read "Repeat every how many days: " | |
1986 '(lambda (x) (> x 0))) | |
1987 (calendar-date-string | |
1988 (or (calendar-cursor-to-date) | |
1989 (error "Cursor is not on a date!")))) | |
1990 arg))) | |
1991 | |
1992 (defun insert-hebrew-diary-entry (arg) | |
1993 "Insert a diary entry for the Hebrew date corresponding to the date | |
1994 indicated by point. Prefix arg will make the entry nonmarking." | |
1995 (interactive "P") | |
1996 (let* ((calendar-date-display-form | |
1997 (if european-calendar-style | |
1998 '(day " " monthname " " year) | |
1999 '(monthname " " day ", " year))) | |
2000 (calendar-month-name-array | |
2001 calendar-hebrew-month-name-array-leap-year)) | |
2002 (make-diary-entry | |
2003 (concat | |
2004 hebrew-diary-entry-symbol | |
2005 (calendar-date-string | |
2006 (calendar-hebrew-from-absolute | |
2007 (calendar-absolute-from-gregorian | |
2008 (or (calendar-cursor-to-date) | |
2009 (error "Cursor is not on a date!")))))) | |
2010 arg))) | |
2011 | |
2012 (defun insert-monthly-hebrew-diary-entry (arg) | |
2013 "Insert a monthly diary entry for the day of the Hebrew month corresponding | |
2014 to the date indicated by point. Prefix arg will make the entry nonmarking." | |
2015 (interactive "P") | |
2016 (let* ((calendar-date-display-form | |
2017 (if european-calendar-style '(day " * ") '("* " day ))) | |
2018 (calendar-month-name-array | |
2019 calendar-hebrew-month-name-array-leap-year)) | |
2020 (make-diary-entry | |
2021 (concat | |
2022 hebrew-diary-entry-symbol | |
2023 (calendar-date-string | |
2024 (calendar-hebrew-from-absolute | |
2025 (calendar-absolute-from-gregorian | |
2026 (or (calendar-cursor-to-date) | |
2027 (error "Cursor is not on a date!")))))) | |
2028 arg))) | |
2029 | |
2030 (defun insert-yearly-hebrew-diary-entry (arg) | |
2031 "Insert an annual diary entry for the day of the Hebrew year corresponding | |
2032 to the date indicated by point. Prefix arg will make the entry nonmarking." | |
2033 (interactive "P") | |
2034 (let* ((calendar-date-display-form | |
2035 (if european-calendar-style | |
2036 '(day " " monthname) | |
2037 '(monthname " " day))) | |
2038 (calendar-month-name-array | |
2039 calendar-hebrew-month-name-array-leap-year)) | |
2040 (make-diary-entry | |
2041 (concat | |
2042 hebrew-diary-entry-symbol | |
2043 (calendar-date-string | |
2044 (calendar-hebrew-from-absolute | |
2045 (calendar-absolute-from-gregorian | |
2046 (or (calendar-cursor-to-date) | |
2047 (error "Cursor is not on a date!")))))) | |
2048 arg))) | |
2049 | |
2050 (defun insert-islamic-diary-entry (arg) | |
2051 "Insert a diary entry for the Islamic date corresponding to the date | |
2052 indicated by point. Prefix arg will make the entry nonmarking." | |
2053 (interactive "P") | |
2054 (let* ((calendar-date-display-form | |
2055 (if european-calendar-style | |
2056 '(day " " monthname " " year) | |
2057 '(monthname " " day ", " year))) | |
2058 (calendar-month-name-array calendar-islamic-month-name-array)) | |
2059 (make-diary-entry | |
2060 (concat | |
2061 islamic-diary-entry-symbol | |
2062 (calendar-date-string | |
2063 (calendar-islamic-from-absolute | |
2064 (calendar-absolute-from-gregorian | |
2065 (or (calendar-cursor-to-date) | |
2066 (error "Cursor is not on a date!")))))) | |
2067 arg))) | |
2068 | |
2069 (defun insert-monthly-islamic-diary-entry (arg) | |
2070 "Insert a monthly diary entry for the day of the Islamic month corresponding | |
2071 to the date indicated by point. Prefix arg will make the entry nonmarking." | |
2072 (interactive "P") | |
2073 (let* ((calendar-date-display-form | |
2074 (if european-calendar-style '(day " * ") '("* " day ))) | |
2075 (calendar-month-name-array calendar-islamic-month-name-array)) | |
2076 (make-diary-entry | |
2077 (concat | |
2078 islamic-diary-entry-symbol | |
2079 (calendar-date-string | |
2080 (calendar-islamic-from-absolute | |
2081 (calendar-absolute-from-gregorian | |
2082 (or (calendar-cursor-to-date) | |
2083 (error "Cursor is not on a date!")))))) | |
2084 arg))) | |
2085 | |
2086 (defun insert-yearly-islamic-diary-entry (arg) | |
2087 "Insert an annual diary entry for the day of the Islamic year corresponding | |
2088 to the date indicated by point. Prefix arg will make the entry nonmarking." | |
2089 (interactive "P") | |
2090 (let* ((calendar-date-display-form | |
2091 (if european-calendar-style | |
2092 '(day " " monthname) | |
2093 '(monthname " " day))) | |
2094 (calendar-month-name-array calendar-islamic-month-name-array)) | |
2095 (make-diary-entry | |
2096 (concat | |
2097 islamic-diary-entry-symbol | |
2098 (calendar-date-string | |
2099 (calendar-islamic-from-absolute | |
2100 (calendar-absolute-from-gregorian | |
2101 (or (calendar-cursor-to-date) | |
2102 (error "Cursor is not on a date!")))))) | |
2103 arg))) | |
584 | 2104 |
2105 (provide 'diary) | |
2106 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2107 ;;; diary.el ends here |