1 ;;; diary.el --- diary functions.
3 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
4 ;; Last-Modified: 30 Jun 1992
7 ;; Copyright (C) 1989, 1990 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY. No author or distributor
13 ;; accepts responsibility to anyone for the consequences of using it
14 ;; or for whether it serves any particular purpose or works at all,
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public
16 ;; License for full details.
18 ;; Everyone is granted permission to copy, modify and redistribute
19 ;; GNU Emacs, but only under the conditions described in the
20 ;; GNU Emacs General Public License. A copy of this license is
21 ;; supposed to have been given to you along with GNU Emacs so you
22 ;; can know your rights and responsibilities. It should be in a
23 ;; file named COPYING. Among other things, the copyright notice
24 ;; and this notice must be preserved on all copies.
28 ;; This collection of functions implements the diary features as described
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
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."
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)
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!"))))
62 (defun view-diary-entries (arg)
63 "Prepare and display a buffer with diary entries.
64 Searches the file diary-file for entries that match ARG days starting with
65 the date indicated by the cursor position in the displayed three-month
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 (or (calendar-cursor-to-date)
72 (error "Cursor is not on a date!"))
74 (error "Your diary file is not readable!"))
75 (error "You don't have a diary file!"))))
77 (autoload 'check-calendar-holidays "holidays"
78 "Check the list of holidays for any that occur on DATE.
79 The value returned is a list of strings of relevant holiday descriptions.
80 The holidays are those in the list calendar-holidays.")
82 (autoload 'calendar-holiday-list "holidays"
83 "Form the list of holidays that occur on dates in the calendar window.
84 The holidays are those in the list calendar-holidays.")
86 (defvar diary-syntax-table
87 (standard-syntax-table)
88 "The syntax table used when parsing dates in the diary file.
89 It is the standard syntax table used in Fundamental mode, but with the
90 syntax of `*' changed to be a word constituent.")
92 (modify-syntax-entry ?* "w" diary-syntax-table)
94 (defun list-diary-entries (date number)
95 "Create and display a buffer containing the relevant lines in diary-file.
96 All lines that apply to DATE and the next NUMBER-1 days are included.
98 Makes all diary entries in the diary file invisible (using selective display),
99 *except* those that are relevant.
101 Returns a list of all relevant diary entries found, if any, in order by date.
102 The list entries have the form ((month day year) string). If the variable
103 `diary-list-include-blanks' is t, this list will include a dummy diary entry
104 \(consisting of the empty string\) for a date with no diary entries.
106 After the list is prepared, the hooks `nongregorian-diary-listing-hook',
107 `list-diary-entries-hook', and `diary-display-hook' are run. These hooks
108 have the following distinct roles:
110 `nongregorian-diary-listing-hook' can cull dates from the diary
111 and each included file. Usually used for Hebrew or Islamic
112 diary entries in files. Applied to *each* file.
114 `list-diary-entries-hook' adds or manipulates diary entries from
115 external sources. Used, for example, to include diary entries
116 from other files or to sort the diary entries. Invoked *once* only.
118 `diary-display-hook' does the actual display of information. Could be
119 used also for an appointment notification function."
122 (let* ((original-date date);; save for possible use in the hooks
123 (old-diary-syntax-table)
125 (date-string (calendar-date-string date))
126 (d-file (substitute-in-file-name diary-file)))
127 (message "Preparing diary...")
129 (let ((diary-buffer (get-file-buffer d-file)))
130 (set-buffer (if diary-buffer
132 (find-file-noselect d-file t))))
133 (setq selective-display t)
134 (setq selective-display-ellipses nil)
135 (setq old-diary-syntax-table (syntax-table))
136 (set-syntax-table diary-syntax-table)
138 (let ((buffer-read-only nil)
139 (diary-modified (buffer-modified-p))
140 (mark (regexp-quote diary-nonmarking-symbol)))
141 (goto-char (1- (point-max)))
142 (if (not (looking-at "\^M\\|\n"))
145 (insert-string "\^M")))
146 (goto-char (point-min))
147 (if (not (looking-at "\^M\\|\n"))
148 (insert-string "\^M"))
149 (subst-char-in-region (point-min) (point-max) ?\n ?\^M t)
150 (calendar-for-loop i from 1 to number do
151 (let ((d diary-date-forms)
152 (month (extract-calendar-month date))
153 (day (extract-calendar-day date))
154 (year (extract-calendar-year date))
155 (entry-found (list-sexp-diary-entries date)))
158 ((date-form (if (equal (car (car d)) 'backup)
161 (backup (equal (car (car d)) 'backup))
164 (calendar-day-name date) "\\|"
165 (substring (calendar-day-name date) 0 3) ".?"))
169 (calendar-month-name month) "\\|"
170 (substring (calendar-month-name month) 0 3) ".?"))
171 (month (concat "\\*\\|0*" (int-to-string month)))
172 (day (concat "\\*\\|0*" (int-to-string day)))
175 "\\*\\|0*" (int-to-string year)
176 (if abbreviated-calendar-year
177 (concat "\\|" (int-to-string (% year 100)))
181 "\\(\\`\\|\^M\\|\n\\)" mark "?\\("
182 (mapconcat 'eval date-form "\\)\\(")
184 (case-fold-search t))
185 (goto-char (point-min))
186 (while (re-search-forward regexp nil t)
187 (if backup (re-search-backward "\\<" nil t))
188 (if (and (or (char-equal (preceding-char) ?\^M)
189 (char-equal (preceding-char) ?\n))
190 (not (looking-at " \\|\^I")))
191 ;; Diary entry that consists only of date.
193 ;; Found a nonempty diary entry--make it visible and
194 ;; add it to the list.
196 (let ((entry-start (point))
198 (re-search-backward "\^M\\|\n\\|\\`")
199 (setq date-start (point))
200 (re-search-forward "\^M\\|\n" nil t 2)
201 (while (looking-at " \\|\^I")
202 (re-search-forward "\^M\\|\n" nil t))
204 (subst-char-in-region date-start
207 date (buffer-substring entry-start (point)))))))
210 (not diary-list-include-blanks)
211 (setq diary-entries-list
212 (append diary-entries-list
213 (list (list date "")))))
215 (calendar-gregorian-from-absolute
216 (1+ (calendar-absolute-from-gregorian date))))
217 (setq entry-found nil)))
218 (set-buffer-modified-p diary-modified))
219 (set-syntax-table old-diary-syntax-table))
220 (goto-char (point-min))
221 (run-hooks 'nongregorian-diary-listing-hook
222 'list-diary-entries-hook
224 diary-entries-list))))
226 (defun include-other-diary-files ()
227 "Include the diary entries from other diary files with those of diary-file.
228 This function is suitable for use just before fancy-diary-display as the
229 list-diary-entries-hook; it enables you to use shared diary files together
230 with your own. The files included are specified in the diary-file by lines of
232 #include \"filename\"
233 This is recursive; that is, #include directives in diary files thus included
234 are obeyed. You can change the \"#include\" to some other string by
235 changing the variable `diary-include-string'."
236 (goto-char (point-min))
237 (while (re-search-forward
239 "\\(\\`\\|\^M\\|\n\\)"
240 (regexp-quote diary-include-string)
243 (let ((diary-file (substitute-in-file-name
244 (buffer-substring (match-beginning 2) (match-end 2))))
245 (diary-list-include-blanks nil)
246 (list-diary-entries-hook 'include-other-diary-files)
247 (diary-display-hook nil))
248 (if (file-exists-p diary-file)
249 (if (file-readable-p diary-file)
251 (setq diary-entries-list
252 (append diary-entries-list
253 (list-diary-entries original-date number)))
254 (kill-buffer (get-file-buffer diary-file)))
256 (message "Can't read included diary file %s" diary-file)
259 (message "Can't find included diary file %s" diary-file)
261 (goto-char (point-min)))
263 (defun simple-diary-display ()
264 "Display the diary buffer if there are any relevant entries or holidays."
265 (let* ((holiday-list (if holidays-in-diary-buffer
266 (check-calendar-holidays original-date)))
267 (msg (format "No diary entries for %s %s"
268 (concat date-string (if holiday-list ":" ""))
269 (mapconcat 'identity holiday-list "; "))))
270 (if (or (not diary-entries-list)
271 (and (not (cdr diary-entries-list))
272 (string-equal (car (cdr (car diary-entries-list))) "")))
273 (if (<= (length msg) (frame-width))
275 (set-buffer (get-buffer-create holiday-buffer))
276 (setq buffer-read-only nil)
277 (setq mode-line-format
278 (format "--------------------------%s%%-" date-string))
280 (insert (mapconcat 'identity holiday-list "\n"))
281 (goto-char (point-min))
282 (set-buffer-modified-p nil)
283 (setq buffer-read-only t)
284 (display-buffer holiday-buffer)
285 (message "No diary entries for %s" date-string))
286 (setq mode-line-format
287 (format "%%*--%sDiary %s %s%s%s%%-"
288 (if holiday-list "" "---------------")
289 (if holiday-list "for" "entries for")
291 (if holiday-list ": " "")
292 (mapconcat 'identity holiday-list "; ")))
293 (display-buffer (get-file-buffer d-file))
294 (message "Preparing diary...done"))))
296 (defun fancy-diary-display ()
297 "Prepare a diary buffer with relevant entries in a fancy, noneditable form.
298 This function is provided for optional use as the `list-diary-entries-hook'."
299 (if (or (not diary-entries-list)
300 (and (not (cdr diary-entries-list))
301 (string-equal (car (cdr (car diary-entries-list))) "")))
302 (let* ((holiday-list (if holidays-in-diary-buffer
303 (check-calendar-holidays original-date)))
304 (msg (format "No diary entries for %s %s"
305 (concat date-string (if holiday-list ":" ""))
306 (mapconcat 'identity holiday-list "; "))))
307 (if (<= (length msg) (frame-width))
309 (set-buffer (get-buffer-create holiday-buffer))
310 (setq buffer-read-only nil)
311 (setq mode-line-format
312 (format "--------------------------%s%%-" date-string))
314 (insert (mapconcat 'identity holiday-list "\n"))
315 (goto-char (point-min))
316 (set-buffer-modified-p nil)
317 (setq buffer-read-only t)
318 (display-buffer holiday-buffer)
319 (message "No diary entries for %s" date-string)))
320 (save-excursion;; Turn off selective-display in the diary file's buffer.
321 (set-buffer (get-file-buffer (substitute-in-file-name diary-file)))
322 (let ((diary-modified (buffer-modified-p)))
323 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)
324 (setq selective-display nil)
325 (kill-local-variable 'mode-line-format)
326 (set-buffer-modified-p diary-modified)))
327 (save-excursion;; Prepare the fancy diary buffer.
328 (set-buffer (get-buffer-create fancy-diary-buffer))
329 (setq buffer-read-only nil)
330 (make-local-variable 'mode-line-format)
331 (setq mode-line-format "---------------------------Diary Entries%-")
333 (let ((entry-list diary-entries-list)
335 (holiday-list-last-month 1)
336 (holiday-list-last-year 1)
339 (if (not (calendar-date-equal date (car (car entry-list))))
341 (setq date (car (car entry-list)))
342 (and holidays-in-diary-buffer
343 (calendar-date-compare
344 (list (list holiday-list-last-month
345 (calendar-last-day-of-month
346 holiday-list-last-month
347 holiday-list-last-year)
348 holiday-list-last-year))
350 ;; We need to get the holidays for the next 3 months.
351 (setq holiday-list-last-month
352 (extract-calendar-month date))
353 (setq holiday-list-last-year
354 (extract-calendar-year date))
355 (increment-calendar-month
356 holiday-list-last-month holiday-list-last-year 1)
358 (let ((displayed-month holiday-list-last-month)
359 (displayed-year holiday-list-last-year))
360 (calendar-holiday-list)))
361 (increment-calendar-month
362 holiday-list-last-month holiday-list-last-year 1))
363 (let* ((date-string (calendar-date-string date))
365 (let ((h holiday-list)
367 ;; Make a list of all holidays for date.
369 (if (calendar-date-equal date (car (car h)))
370 (setq d (append d (cdr (car h)))))
373 (insert (if (= (point) (point-min)) "" ?\n) date-string)
374 (if date-holiday-list (insert ": "))
375 (let ((l (current-column)))
376 (insert (mapconcat 'identity date-holiday-list
377 (concat "\n" (make-string l ? )))))
378 (let ((l (current-column)))
379 (insert ?\n (make-string l ?=) ?\n)))))
380 (if (< 0 (length (car (cdr (car entry-list)))))
381 (insert (car (cdr (car entry-list))) ?\n))
382 (setq entry-list (cdr entry-list))))
383 (set-buffer-modified-p nil)
384 (goto-char (point-min))
385 (setq buffer-read-only t)
386 (display-buffer fancy-diary-buffer)
387 (message "Preparing diary...done"))))
389 (defun print-diary-entries ()
390 "Print a hard copy of the entries visible in the diary window.
391 The hooks given by the variable `print-diary-entries-hook' are called after
392 the temporary buffer of visible diary entries is prepared; it is the hooks
393 that do the actual printing and kill the buffer."
395 (let ((diary-buffer (get-file-buffer (substitute-in-file-name diary-file))))
397 (let ((temp-buffer (get-buffer-create "*Printable Diary Entries*")))
399 (set-buffer diary-buffer)
400 (copy-to-buffer temp-buffer (point-min) (point-max))
401 (set-buffer temp-buffer)
402 (while (re-search-forward "\^M.*$" nil t)
404 (run-hooks 'print-diary-entries-hook)))
405 (error "You don't have a diary buffer!"))))
407 (defun add-diary-heading ()
408 "Add a heading to the diary entries for printing.
409 The heading is formed from the mode line of the diary buffer. This function
410 is used in the default value of the variable `print-diary-entry-hooks'."
413 (set-buffer diary-buffer)
414 (setq heading mode-line-format)
415 (string-match "%\\*-*\\([^-].*\\)%-$" heading)
417 (substring heading (match-beginning 1) (match-end 1)))
418 (set-buffer temp-buffer)
419 (goto-char (point-min))
421 (make-string (length heading) ?=) "\n"))))
423 (defun show-all-diary-entries ()
424 "Show all of the diary entries in the diary-file.
425 This function gets rid of the selective display of the diary-file so that
426 all entries, not just some, are visible. If there is no diary buffer, one
429 (let ((d-file (substitute-in-file-name diary-file)))
430 (if (and d-file (file-exists-p d-file))
431 (if (file-readable-p d-file)
433 (let ((diary-buffer (get-file-buffer d-file)))
434 (set-buffer (if diary-buffer
436 (find-file-noselect d-file t)))
437 (let ((buffer-read-only nil)
438 (diary-modified (buffer-modified-p)))
439 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)
440 (setq selective-display nil)
441 (make-local-variable 'mode-line-format)
442 (setq mode-line-format
443 "%*---------------------------All Diary Entries%-")
444 (display-buffer (current-buffer))
445 (set-buffer-modified-p diary-modified))))
446 (error "Your diary file is not readable!"))
447 (error "You don't have a diary file!"))))
449 (defun diary-name-pattern (string-array &optional fullname)
450 "Convert an STRING-ARRAY, an array of strings to a pattern.
451 The pattern will match any of the strings, either entirely or abbreviated
452 to three characters. An abbreviated form will match with or without a period;
453 If the optional FULLNAME is t, abbreviations will not match, just the full
456 (calendar-for-loop i from 0 to (1- (length string-array)) do
460 (if (string-equal pattern "") "" "\\|")
461 (aref string-array i)
466 (substring (aref string-array i) 0 3) ".?")))))
469 (defun mark-diary-entries ()
470 "Mark days in the calendar window that have diary entries.
471 Each entry in diary-file visible in the calendar window is marked. After the
472 entries are marked, the hooks `nongregorian-diary-marking-hook' and
473 `mark-diary-entries-hook' are run."
475 (setq mark-diary-entries-in-calendar t)
476 (let ((d-file (substitute-in-file-name diary-file)))
477 (if (and d-file (file-exists-p d-file))
478 (if (file-readable-p d-file)
480 (message "Marking diary entries...")
481 (set-buffer (find-file-noselect d-file t))
482 (let ((d diary-date-forms)
483 (old-diary-syntax-table))
484 (setq old-diary-syntax-table (syntax-table))
485 (set-syntax-table diary-syntax-table)
488 ((date-form (if (equal (car (car d)) 'backup)
490 (car d)));; ignore 'backup directive
491 (dayname (diary-name-pattern calendar-day-name-array))
494 (diary-name-pattern calendar-month-name-array)
496 (month "[0-9]+\\|\\*")
498 (year "[0-9]+\\|\\*")
499 (l (length date-form))
500 (d-name-pos (- l (length (memq 'dayname date-form))))
501 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos)))
502 (m-name-pos (- l (length (memq 'monthname date-form))))
503 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos)))
504 (d-pos (- l (length (memq 'day date-form))))
505 (d-pos (if (/= l d-pos) (+ 2 d-pos)))
506 (m-pos (- l (length (memq 'month date-form))))
507 (m-pos (if (/= l m-pos) (+ 2 m-pos)))
508 (y-pos (- l (length (memq 'year date-form))))
509 (y-pos (if (/= l y-pos) (+ 2 y-pos)))
512 "\\(\\`\\|\^M\\|\n\\)\\("
513 (mapconcat 'eval date-form "\\)\\(")
515 (case-fold-search t))
516 (goto-char (point-min))
517 (while (re-search-forward regexp nil t)
521 (match-beginning d-name-pos)
522 (match-end d-name-pos))))
526 (match-beginning m-name-pos)
527 (match-end m-name-pos))))
531 (match-beginning m-pos)
537 (match-beginning d-pos)
542 (match-beginning y-pos)
546 (if (and (= (length y-str) 2)
547 abbreviated-calendar-year)
549 (extract-calendar-year
550 (calendar-current-date)))
551 (y (+ (string-to-int y-str)
553 (/ current-y 100)))))
554 (if (> (- y current-y) 50)
556 (if (> (- current-y y) 50)
559 (string-to-int y-str)))))
561 (mark-calendar-days-named
562 (cdr (assoc (capitalize (substring dd-name 0 3))
564 calendar-day-name-array
566 '(lambda (x) (substring x 0 3))))))
568 (if (string-equal mm-name "*")
573 (substring mm-name 0 3))
575 calendar-month-name-array
577 '(lambda (x) (substring x 0 3)))
579 (mark-calendar-date-pattern mm dd yy))))
581 (mark-sexp-diary-entries)
582 (run-hooks 'nongregorian-diary-marking-hook
583 'mark-diary-entries-hook)
584 (set-syntax-table old-diary-syntax-table)
585 (message "Marking diary entries...done")))
586 (error "Your diary file is not readable!"))
587 (error "You don't have a diary file!"))))
589 (defun mark-sexp-diary-entries ()
590 "Mark days in the calendar window that have sexp diary entries.
591 Each entry in diary-file (or included files) visible in the calendar window
592 is marked. See the documentation for the function `list-sexp-diary-entries'."
593 (let* ((sexp-mark (regexp-quote sexp-diary-entry-symbol))
594 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)" sexp-mark "("))
600 (set-buffer calendar-buffer)
601 (setq m displayed-month)
602 (setq y displayed-year))
603 (increment-calendar-month m y -1)
605 (calendar-absolute-from-gregorian (list m 1 y)))
606 (increment-calendar-month m y 2)
608 (calendar-absolute-from-gregorian
609 (list m (calendar-last-day-of-month m y) y)))
610 (goto-char (point-min))
611 (while (re-search-forward s-entry nil t)
613 (let ((sexp-start (point))
619 (setq sexp (buffer-substring sexp-start (point)))
621 (re-search-backward "\^M\\|\n\\|\\`")
622 (setq line-start (point)))
624 (if (and (or (char-equal (preceding-char) ?\^M)
625 (char-equal (preceding-char) ?\n))
626 (not (looking-at " \\|\^I")))
627 (progn;; Diary entry consists only of the sexp
630 (setq entry-start (point))
631 (re-search-forward "\^M\\|\n" nil t)
632 (while (looking-at " \\|\^I")
633 (re-search-forward "\^M\\|\n" nil t))
635 (setq entry (buffer-substring entry-start (point)))
636 (while (string-match "[\^M]" entry)
637 (aset entry (match-beginning 0) ?\n )))
638 (calendar-for-loop date from first-date to last-date do
639 (if (diary-sexp-entry sexp entry
640 (calendar-gregorian-from-absolute date))
641 (mark-visible-calendar-date
642 (calendar-gregorian-from-absolute date))))))))
644 (defun mark-included-diary-files ()
645 "Mark the diary entries from other diary files with those of diary-file.
646 This function is suitable for use as the mark-diary-entries-hook; it enables
647 you to use shared diary files together with your own. The files included are
648 specified in the diary-file by lines of the form
649 #include \"filename\"
650 This is recursive; that is, #include directives in diary files thus included
651 are obeyed. You can change the \"#include\" to some other string by
652 changing the variable `diary-include-string'."
653 (goto-char (point-min))
654 (while (re-search-forward
656 "\\(\\`\\|\^M\\|\n\\)"
657 (regexp-quote diary-include-string)
660 (let ((diary-file (substitute-in-file-name
661 (buffer-substring (match-beginning 2) (match-end 2))))
662 (mark-diary-entries-hook 'mark-included-diary-files))
663 (if (file-exists-p diary-file)
664 (if (file-readable-p diary-file)
667 (kill-buffer (get-file-buffer diary-file)))
669 (message "Can't read included diary file %s" diary-file)
672 (message "Can't find included diary file %s" diary-file)
674 (goto-char (point-min)))
676 (defun mark-calendar-days-named (dayname)
677 "Mark all dates in the calendar window that are day DAYNAME of the week.
678 0 means all Sundays, 1 means all Mondays, and so on."
680 (set-buffer calendar-buffer)
681 (let ((prev-month displayed-month)
682 (prev-year displayed-year)
683 (succ-month displayed-month)
684 (succ-year displayed-year)
687 (increment-calendar-month succ-month succ-year 1)
688 (increment-calendar-month prev-month prev-year -1)
689 (setq day (calendar-absolute-from-gregorian
690 (calendar-nth-named-day 1 dayname prev-month prev-year)))
691 (setq last-day (calendar-absolute-from-gregorian
692 (calendar-nth-named-day -1 dayname succ-month succ-year)))
693 (while (<= day last-day)
694 (mark-visible-calendar-date (calendar-gregorian-from-absolute day))
695 (setq day (+ day 7))))))
697 (defun mark-calendar-date-pattern (month day year)
698 "Mark all dates in the calendar window that conform to MONTH/DAY/YEAR.
699 A value of 0 in any position is a wild-card."
701 (set-buffer calendar-buffer)
702 (let ((m displayed-month)
704 (increment-calendar-month m y -1)
705 (calendar-for-loop i from 0 to 2 do
706 (mark-calendar-month m y month day year)
707 (increment-calendar-month m y 1)))))
709 (defun mark-calendar-month (month year p-month p-day p-year)
710 "Mark dates in the MONTH/YEAR that conform to pattern P-MONTH/P_DAY/P-YEAR.
711 A value of 0 in any position of the pattern is a wild-card."
712 (if (or (and (= month p-month)
713 (or (= p-year 0) (= year p-year)))
715 (or (= p-year 0) (= year p-year))))
718 i from 1 to (calendar-last-day-of-month month year) do
719 (mark-visible-calendar-date (list month i year)))
720 (mark-visible-calendar-date (list month p-day year)))))
722 (defun diary-entry-compare (e1 e2)
723 "Returns t if E1 is earlier than E2."
724 (or (calendar-date-compare e1 e2)
725 (and (calendar-date-equal (car e1) (car e2))
726 (< (diary-entry-time (car (cdr e1)))
727 (diary-entry-time (car (cdr e2)))))))
729 (defun diary-entry-time (s)
730 "Time at the beginning of the string S in a military-style integer.
731 For example, returns 1325 for 1:25pm. Returns -9999 if no time is recognized.
732 The recognized forms are XXXX or X:XX or XX:XX (military time), XXam or XXpm,
733 and XX:XXam or XX:XXpm."
734 (cond ((string-match;; Military time
735 "^ *\\([0-9]?[0-9]\\):?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)" s)
736 (+ (* 100 (string-to-int
737 (substring s (match-beginning 1) (match-end 1))))
738 (string-to-int (substring s (match-beginning 2) (match-end 2)))))
739 ((string-match;; Hour only XXam or XXpm
740 "^ *\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s)
741 (+ (* 100 (% (string-to-int
742 (substring s (match-beginning 1) (match-end 1)))
744 (if (string-equal "a"
745 (substring s (match-beginning 2) (match-end 2)))
747 ((string-match;; Hour and minute XX:XXam or XX:XXpm
748 "^ *\\([0-9]?[0-9]\\):\\([0-9][0-9]\\)\\([ap]\\)m\\>" s)
749 (+ (* 100 (% (string-to-int
750 (substring s (match-beginning 1) (match-end 1)))
752 (string-to-int (substring s (match-beginning 2) (match-end 2)))
753 (if (string-equal "a"
754 (substring s (match-beginning 3) (match-end 3)))
756 (t -9999)));; Unrecognizable
758 (defun list-hebrew-diary-entries ()
759 "Add any Hebrew date entries from the diary-file to diary-entries-list.
760 Hebrew date diary entries must be prefaced by a hebrew-diary-entry-symbol
761 \(normally an `H'\). The same diary-date-forms govern the style of the Hebrew
762 calendar entries, except that the Hebrew month names must be spelled in full.
763 The Hebrew months are numbered from 1 to 13 with Nisan being 1, 12 being
764 Adar I and 13 being Adar II; you must use `Adar I' if you want Adar of a
765 common Hebrew year. If a Hebrew date diary entry begins with a
766 diary-nonmarking-symbol the entry will appear in the diary listing, but will
767 not be marked in the calendar. This function is provided for use with the
768 nongregorian-diary-listing-hook."
770 (let ((buffer-read-only nil)
771 (diary-modified (buffer-modified-p))
772 (gdate original-date)
773 (mark (regexp-quote diary-nonmarking-symbol)))
774 (calendar-for-loop i from 1 to number do
775 (let* ((d diary-date-forms)
776 (hdate (calendar-hebrew-from-absolute
777 (calendar-absolute-from-gregorian gdate)))
778 (month (extract-calendar-month hdate))
779 (day (extract-calendar-day hdate))
780 (year (extract-calendar-year hdate)))
783 ((date-form (if (equal (car (car d)) 'backup)
786 (backup (equal (car (car d)) 'backup))
789 (calendar-day-name gdate) "\\|"
790 (substring (calendar-day-name gdate) 0 3) ".?"))
791 (calendar-month-name-array
792 calendar-hebrew-month-name-array-leap-year)
796 (calendar-month-name month)))
797 (month (concat "\\*\\|0*" (int-to-string month)))
798 (day (concat "\\*\\|0*" (int-to-string day)))
801 "\\*\\|0*" (int-to-string year)
802 (if abbreviated-calendar-year
803 (concat "\\|" (int-to-string (% year 100)))
807 "\\(\\`\\|\^M\\|\n\\)" mark "?"
808 (regexp-quote hebrew-diary-entry-symbol)
810 (mapconcat 'eval date-form "\\)\\(")
812 (case-fold-search t))
813 (goto-char (point-min))
814 (while (re-search-forward regexp nil t)
815 (if backup (re-search-backward "\\<" nil t))
816 (if (and (or (char-equal (preceding-char) ?\^M)
817 (char-equal (preceding-char) ?\n))
818 (not (looking-at " \\|\^I")))
819 ;; Diary entry that consists only of date.
821 ;; Found a nonempty diary entry--make it visible and
822 ;; add it to the list.
823 (let ((entry-start (point))
825 (re-search-backward "\^M\\|\n\\|\\`")
826 (setq date-start (point))
827 (re-search-forward "\^M\\|\n" nil t 2)
828 (while (looking-at " \\|\^I")
829 (re-search-forward "\^M\\|\n" nil t))
831 (subst-char-in-region date-start (point) ?\^M ?\n t)
833 gdate (buffer-substring entry-start (point)))))))
836 (calendar-gregorian-from-absolute
837 (1+ (calendar-absolute-from-gregorian gdate)))))
838 (set-buffer-modified-p diary-modified))
839 (goto-char (point-min))))
841 (defun mark-hebrew-diary-entries ()
842 "Mark days in the calendar window that have Hebrew date diary entries.
843 Each entry in diary-file (or included files) visible in the calendar window
844 is marked. Hebrew date entries are prefaced by a hebrew-diary-entry-symbol
845 \(normally an `H'\). The same diary-date-forms govern the style of the Hebrew
846 calendar entries, except that the Hebrew month names must be spelled in full.
847 The Hebrew months are numbered from 1 to 13 with Nisan being 1, 12 being
848 Adar I and 13 being Adar II; you must use `Adar I' if you want Adar of a
849 common Hebrew year. Hebrew date diary entries that begin with a
850 diary-nonmarking symbol will not be marked in the calendar. This function
851 is provided for use as part of the nongregorian-diary-marking-hook."
852 (let ((d diary-date-forms))
855 ((date-form (if (equal (car (car d)) 'backup)
857 (car d)));; ignore 'backup directive
858 (dayname (diary-name-pattern calendar-day-name-array))
861 (diary-name-pattern calendar-hebrew-month-name-array-leap-year t)
863 (month "[0-9]+\\|\\*")
865 (year "[0-9]+\\|\\*")
866 (l (length date-form))
867 (d-name-pos (- l (length (memq 'dayname date-form))))
868 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos)))
869 (m-name-pos (- l (length (memq 'monthname date-form))))
870 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos)))
871 (d-pos (- l (length (memq 'day date-form))))
872 (d-pos (if (/= l d-pos) (+ 2 d-pos)))
873 (m-pos (- l (length (memq 'month date-form))))
874 (m-pos (if (/= l m-pos) (+ 2 m-pos)))
875 (y-pos (- l (length (memq 'year date-form))))
876 (y-pos (if (/= l y-pos) (+ 2 y-pos)))
879 "\\(\\`\\|\^M\\|\n\\)"
880 (regexp-quote hebrew-diary-entry-symbol)
882 (mapconcat 'eval date-form "\\)\\(")
884 (case-fold-search t))
885 (goto-char (point-min))
886 (while (re-search-forward regexp nil t)
890 (match-beginning d-name-pos)
891 (match-end d-name-pos))))
895 (match-beginning m-name-pos)
896 (match-end m-name-pos))))
900 (match-beginning m-pos)
906 (match-beginning d-pos)
911 (match-beginning y-pos)
915 (if (and (= (length y-str) 2)
916 abbreviated-calendar-year)
918 (extract-calendar-year
919 (calendar-hebrew-from-absolute
920 (calendar-absolute-from-gregorian
921 (calendar-current-date)))))
922 (y (+ (string-to-int y-str)
923 (* 100 (/ current-y 100)))))
924 (if (> (- y current-y) 50)
926 (if (> (- current-y y) 50)
929 (string-to-int y-str)))))
931 (mark-calendar-days-named
932 (cdr (assoc (capitalize (substring dd-name 0 3))
934 calendar-day-name-array
936 '(lambda (x) (substring x 0 3))))))
938 (if (string-equal mm-name "*")
946 calendar-hebrew-month-name-array-leap-year))))))
947 (mark-hebrew-calendar-date-pattern mm dd yy)))))
950 (defun mark-hebrew-calendar-date-pattern (month day year)
951 "Mark all dates in the calendar window that conform to the Hebrew date
952 MONTH/DAY/YEAR. A value of 0 in any position is a wild-card."
954 (set-buffer calendar-buffer)
955 (if (and (/= 0 month) (/= 0 day))
957 ;; Fully specified Hebrew date.
958 (let ((date (calendar-gregorian-from-absolute
959 (calendar-absolute-from-hebrew
960 (list month day year)))))
961 (if (calendar-date-is-visible-p date)
962 (mark-visible-calendar-date date)))
963 ;; Month and day in any year--this taken from the holiday stuff.
964 (if (memq displayed-month;; This test is only to speed things up a
965 (list ;; bit; it works fine without the test too.
966 (if (< 11 month) (- month 11) (+ month 1))
967 (if (< 10 month) (- month 10) (+ month 2))
968 (if (< 9 month) (- month 9) (+ month 3))
969 (if (< 8 month) (- month 8) (+ month 4))
970 (if (< 7 month) (- month 7) (+ month 5))))
971 (let ((m1 displayed-month)
976 (increment-calendar-month m1 y1 -1)
977 (increment-calendar-month m2 y2 1)
978 (let* ((start-date (calendar-absolute-from-gregorian
980 (end-date (calendar-absolute-from-gregorian
982 (calendar-last-day-of-month m2 y2)
985 (calendar-hebrew-from-absolute start-date))
986 (hebrew-end (calendar-hebrew-from-absolute end-date))
987 (hebrew-y1 (extract-calendar-year hebrew-start))
988 (hebrew-y2 (extract-calendar-year hebrew-end)))
989 (setq year (if (< 6 month) hebrew-y2 hebrew-y1))
990 (let ((date (calendar-gregorian-from-absolute
991 (calendar-absolute-from-hebrew
992 (list month day year)))))
993 (if (calendar-date-is-visible-p date)
994 (mark-visible-calendar-date date)))))))
995 ;; Not one of the simple cases--check all visible dates for match.
996 ;; Actually, the following code takes care of ALL of the cases, but
997 ;; it's much too slow to be used for the simple (common) cases.
998 (let ((m displayed-month)
1002 (increment-calendar-month m y -1)
1004 (calendar-absolute-from-gregorian
1006 (increment-calendar-month m y 2)
1008 (calendar-absolute-from-gregorian
1009 (list m (calendar-last-day-of-month m y) y)))
1010 (calendar-for-loop date from first-date to last-date do
1011 (let* ((h-date (calendar-hebrew-from-absolute date))
1012 (h-month (extract-calendar-month h-date))
1013 (h-day (extract-calendar-day h-date))
1014 (h-year (extract-calendar-year h-date)))
1015 (and (or (zerop month)
1021 (mark-visible-calendar-date
1022 (calendar-gregorian-from-absolute date)))))))))
1024 (defun list-sexp-diary-entries (date)
1025 "Add any sexp entries for DATE from the diary-file to diary-entries-list
1026 and make them visible in the diary file. Returns t if any entries were found.
1028 Sexp diary entries must be prefaced by a sexp-diary-entry-symbol (normally
1029 `%%'). The form of a sexp diary entry is
1033 Both ENTRY and DATE are globally available when the SEXP is evaluated. If the
1034 SEXP yields the value nil, the diary entry does not apply. If it yields a
1035 non-nil value, ENTRY will be taken to apply to DATE; if the non-nil value is a
1036 string, that string will be the diary entry in the fancy diary display.
1038 For example, the following diary entry will apply to the 21st of the month
1039 if it is a weekday and the Friday before if the 21st is on a weekend:
1041 &%%(let ((dayname (calendar-day-of-week date))
1042 (day (extract-calendar-day date)))
1044 (and (= day 21) (memq dayname '(1 2 3 4 5)))
1045 (and (memq day '(19 20)) (= dayname 5)))
1046 ) UIUC pay checks deposited
1048 A number of built-in functions are available for this type of diary entry:
1050 %%(diary-float MONTH DAYNAME N) text
1051 Entry will appear on the Nth DAYNAME of MONTH.
1052 (DAYNAME=0 means Sunday, 1 means Monday, and so on;
1053 if N is negative it counts backward from the end of
1054 the month. MONTH can be a list of months, a single
1055 month, or t to specify all months.
1057 %%(diary-block M1 D1 Y1 M2 D2 Y2) text
1058 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2,
1059 inclusive. (If `european-calendar-style' is t, the
1060 order of the parameters should be changed to D1, M1, Y1,
1063 %%(diary-anniversary MONTH DAY YEAR) text
1064 Entry will appear on anniversary dates of MONTH DAY, YEAR.
1065 (If `european-calendar-style' is t, the order of the
1066 parameters should be changed to DAY, MONTH, YEAR.) Text
1067 can contain %d or %d%s; %d will be replaced by the number
1068 of years since the MONTH DAY, YEAR and %s will be replaced
1069 by the ordinal ending of that number (that is, `st', `nd',
1070 `rd' or `th', as appropriate. The anniversary of February
1071 29 is considered to be March 1 in a non-leap year.
1073 %%(diary-cyclic N MONTH DAY YEAR) text
1074 Entry will appear every N days, starting MONTH DAY, YEAR.
1075 (If `european-calendar-style' is t, the order of the
1076 parameters should be changed to N, DAY, MONTH, YEAR.) Text
1077 can contain %d or %d%s; %d will be replaced by the number
1078 of repetitions since the MONTH DAY, YEAR and %s will
1079 be replaced by the ordinal ending of that number (that is,
1080 `st', `nd', `rd' or `th', as appropriate.
1082 %%(diary-day-of-year)
1083 Diary entries giving the day of the year and the number of
1084 days remaining in the year will be made every day. Note
1085 that since there is no text, it makes sense only if the
1086 fancy diary display is used.
1089 Diary entries giving the corresponding ISO commercial date
1090 will be made every day. Note that since there is no text,
1091 it makes sense only if the fancy diary display is used.
1093 %%(diary-french-date)
1094 Diary entries giving the corresponding French Revolutionary
1095 date will be made every day. Note that since there is no
1096 text, it makes sense only if the fancy diary display is used.
1098 %%(diary-islamic-date)
1099 Diary entries giving the corresponding Islamic date will be
1100 made every day. Note that since there is no text, it
1101 makes sense only if the fancy diary display is used.
1103 %%(diary-hebrew-date)
1104 Diary entries giving the corresponding Hebrew date will be
1105 made every day. Note that since there is no text, it
1106 makes sense only if the fancy diary display is used.
1108 %%(diary-yahrzeit MONTH DAY YEAR) text
1109 Text is assumed to be the name of the person; the date is
1110 the date of death on the *civil* calendar. The diary entry
1111 will appear on the proper Hebrew-date anniversary and on the
1112 day before. (If `european-calendar-style' is t, the order
1113 of the parameters should be changed to DAY, MONTH, YEAR.)
1115 %%(diary-rosh-hodesh)
1116 Diary entries will be made on the dates of Rosh Hodesh on
1117 the Hebrew calendar. Note that since there is no text, it
1118 makes sense only if the fancy diary display is used.
1121 Diary entries giving the weekly parasha will be made on
1122 every Saturday. Note that since there is no text, it
1123 makes sense only if the fancy diary display is used.
1126 Diary entries giving the omer count will be made every day
1127 from Passover to Shavuoth. Note that since there is no text,
1128 it makes sense only if the fancy diary display is used.
1130 Marking these entries is *extremely* time consuming, so these entries are
1131 best if they are nonmarking."
1132 (let* ((mark (regexp-quote diary-nonmarking-symbol))
1133 (sexp-mark (regexp-quote sexp-diary-entry-symbol))
1134 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)" mark "?" sexp-mark "("))
1136 (goto-char (point-min))
1137 (while (re-search-forward s-entry nil t)
1139 (let ((sexp-start (point))
1145 (setq sexp (buffer-substring sexp-start (point)))
1147 (re-search-backward "\^M\\|\n\\|\\`")
1148 (setq line-start (point)))
1150 (if (and (or (char-equal (preceding-char) ?\^M)
1151 (char-equal (preceding-char) ?\n))
1152 (not (looking-at " \\|\^I")))
1153 (progn;; Diary entry consists only of the sexp
1156 (setq entry-start (point))
1157 (re-search-forward "\^M\\|\n" nil t)
1158 (while (looking-at " \\|\^I")
1159 (re-search-forward "\^M\\|\n" nil t))
1161 (setq entry (buffer-substring entry-start (point)))
1162 (while (string-match "[\^M]" entry)
1163 (aset entry (match-beginning 0) ?\n )))
1164 (let ((diary-entry (diary-sexp-entry sexp entry date)))
1166 (subst-char-in-region line-start (point) ?\^M ?\n t))
1167 (add-to-diary-list date diary-entry)
1168 (setq entry-found (or entry-found diary-entry)))))
1171 (defun diary-sexp-entry (sexp entry date)
1172 "Process a SEXP diary ENTRY for DATE."
1173 (let ((result (condition-case nil
1174 (eval (car (read-from-string sexp)))
1177 (message "Bad sexp at line %d in %s: %s"
1180 (narrow-to-region 1 (point))
1181 (goto-char (point-min))
1183 (while (re-search-forward "\n\\|\^M" nil t)
1184 (setq lines (1+ lines)))
1188 (if (stringp result)
1194 (defun diary-block (m1 d1 y1 m2 d2 y2)
1195 "Block diary entry--entry applies if date is between two dates. Order of
1196 the parameters is M1, D1, Y1, M2, D2, Y2 `european-calendar-style' is nil, and
1197 D1, M1, Y1, D2, M2, Y2 if `european-calendar-style' is t."
1198 (let ((date1 (calendar-absolute-from-gregorian
1199 (if european-calendar-style
1202 (date2 (calendar-absolute-from-gregorian
1203 (if european-calendar-style
1206 (d (calendar-absolute-from-gregorian date)))
1207 (if (and (<= date1 d) (<= d date2))
1210 (defun diary-float (month dayname n)
1211 "Floating diary entry--entry applies if date is the nth dayname of month.
1212 Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant
1213 t, or an integer. The constant t means all months. If N is negative, count
1214 backward from the end of the month."
1215 (let ((m (extract-calendar-month date))
1216 (y (extract-calendar-year date)))
1218 (or (and (listp month) (memq m month))
1221 (calendar-date-equal date (calendar-nth-named-day n dayname m y)))
1224 (defun diary-anniversary (month day year)
1225 "Anniversary diary entry--entry applies if date is the anniversary of
1226 MONTH, DAY, YEAR if `european-calendar-style' is nil, and DAY, MONTH, YEAR
1227 if `european-calendar-style' is t. Diary entry can contain `%d' or `%d%s'; the
1228 %d will be replaced by the number of years since the MONTH DAY, YEAR and the
1229 %s will be replaced by the ordinal ending of that number (that is, `st', `nd',
1230 `rd' or `th', as appropriate. The anniversary of February 29 is considered
1231 to be March 1 in non-leap years."
1232 (let* ((d (if european-calendar-style
1235 (m (if european-calendar-style
1238 (y (extract-calendar-year date))
1240 (if (and (= m 2) (= d 29) (not (calendar-leap-year-p y)))
1243 (if (and (> diff 0) (calendar-date-equal (list m d y) date))
1244 (format entry diff (diary-ordinal-suffix diff)))))
1246 (defun diary-cyclic (n month day year)
1247 "Cycle diary entry--entry applies every N days starting at MONTH, DAY, YEAR.
1248 If `european-calendar-style' is t, parameters are N, DAY, MONTH, YEAR.
1249 ENTRY can contain `%d' or `%d%s'; the %d will be replaced by the number of
1250 years since the MONTH DAY, YEAR and the %s will be replaced by the ordinal
1251 ending of that number (that is, `st', `nd', `rd' or `th', as appropriate."
1252 (let* ((d (if european-calendar-style
1255 (m (if european-calendar-style
1258 (diff (- (calendar-absolute-from-gregorian date)
1259 (calendar-absolute-from-gregorian
1262 (if (and (>= diff 0) (zerop (% diff n)))
1263 (format entry cycle (diary-ordinal-suffix cycle)))))
1265 (defun diary-ordinal-suffix (n)
1266 "Ordinal suffix for N. (That is, `st', `nd', `rd', or `th', as appropriate.)"
1267 (if (or (memq (% n 100) '(11 12 13))
1270 (aref ["th" "st" "nd" "rd"] (% n 10))))
1272 (defun diary-day-of-year ()
1273 "Day of year and number of days remaining in the year of date diary entry."
1274 (let* ((year (extract-calendar-year date))
1275 (day (calendar-day-number date))
1276 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
1277 (format "Day %d of %d; %d day%s remaining in the year"
1278 day year days-remaining (if (= days-remaining 1) "" "s"))))
1280 (defun diary-iso-date ()
1281 "ISO calendar equivalent of date diary entry."
1282 (let ((day (% (calendar-absolute-from-gregorian date) 7))
1283 (iso-date (calendar-iso-from-absolute
1284 (calendar-absolute-from-gregorian date))))
1285 (format "ISO date: Day %s of week %d of %d."
1286 (if (zerop day) 7 day)
1287 (extract-calendar-month iso-date)
1288 (extract-calendar-year iso-date))))
1290 (defun diary-islamic-date ()
1291 "Islamic calendar equivalent of date diary entry."
1292 (let* ((calendar-date-display-form
1293 (if european-calendar-style
1294 '(day " " monthname " " year)
1295 '(monthname " " day ", " year)))
1296 (i-date (calendar-islamic-from-absolute
1297 (calendar-absolute-from-gregorian date)))
1298 (calendar-month-name-array calendar-islamic-month-name-array))
1299 (if (>= (extract-calendar-year i-date) 1)
1300 (format "Islamic date: %s" (calendar-date-string i-date)))))
1302 (defun diary-hebrew-date ()
1303 "Hebrew calendar equivalent of date diary entry."
1304 (let* ((calendar-date-display-form
1305 (if european-calendar-style
1306 '(day " " monthname " " year)
1307 '(monthname " " day ", " year)))
1308 (h-date (calendar-hebrew-from-absolute
1309 (calendar-absolute-from-gregorian date)))
1310 (calendar-month-name-array
1311 (if (hebrew-calendar-leap-year-p
1312 (extract-calendar-year h-date))
1313 calendar-hebrew-month-name-array-leap-year
1314 calendar-hebrew-month-name-array-common-year)))
1315 (format "Hebrew date: %s" (calendar-date-string h-date))))
1317 (defun diary-french-date ()
1318 "French calendar equivalent of date diary entry."
1319 (let* ((french-date (calendar-french-from-absolute
1320 (calendar-absolute-from-gregorian date)))
1321 (y (extract-calendar-year french-date))
1322 (m (extract-calendar-month french-date))
1323 (d (extract-calendar-day french-date)))
1326 (format "Jour %s de l'Annee %d de la Revolution"
1327 (aref french-calendar-special-days-array (1- d))
1329 (format "Decade %s, %s de %s de l'Annee %d de la Revolution"
1330 (make-string (1+ (/ (1- d) 10)) ?I)
1331 (aref french-calendar-day-name-array (% (1- d) 10))
1332 (aref french-calendar-month-name-array (1- m))
1335 (defun diary-omer ()
1336 "Omer count diary entry--entry applies if date is within 50 days after
1339 (calendar-absolute-from-hebrew
1340 (list 1 15 (+ (extract-calendar-year date) 3760))))
1341 (omer (- (calendar-absolute-from-gregorian date) passover))
1344 (if (and (> omer 0) (< omer 50))
1345 (format "Day %d%s of the omer (until sunset)"
1349 (format ", that is, %d week%s%s"
1351 (if (= week 1) "" "s")
1354 (format " and %d day%s"
1355 day (if (= day 1) "" "s")))))))))
1357 (defun diary-yahrzeit (death-month death-day death-year)
1358 "Yahrzeit diary entry--entry applies if date is yahrzeit or the day before.
1359 Parameters are DEATH-MONTH, DEATH-DAY, DEATH-YEAR; the diary entry is assumed
1360 to be the name of the person. Date of death is on the *civil* calendar;
1361 although the date of death is specified by the civil calendar, the proper
1362 Hebrew calendar yahrzeit is determined. If european-calendar-style is t, the
1363 order of the parameters is changed to DEATH-DAY, DEATH-MONTH, DEATH-YEAR."
1364 (let* ((h-date (calendar-hebrew-from-absolute
1365 (calendar-absolute-from-gregorian
1366 (if european-calendar-style
1367 (list death-day death-month death-year)
1368 (list death-month death-day death-year)))))
1369 (h-month (extract-calendar-month h-date))
1370 (h-day (extract-calendar-day h-date))
1371 (h-year (extract-calendar-year h-date))
1372 (d (calendar-absolute-from-gregorian date))
1373 (yr (extract-calendar-year (calendar-hebrew-from-absolute d)))
1374 (diff (- yr h-year))
1375 (y (hebrew-calendar-yahrzeit h-date yr)))
1376 (if (and (> diff 0) (or (= y d) (= y (1+ d))))
1377 (format "Yahrzeit of %s%s: %d%s anniversary"
1379 (if (= y d) "" " (evening)")
1381 (cond ((= (% diff 10) 1) "st")
1382 ((= (% diff 10) 2) "nd")
1383 ((= (% diff 10) 3) "rd")
1386 (defun diary-rosh-hodesh ()
1387 "Rosh Hodesh diary entry--entry applies if date is Rosh Hodesh, the day
1388 before, or the Saturday before."
1389 (let* ((d (calendar-absolute-from-gregorian date))
1390 (h-date (calendar-hebrew-from-absolute d))
1391 (h-month (extract-calendar-month h-date))
1392 (h-day (extract-calendar-day h-date))
1393 (h-year (extract-calendar-year h-date))
1394 (leap-year (hebrew-calendar-leap-year-p h-year))
1395 (last-day (hebrew-calendar-last-day-of-month h-month h-year))
1398 calendar-hebrew-month-name-array-leap-year
1399 calendar-hebrew-month-name-array-common-year))
1400 (this-month (aref h-month-names (1- h-month)))
1401 (h-yesterday (extract-calendar-day
1402 (calendar-hebrew-from-absolute (1- d)))))
1403 (if (or (= h-day 30) (and (= h-day 1) (/= h-month 7)))
1409 ;; next month must be in the same year since this
1410 ;; month can't be the last month of the year since
1412 (aref h-month-names h-month))
1413 (if (= h-yesterday 30)
1414 (format "%s (second day)" this-month)
1416 (if (= (mod d 7) 6);; Saturday--check for Shabbat Mevarhim
1417 (cond ((and (> h-day 22) (/= h-month 6) (= 29 last-day))
1418 (format "Mevarhim Rosh Hodesh %s (%s)"
1421 (hebrew-calendar-last-month-of-year
1424 (aref calendar-day-name-array (- 29 h-day))))
1425 ((and (< h-day 30) (> h-day 22) (= 30 last-day))
1426 (format "Mevarhim Rosh Hodesh %s (%s-%s)"
1427 (aref h-month-names h-month)
1430 (aref calendar-day-name-array (- 29 h-day)))
1431 (aref calendar-day-name-array
1432 (mod (- 30 h-day) 7)))))
1433 (if (and (= h-day 29) (/= h-month 6))
1434 (format "Erev Rosh Hodesh %s"
1437 (hebrew-calendar-last-month-of-year
1441 (defun diary-parasha ()
1442 "Parasha diary entry--entry applies if date is a Saturday."
1443 (let ((d (calendar-absolute-from-gregorian date)))
1444 (if (= (% d 7) 6);; Saturday
1446 ((h-year (extract-calendar-year
1447 (calendar-hebrew-from-absolute d)))
1449 (calendar-absolute-from-hebrew (list 7 1 h-year)))
1451 (calendar-absolute-from-hebrew (list 1 15 h-year)))
1453 (aref calendar-day-name-array (% rosh-hashannah 7)))
1455 (aref calendar-day-name-array (% passover 7)))
1456 (long-h (hebrew-calendar-long-heshvan-p h-year))
1457 (short-k (hebrew-calendar-short-kislev-p h-year))
1458 (type (cond ((and long-h (not short-k)) "complete")
1459 ((and (not long-h) short-k) "incomplete")
1463 (intern (format "hebrew-calendar-year-%s-%s-%s";; keviah
1464 rosh-hashannah-day type passover-day))))
1465 (first-saturday;; of Hebrew year
1466 (calendar-dayname-on-or-before 6 (+ 6 rosh-hashannah)))
1467 (saturday;; which Saturday of the Hebrew year
1468 (/ (- d first-saturday) 7))
1469 (parasha (aref year-format saturday)))
1473 (if (listp parasha);; Israel differs from diaspora
1475 (format "%s (diaspora), %s (Israel)"
1476 (hebrew-calendar-parasha-name (car parasha))
1477 (hebrew-calendar-parasha-name (cdr parasha)))
1478 (format "%s (Israel)"
1479 (hebrew-calendar-parasha-name (cdr parasha))))
1480 (hebrew-calendar-parasha-name parasha))))))))
1482 (defun add-to-diary-list (date string)
1483 "Add the entry (DATE STRING) to the diary-entries-list.
1484 Do nothing if DATE or STRING is nil."
1486 (setq diary-entries-list
1487 (append diary-entries-list (list (list date string))))))
1489 (defconst hebrew-calendar-parashiot-names
1490 ["Bereshith" "Noah" "Lech L'cha" "Vayera" "Hayei Sarah" "Toledoth"
1491 "Vayetze" "Vayishlah" "Vayeshev" "Mikketz" "Vayiggash" "Vayhi"
1492 "Shemoth" "Vaera" "Bo" "Beshallah" "Yithro" "Mishpatim"
1493 "Terumah" "Tetzavveh" "Ki Tissa" "Vayakhel" "Pekudei" "Vayikra"
1494 "Tzav" "Shemini" "Tazria" "Metzora" "Aharei Moth" "Kedoshim"
1495 "Emor" "Behar" "Behukkotai" "Bemidbar" "Naso" "Behaalot'cha"
1496 "Shelah L'cha" "Korah" "Hukkath" "Balak" "Pinhas" "Mattoth"
1497 "Masei" "Devarim" "Vaethanan" "Ekev" "Reeh" "Shofetim"
1498 "Ki Tetze" "Ki Tavo" "Nitzavim" "Vayelech" "Haazinu"]
1499 "The names of the parashiot in the Torah.")
1501 ;; The seven ordinary year types (keviot)
1503 (defconst hebrew-calendar-year-Saturday-incomplete-Sunday
1504 [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]
1505 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
1506 43 44 45 46 47 48 49 50]
1507 "The structure of the parashiot in a Hebrew year that starts on Saturday,
1508 is `incomplete' (Heshvan and Kislev each have 29 days), and has Passover
1511 (defconst hebrew-calendar-year-Saturday-complete-Tuesday
1512 [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]
1513 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
1514 43 44 45 46 47 48 49 [50 51]]
1515 "The structure of the parashiot in a Hebrew year that starts on Saturday,
1516 is `complete' (Heshvan and Kislev each have 30 days), and has Passover
1519 (defconst hebrew-calendar-year-Monday-incomplete-Tuesday
1520 [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]
1521 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
1522 43 44 45 46 47 48 49 [50 51]]
1523 "The structure of the parashiot in a Hebrew year that starts on Monday,
1524 is `incomplete' (Heshvan and Kislev each have 29 days), and has Passover
1527 (defconst hebrew-calendar-year-Monday-complete-Thursday
1528 [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]
1529 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 (nil . 34) (34.35) (35.36)
1530 (36.37) (37.38) ([38 39].39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
1531 "The structure of the parashiot in a Hebrew year that starts on Monday,
1532 is `complete' (Heshvan and Kislev each have 30 days), and has Passover
1533 start on Thursday.")
1535 (defconst hebrew-calendar-year-Tuesday-regular-Thursday
1536 [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]
1537 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 (nil . 34) (34.35) (35.36)
1538 (36.37) (37.38) ([38 39].39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
1539 "The structure of the parashiot in a Hebrew year that starts on Tuesday,
1540 is `regular' (Heshvan has 29 days and Kislev has 30 days), and has Passover
1541 start on Thursday.")
1543 (defconst hebrew-calendar-year-Thursday-regular-Saturday
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 (nil . 25) (25.[26 27]) ([26 27].[28 29]) ([28 29].30) (30.31)
1546 ([31 32].32) 33 34 35 36 37 38 39 40 [41 42]
1547 43 44 45 46 47 48 49 50]
1548 "The structure of the parashiot in a Hebrew year that starts on Thursday,
1549 is `regular' (Heshvan has 29 days and Kislev has 30 days), and has Passover
1550 start on Saturday.")
1552 (defconst hebrew-calendar-year-Thursday-complete-Sunday
1553 [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
1554 23 24 nil 25 [26 27] [28 29] 30 [31 32] 33 34 35 36 37 38 39 40 [41 42]
1555 43 44 45 46 47 48 49 50]
1556 "The structure of the parashiot in a Hebrew year that starts on Thursday,
1557 is `complete' (Heshvan and Kislev each have 30 days), and has Passover
1560 ;; The seven leap year types (keviot)
1562 (defconst hebrew-calendar-year-Saturday-incomplete-Tuesday
1563 [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
1564 23 24 25 26 27 nil 28 29 30 31 32 33 34 35 36 37 38 39 40 [41 42]
1565 43 44 45 46 47 48 49 [50 51]]
1566 "The structure of the parashiot in a Hebrew year that starts on Saturday,
1567 is `incomplete' (Heshvan and Kislev each have 29 days), and has Passover
1570 (defconst hebrew-calendar-year-Saturday-complete-Thursday
1571 [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
1572 23 24 25 26 27 nil 28 29 30 31 32 33 (nil . 34) (34.35) (35.36) (36.37)
1573 (37.38) ([38 39].39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
1574 "The structure of the parashiot in a Hebrew year that starts on Saturday,
1575 is `complete' (Heshvan and Kislev each have 30 days), and has Passover
1576 start on Thursday.")
1578 (defconst hebrew-calendar-year-Monday-incomplete-Thursday
1579 [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
1580 23 24 25 26 27 nil 28 29 30 31 32 33 (nil . 34) (34.35) (35.36) (36.37)
1581 (37.38) ([38 39].39) 40 [41 42] 43 44 45 46 47 48 49 [50 51]]
1582 "The structure of the parashiot in a Hebrew year that starts on Monday,
1583 is `incomplete' (Heshvan and Kislev each have 29 days), and has Passover
1584 start on Thursday.")
1586 (defconst hebrew-calendar-year-Monday-complete-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 Monday,
1592 is `complete' (Heshvan and Kislev each have 30 days), and has Passover
1593 start on Saturday.")
1595 (defconst hebrew-calendar-year-Tuesday-regular-Saturday
1596 [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
1597 23 24 25 26 27 nil (nil . 28) (28.29) (29.30) (30.31) (31.32) (32.33)
1598 (33.34) (34.35) (35.36) (36.37) (37.38) (38.39) (39.40) (40.41) ([41 42].42)
1599 43 44 45 46 47 48 49 50]
1600 "The structure of the parashiot in a Hebrew year that starts on Tuesday,
1601 is `regular' (Heshvan has 29 days and Kislev has 30 days), and has Passover
1602 start on Saturday.")
1604 (defconst hebrew-calendar-year-Thursday-incomplete-Sunday
1605 [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
1606 23 24 25 26 27 28 nil 29 30 31 32 33 34 35 36 37 38 39 40 41 42
1607 43 44 45 46 47 48 49 50]
1608 "The structure of the parashiot in a Hebrew year that starts on Thursday,
1609 is `incomplete' (Heshvan and Kislev both have 29 days), and has Passover
1612 (defconst hebrew-calendar-year-Thursday-complete-Tuesday
1613 [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
1614 23 24 25 26 27 28 nil 29 30 31 32 33 34 35 36 37 38 39 40 41 42
1615 43 44 45 46 47 48 49 [50 51]]
1616 "The structure of the parashiot in a Hebrew year that starts on Thursday,
1617 is `complete' (Heshvan and Kislev both have 30 days), and has Passover
1620 (defun hebrew-calendar-parasha-name (p)
1621 "Name(s) corresponding to parasha P."
1622 (if (arrayp p);; combined parasha
1624 (aref hebrew-calendar-parashiot-names (aref p 0))
1625 (aref hebrew-calendar-parashiot-names (aref p 1)))
1626 (aref hebrew-calendar-parashiot-names p)))
1628 (defun list-islamic-diary-entries ()
1629 "Add any Islamic date entries from the diary-file to diary-entries-list.
1630 Islamic date diary entries must be prefaced by an islamic-diary-entry-symbol
1631 \(normally an `I'\). The same diary-date-forms govern the style of the Islamic
1632 calendar entries, except that the Islamic month names must be spelled in full.
1633 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being
1634 Dhu al-Hijjah. If an Islamic date diary entry begins with a
1635 diary-nonmarking-symbol the entry will appear in the diary listing, but will
1636 not be marked in the calendar. This function is provided for use with the
1637 nongregorian-diary-listing-hook."
1639 (let ((buffer-read-only nil)
1640 (diary-modified (buffer-modified-p))
1641 (gdate original-date)
1642 (mark (regexp-quote diary-nonmarking-symbol)))
1643 (calendar-for-loop i from 1 to number do
1644 (let* ((d diary-date-forms)
1645 (idate (calendar-islamic-from-absolute
1646 (calendar-absolute-from-gregorian gdate)))
1647 (month (extract-calendar-month idate))
1648 (day (extract-calendar-day idate))
1649 (year (extract-calendar-year idate)))
1652 ((date-form (if (equal (car (car d)) 'backup)
1655 (backup (equal (car (car d)) 'backup))
1658 (calendar-day-name gdate) "\\|"
1659 (substring (calendar-day-name gdate) 0 3) ".?"))
1660 (calendar-month-name-array
1661 calendar-islamic-month-name-array)
1665 (calendar-month-name month)))
1666 (month (concat "\\*\\|0*" (int-to-string month)))
1667 (day (concat "\\*\\|0*" (int-to-string day)))
1670 "\\*\\|0*" (int-to-string year)
1671 (if abbreviated-calendar-year
1672 (concat "\\|" (int-to-string (% year 100)))
1676 "\\(\\`\\|\^M\\|\n\\)" mark "?"
1677 (regexp-quote islamic-diary-entry-symbol)
1679 (mapconcat 'eval date-form "\\)\\(")
1681 (case-fold-search t))
1682 (goto-char (point-min))
1683 (while (re-search-forward regexp nil t)
1684 (if backup (re-search-backward "\\<" nil t))
1685 (if (and (or (char-equal (preceding-char) ?\^M)
1686 (char-equal (preceding-char) ?\n))
1687 (not (looking-at " \\|\^I")))
1688 ;; Diary entry that consists only of date.
1690 ;; Found a nonempty diary entry--make it visible and
1691 ;; add it to the list.
1692 (let ((entry-start (point))
1694 (re-search-backward "\^M\\|\n\\|\\`")
1695 (setq date-start (point))
1696 (re-search-forward "\^M\\|\n" nil t 2)
1697 (while (looking-at " \\|\^I")
1698 (re-search-forward "\^M\\|\n" nil t))
1700 (subst-char-in-region date-start (point) ?\^M ?\n t)
1702 gdate (buffer-substring entry-start (point)))))))
1705 (calendar-gregorian-from-absolute
1706 (1+ (calendar-absolute-from-gregorian gdate)))))
1707 (set-buffer-modified-p diary-modified))
1708 (goto-char (point-min))))
1710 (defun mark-islamic-diary-entries ()
1711 "Mark days in the calendar window that have Islamic date diary entries.
1712 Each entry in diary-file (or included files) visible in the calendar window
1713 is marked. Islamic date entries are prefaced by a islamic-diary-entry-symbol
1714 \(normally an `I'\). The same diary-date-forms govern the style of the Islamic
1715 calendar entries, except that the Islamic month names must be spelled in full.
1716 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being
1717 Dhu al-Hijjah. Islamic date diary entries that begin with a
1718 diary-nonmarking-symbol will not be marked in the calendar. This function is
1719 provided for use as part of the nongregorian-diary-marking-hook."
1720 (let ((d diary-date-forms))
1723 ((date-form (if (equal (car (car d)) 'backup)
1725 (car d)));; ignore 'backup directive
1726 (dayname (diary-name-pattern calendar-day-name-array))
1729 (diary-name-pattern calendar-islamic-month-name-array t)
1731 (month "[0-9]+\\|\\*")
1732 (day "[0-9]+\\|\\*")
1733 (year "[0-9]+\\|\\*")
1734 (l (length date-form))
1735 (d-name-pos (- l (length (memq 'dayname date-form))))
1736 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos)))
1737 (m-name-pos (- l (length (memq 'monthname date-form))))
1738 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos)))
1739 (d-pos (- l (length (memq 'day date-form))))
1740 (d-pos (if (/= l d-pos) (+ 2 d-pos)))
1741 (m-pos (- l (length (memq 'month date-form))))
1742 (m-pos (if (/= l m-pos) (+ 2 m-pos)))
1743 (y-pos (- l (length (memq 'year date-form))))
1744 (y-pos (if (/= l y-pos) (+ 2 y-pos)))
1747 "\\(\\`\\|\^M\\|\n\\)"
1748 (regexp-quote islamic-diary-entry-symbol)
1750 (mapconcat 'eval date-form "\\)\\(")
1752 (case-fold-search t))
1753 (goto-char (point-min))
1754 (while (re-search-forward regexp nil t)
1758 (match-beginning d-name-pos)
1759 (match-end d-name-pos))))
1763 (match-beginning m-name-pos)
1764 (match-end m-name-pos))))
1768 (match-beginning m-pos)
1774 (match-beginning d-pos)
1779 (match-beginning y-pos)
1780 (match-end y-pos))))
1783 (if (and (= (length y-str) 2)
1784 abbreviated-calendar-year)
1786 (extract-calendar-year
1787 (calendar-islamic-from-absolute
1788 (calendar-absolute-from-gregorian
1789 (calendar-current-date)))))
1790 (y (+ (string-to-int y-str)
1791 (* 100 (/ current-y 100)))))
1792 (if (> (- y current-y) 50)
1794 (if (> (- current-y y) 50)
1797 (string-to-int y-str)))))
1799 (mark-calendar-days-named
1800 (cdr (assoc (capitalize (substring dd-name 0 3))
1801 (calendar-make-alist
1802 calendar-day-name-array
1804 '(lambda (x) (substring x 0 3))))))
1806 (if (string-equal mm-name "*")
1810 (capitalize mm-name)
1811 (calendar-make-alist
1812 calendar-islamic-month-name-array))))))
1813 (mark-islamic-calendar-date-pattern mm dd yy)))))
1816 (defun mark-islamic-calendar-date-pattern (month day year)
1817 "Mark all dates in the calendar window that conform to the Islamic date
1818 MONTH/DAY/YEAR. A value of 0 in any position is a wild-card."
1820 (set-buffer calendar-buffer)
1821 (if (and (/= 0 month) (/= 0 day))
1823 ;; Fully specified Islamic date.
1824 (let ((date (calendar-gregorian-from-absolute
1825 (calendar-absolute-from-islamic
1826 (list month day year)))))
1827 (if (calendar-date-is-visible-p date)
1828 (mark-visible-calendar-date date)))
1829 ;; Month and day in any year--this taken from the holiday stuff.
1830 (let* ((islamic-date (calendar-islamic-from-absolute
1831 (calendar-absolute-from-gregorian
1832 (list displayed-month 15 displayed-year))))
1833 (m (extract-calendar-month islamic-date))
1834 (y (extract-calendar-year islamic-date))
1837 nil;; Islamic calendar doesn't apply.
1838 (increment-calendar-month m y (- 10 month))
1839 (if (> m 7);; Islamic date might be visible
1840 (let ((date (calendar-gregorian-from-absolute
1841 (calendar-absolute-from-islamic
1842 (list month day y)))))
1843 (if (calendar-date-is-visible-p date)
1844 (mark-visible-calendar-date date)))))))
1845 ;; Not one of the simple cases--check all visible dates for match.
1846 ;; Actually, the following code takes care of ALL of the cases, but
1847 ;; it's much too slow to be used for the simple (common) cases.
1848 (let ((m displayed-month)
1852 (increment-calendar-month m y -1)
1854 (calendar-absolute-from-gregorian
1856 (increment-calendar-month m y 2)
1858 (calendar-absolute-from-gregorian
1859 (list m (calendar-last-day-of-month m y) y)))
1860 (calendar-for-loop date from first-date to last-date do
1861 (let* ((i-date (calendar-islamic-from-absolute date))
1862 (i-month (extract-calendar-month i-date))
1863 (i-day (extract-calendar-day i-date))
1864 (i-year (extract-calendar-year i-date)))
1865 (and (or (zerop month)
1871 (mark-visible-calendar-date
1872 (calendar-gregorian-from-absolute date)))))))))
1874 (defun make-diary-entry (string &optional nonmarking file)
1875 "Insert a diary entry STRING which may be NONMARKING in FILE.
1876 If omitted, NONMARKING defaults to nil and FILE defaults to diary-file."
1877 (find-file-other-window
1878 (substitute-in-file-name (if file file diary-file)))
1879 (goto-char (point-max))
1882 (if nonmarking diary-nonmarking-symbol "")
1885 (defun insert-diary-entry (arg)
1886 "Insert a diary entry for the date indicated by point.
1887 Prefix arg will make the entry nonmarking."
1889 (let* ((calendar-date-display-form
1890 (if european-calendar-style
1891 '(day " " monthname " " year)
1892 '(monthname " " day ", " year))))
1894 (calendar-date-string
1895 (or (calendar-cursor-to-date)
1896 (error "Cursor is not on a date!"))
1900 (defun insert-weekly-diary-entry (arg)
1901 "Insert a weekly diary entry for the day of the week indicated by point.
1902 Prefix arg will make the entry nonmarking."
1906 (or (calendar-cursor-to-date)
1907 (error "Cursor is not on a date!")))
1910 (defun insert-monthly-diary-entry (arg)
1911 "Insert a monthly diary entry for the day of the month indicated by point.
1912 Prefix arg will make the entry nonmarking."
1914 (let* ((calendar-date-display-form
1915 (if european-calendar-style
1919 (calendar-date-string
1920 (or (calendar-cursor-to-date)
1921 (error "Cursor is not on a date!"))
1925 (defun insert-yearly-diary-entry (arg)
1926 "Insert an annual diary entry for the day of the year indicated by point.
1927 Prefix arg will make the entry nonmarking."
1929 (let* ((calendar-date-display-form
1930 (if european-calendar-style
1931 '(day " " monthname)
1932 '(monthname " " day))))
1934 (calendar-date-string
1935 (or (calendar-cursor-to-date)
1936 (error "Cursor is not on a date!"))
1940 (defun insert-anniversary-diary-entry (arg)
1941 "Insert an anniversary diary entry for the date given by point.
1942 Prefix arg will make the entry nonmarking."
1944 (let* ((calendar-date-display-form
1945 (if european-calendar-style
1946 '(day " " month " " year)
1947 '(month " " day " " year))))
1949 (format "%s(diary-anniversary %s)"
1950 sexp-diary-entry-symbol
1951 (calendar-date-string
1952 (or (calendar-cursor-to-date)
1953 (error "Cursor is not on a date!"))))
1956 (defun insert-block-diary-entry (arg)
1957 "Insert a block diary entry for the days between the point and marked date.
1958 Prefix arg will make the entry nonmarking."
1960 (let* ((calendar-date-display-form
1961 (if european-calendar-style
1962 '(day " " month " " year)
1963 '(month " " day " " year)))
1964 (cursor (or (calendar-cursor-to-date)
1965 (error "Cursor is not on a date!")))
1966 (mark (or (car calendar-mark-ring)
1967 (error "No mark set in this buffer")))
1970 (if (< (calendar-absolute-from-gregorian mark)
1971 (calendar-absolute-from-gregorian cursor))
1977 (format "%s(diary-block %s %s)"
1978 sexp-diary-entry-symbol
1979 (calendar-date-string start)
1980 (calendar-date-string end))
1983 (defun insert-cyclic-diary-entry (arg)
1984 "Insert a cyclic diary entry starting at the date given by point.
1985 Prefix arg will make the entry nonmarking."
1987 (let* ((calendar-date-display-form
1988 (if european-calendar-style
1989 '(day " " month " " year)
1990 '(month " " day " " year))))
1992 (format "%s(diary-cyclic %d %s)"
1993 sexp-diary-entry-symbol
1994 (calendar-read "Repeat every how many days: "
1995 '(lambda (x) (> x 0)))
1996 (calendar-date-string
1997 (or (calendar-cursor-to-date)
1998 (error "Cursor is not on a date!"))))
2001 (defun insert-hebrew-diary-entry (arg)
2002 "Insert a diary entry for the Hebrew date corresponding to the date
2003 indicated by point. Prefix arg will make the entry nonmarking."
2005 (let* ((calendar-date-display-form
2006 (if european-calendar-style
2007 '(day " " monthname " " year)
2008 '(monthname " " day ", " year)))
2009 (calendar-month-name-array
2010 calendar-hebrew-month-name-array-leap-year))
2013 hebrew-diary-entry-symbol
2014 (calendar-date-string
2015 (calendar-hebrew-from-absolute
2016 (calendar-absolute-from-gregorian
2017 (or (calendar-cursor-to-date)
2018 (error "Cursor is not on a date!"))))))
2021 (defun insert-monthly-hebrew-diary-entry (arg)
2022 "Insert a monthly diary entry for the day of the Hebrew month corresponding
2023 to the date indicated by point. Prefix arg will make the entry nonmarking."
2025 (let* ((calendar-date-display-form
2026 (if european-calendar-style '(day " * ") '("* " day )))
2027 (calendar-month-name-array
2028 calendar-hebrew-month-name-array-leap-year))
2031 hebrew-diary-entry-symbol
2032 (calendar-date-string
2033 (calendar-hebrew-from-absolute
2034 (calendar-absolute-from-gregorian
2035 (or (calendar-cursor-to-date)
2036 (error "Cursor is not on a date!"))))))
2039 (defun insert-yearly-hebrew-diary-entry (arg)
2040 "Insert an annual diary entry for the day of the Hebrew year corresponding
2041 to the date indicated by point. Prefix arg will make the entry nonmarking."
2043 (let* ((calendar-date-display-form
2044 (if european-calendar-style
2045 '(day " " monthname)
2046 '(monthname " " day)))
2047 (calendar-month-name-array
2048 calendar-hebrew-month-name-array-leap-year))
2051 hebrew-diary-entry-symbol
2052 (calendar-date-string
2053 (calendar-hebrew-from-absolute
2054 (calendar-absolute-from-gregorian
2055 (or (calendar-cursor-to-date)
2056 (error "Cursor is not on a date!"))))))
2059 (defun insert-islamic-diary-entry (arg)
2060 "Insert a diary entry for the Islamic date corresponding to the date
2061 indicated by point. Prefix arg will make the entry nonmarking."
2063 (let* ((calendar-date-display-form
2064 (if european-calendar-style
2065 '(day " " monthname " " year)
2066 '(monthname " " day ", " year)))
2067 (calendar-month-name-array calendar-islamic-month-name-array))
2070 islamic-diary-entry-symbol
2071 (calendar-date-string
2072 (calendar-islamic-from-absolute
2073 (calendar-absolute-from-gregorian
2074 (or (calendar-cursor-to-date)
2075 (error "Cursor is not on a date!"))))))
2078 (defun insert-monthly-islamic-diary-entry (arg)
2079 "Insert a monthly diary entry for the day of the Islamic month corresponding
2080 to the date indicated by point. Prefix arg will make the entry nonmarking."
2082 (let* ((calendar-date-display-form
2083 (if european-calendar-style '(day " * ") '("* " day )))
2084 (calendar-month-name-array calendar-islamic-month-name-array))
2087 islamic-diary-entry-symbol
2088 (calendar-date-string
2089 (calendar-islamic-from-absolute
2090 (calendar-absolute-from-gregorian
2091 (or (calendar-cursor-to-date)
2092 (error "Cursor is not on a date!"))))))
2095 (defun insert-yearly-islamic-diary-entry (arg)
2096 "Insert an annual diary entry for the day of the Islamic year corresponding
2097 to the date indicated by point. Prefix arg will make the entry nonmarking."
2099 (let* ((calendar-date-display-form
2100 (if european-calendar-style
2101 '(day " " monthname)
2102 '(monthname " " day)))
2103 (calendar-month-name-array calendar-islamic-month-name-array))
2106 islamic-diary-entry-symbol
2107 (calendar-date-string
2108 (calendar-islamic-from-absolute
2109 (calendar-absolute-from-gregorian
2110 (or (calendar-cursor-to-date)
2111 (error "Cursor is not on a date!"))))))
2116 ;;; diary.el ends here