1 ;;; diary-lib.el --- diary functions
3 ;; Copyright (C) 1989, 1990, 1992, 1993, 1994, 1995, 2003, 2004, 2005
4 ;; Free Software Foundation, Inc.
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This collection of functions implements the diary features as described
32 ;; Comments, corrections, and improvements should be sent to
33 ;; Edward M. Reingold Department of Computer Science
34 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
35 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
36 ;; Urbana, Illinois 61801
42 (defun diary-check-diary-file ()
43 "Check that the file specified by `diary-file' exists and is readable.
44 If so, return the expanded file name, otherwise signal an error."
45 (let ((d-file (substitute-in-file-name diary-file
)))
46 (if (and d-file
(file-exists-p d-file
))
47 (if (file-readable-p d-file
)
49 (error "Diary file `%s' is not readable" diary-file
))
50 (error "Diary file `%s' does not exist" diary-file
))))
53 (defun diary (&optional arg
)
54 "Generate the diary window for ARG days starting with the current date.
55 If no argument is provided, the number of days of diary entries is governed
56 by the variable `number-of-diary-entries'. A value of ARG less than 1
57 does nothing. This function is suitable for execution in a `.emacs' file."
59 (diary-check-diary-file)
60 (let ((date (calendar-current-date)))
61 (diary-list-entries date
(if arg
(prefix-numeric-value arg
)))))
63 (define-obsolete-function-alias 'view-diary-entries
'diary-view-entries
)
64 (defun diary-view-entries (&optional arg
)
65 "Prepare and display a buffer with diary entries.
66 Searches the file named in `diary-file' for entries that
67 match ARG days starting with the date indicated by the cursor position
68 in the displayed three-month calendar."
70 (diary-check-diary-file)
71 (diary-list-entries (calendar-cursor-to-date t
) arg
))
73 (defun view-other-diary-entries (arg d-file
)
74 "Prepare and display buffer of diary entries from an alternative diary file.
75 Searches for entries that match ARG days, starting with the date indicated
76 by the cursor position in the displayed three-month calendar.
77 D-FILE specifies the file to use as the diary file."
79 (list (prefix-numeric-value current-prefix-arg
)
80 (read-file-name "Enter diary file name: " default-directory nil t
)))
81 (let ((diary-file d-file
))
82 (view-diary-entries arg
)))
84 (autoload 'check-calendar-holidays
"holidays"
85 "Check the list of holidays for any that occur on DATE.
86 The value returned is a list of strings of relevant holiday descriptions.
87 The holidays are those in the list `calendar-holidays'.")
89 (autoload 'calendar-holiday-list
"holidays"
90 "Form the list of holidays that occur on dates in the calendar window.
91 The holidays are those in the list `calendar-holidays'.")
93 (autoload 'diary-french-date
"cal-french"
94 "French calendar equivalent of date diary entry.")
96 (autoload 'diary-mayan-date
"cal-mayan"
97 "Mayan calendar equivalent of date diary entry.")
99 (autoload 'diary-iso-date
"cal-iso"
100 "ISO calendar equivalent of date diary entry.")
102 (autoload 'diary-julian-date
"cal-julian"
103 "Julian calendar equivalent of date diary entry.")
105 (autoload 'diary-astro-day-number
"cal-julian"
106 "Astronomical (Julian) day number diary entry.")
108 (autoload 'diary-chinese-date
"cal-china"
109 "Chinese calendar equivalent of date diary entry.")
111 (autoload 'diary-islamic-date
"cal-islam"
112 "Islamic calendar equivalent of date diary entry.")
114 (autoload 'list-islamic-diary-entries
"cal-islam"
115 "Add any Islamic date entries from the diary file to `diary-entries-list'.")
117 (autoload 'mark-islamic-diary-entries
"cal-islam"
118 "Mark days in the calendar window that have Islamic date diary entries.")
120 (autoload 'mark-islamic-calendar-date-pattern
"cal-islam"
121 "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR.")
123 (autoload 'diary-bahai-date
"cal-bahai"
124 "Baha'i calendar equivalent of date diary entry."
127 (autoload 'list-bahai-diary-entries
"cal-bahai"
128 "Add any Baha'i date entries from the diary file to `diary-entries-list'."
131 (autoload 'mark-bahai-diary-entries
"cal-bahai"
132 "Mark days in the calendar window that have Baha'i date diary entries."
135 (autoload 'mark-bahai-calendar-date-pattern
"cal-bahai"
136 "Mark dates in calendar window that conform to Baha'i date MONTH/DAY/YEAR."
139 (autoload 'diary-hebrew-date
"cal-hebrew"
140 "Hebrew calendar equivalent of date diary entry.")
142 (autoload 'diary-omer
"cal-hebrew"
143 "Omer count diary entry.")
145 (autoload 'diary-yahrzeit
"cal-hebrew"
146 "Yahrzeit diary entry--entry applies if date is yahrzeit or the day before.")
148 (autoload 'diary-parasha
"cal-hebrew"
149 "Parasha diary entry--entry applies if date is a Saturday.")
151 (autoload 'diary-rosh-hodesh
"cal-hebrew"
152 "Rosh Hodesh diary entry.")
154 (autoload 'list-hebrew-diary-entries
"cal-hebrew"
155 "Add any Hebrew date entries from the diary file to `diary-entries-list'.")
157 (autoload 'mark-hebrew-diary-entries
"cal-hebrew"
158 "Mark days in the calendar window that have Hebrew date diary entries.")
160 (autoload 'mark-hebrew-calendar-date-pattern
"cal-hebrew"
161 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR.")
163 (autoload 'diary-coptic-date
"cal-coptic"
164 "Coptic calendar equivalent of date diary entry.")
166 (autoload 'diary-ethiopic-date
"cal-coptic"
167 "Ethiopic calendar equivalent of date diary entry.")
169 (autoload 'diary-persian-date
"cal-persia"
170 "Persian calendar equivalent of date diary entry.")
172 (autoload 'diary-phases-of-moon
"lunar" "Moon phases diary entry.")
174 (autoload 'diary-sunrise-sunset
"solar"
175 "Local time of sunrise and sunset as a diary entry.")
177 (autoload 'diary-sabbath-candles
"solar"
178 "Local time of candle lighting diary entry--applies if date is a Friday.
179 No diary entry if there is no sunset on that date.")
181 (defvar diary-syntax-table
182 (let ((st (copy-syntax-table (standard-syntax-table))))
183 (modify-syntax-entry ?
* "w" st
)
184 (modify-syntax-entry ?
: "w" st
)
186 "The syntax table used when parsing dates in the diary file.
187 It is the standard syntax table used in Fundamental mode, but with the
188 syntax of `*' and `:' changed to be word constituents.")
190 (defvar diary-entries-list
)
191 (defvar displayed-year
)
192 (defvar displayed-month
)
197 (defvar original-date
)
199 (defun diary-attrtype-convert (attrvalue type
)
200 "Convert string ATTRVALUE to TYPE appropriate for a face description.
201 Valid TYPEs are: string, symbol, int, stringtnil, tnil."
203 (setq ret
(cond ((eq type
'string
) attrvalue
)
204 ((eq type
'symbol
) (read attrvalue
))
205 ((eq type
'int
) (string-to-number attrvalue
))
206 ((eq type
'stringtnil
)
207 (cond ((string= "t" attrvalue
) t
)
208 ((string= "nil" attrvalue
) nil
)
211 (cond ((string= "t" attrvalue
) t
)
212 ((string= "nil" attrvalue
) nil
)))))
213 ; (message "(%s)[%s]=[%s]" (print type) attrvalue ret)
217 (defun diary-pull-attrs (entry fileglobattrs
)
218 "Pull the face-related attributes off the entry, merge with the
219 fileglobattrs, and return the (possibly modified) entry and face
220 data in a list of attrname attrvalue values.
221 The entry will be modified to drop all tags that are used for face matching.
222 If entry is nil, then the fileglobattrs are being searched for,
223 the fileglobattrs variable is ignored, and
224 diary-glob-file-regexp-prefix is prepended to the regexps before each
227 (let (regexp regnum attrname attr-list attrname attrvalue type
232 attr-list diary-face-attrs
)
234 (goto-char (point-min))
235 (setq attr
(car attr-list
)
238 attrname
(nth 2 attr
)
240 regexp
(concat diary-glob-file-regexp-prefix regexp
))
242 (if (re-search-forward regexp
(point-max) t
)
243 (setq attrvalue
(match-string-no-properties regnum
)))
245 (setq attrvalue
(diary-attrtype-convert attrvalue type
)))
246 (setq ret-attr
(append ret-attr
(list attrname attrvalue
))))
247 (setq attr-list
(cdr attr-list
)))
248 (setq fileglobattrs ret-attr
))
250 (setq ret-attr fileglobattrs
251 attr-list diary-face-attrs
)
253 (goto-char (point-min))
254 (setq attr
(car attr-list
)
257 attrname
(nth 2 attr
)
260 (if (string-match regexp entry
)
262 (setq attrvalue
(match-string-no-properties regnum entry
))
263 (setq entry
(replace-match "" t t entry
))))
265 (setq attrvalue
(diary-attrtype-convert attrvalue type
)))
266 (setq ret-attr
(append ret-attr
(list attrname attrvalue
))))
267 (setq attr-list
(cdr attr-list
)))))
268 (list entry ret-attr
))))
271 ;; This can be removed once the kill/yank treatment of invisible text
272 ;; (see etc/TODO) is fixed. -- gm
273 (defcustom diary-header-line-flag t
274 "If non-nil, `diary-simple-display' will show a header line.
275 The format of the header is specified by `diary-header-line-format'."
280 (defvar diary-selective-display nil
)
282 (defcustom diary-header-line-format
283 '(:eval
(calendar-string-spread
284 (list (if diary-selective-display
285 "Selective display active - press \"s\" in calendar \
289 "Format of the header line displayed by `diary-simple-display'.
290 Only used if `diary-header-line-flag' is non-nil."
295 (defvar diary-saved-point
) ; internal
298 (defcustom number-of-diary-entries
1
299 "Specifies how many days of diary entries are to be displayed initially.
300 This variable affects the diary display when the command \\[diary] is used,
301 or if the value of the variable `view-diary-entries-initially' is t. For
302 example, if the default value 1 is used, then only the current day's diary
303 entries will be displayed. If the value 2 is used, then both the current
304 day's and the next day's entries will be displayed.
306 The value can also be a vector such as [0 2 2 2 2 4 1]; this value
307 says to display no diary entries on Sunday, the display the entries
308 for the current date and the day after on Monday through Thursday,
309 display Friday through Monday's entries on Friday, and display only
310 Saturday's entries on Saturday.
312 This variable does not affect the diary display with the `d' command
313 from the calendar; in that case, the prefix argument controls the
314 number of days of diary entries displayed."
315 :type
'(choice (integer :tag
"Entries")
316 (vector :value
[0 0 0 0 0 0 0]
317 (integer :tag
"Sunday")
318 (integer :tag
"Monday")
319 (integer :tag
"Tuesday")
320 (integer :tag
"Wednesday")
321 (integer :tag
"Thursday")
322 (integer :tag
"Friday")
323 (integer :tag
"Saturday")))
326 (define-obsolete-function-alias 'list-diary-entries
'diary-list-entries
)
327 (defun diary-list-entries (date number
&optional list-only
)
328 "Create and display a buffer containing the relevant lines in `diary-file'.
329 The arguments are DATE and NUMBER; the entries selected are those
330 for NUMBER days starting with date DATE. The other entries are hidden
331 using selective display. If NUMBER is less than 1, this function does nothing.
333 Returns a list of all relevant diary entries found, if any, in order by date.
334 The list entries have the form ((MONTH DAY YEAR) STRING SPECIFIER) where
335 \(MONTH DAY YEAR) is the date of the entry, STRING is the entry text, and
336 SPECIFIER is the applicability. If the variable `diary-list-include-blanks'
337 is t, this list includes a dummy diary entry consisting of the empty string
338 for a date with no diary entries.
340 After the list is prepared, the hooks `nongregorian-diary-listing-hook',
341 `list-diary-entries-hook', `diary-display-hook', and `diary-hook' are run.
342 These hooks have the following distinct roles:
344 `nongregorian-diary-listing-hook' can cull dates from the diary
345 and each included file. Usually used for Hebrew or Islamic
346 diary entries in files. Applied to *each* file.
348 `list-diary-entries-hook' adds or manipulates diary entries from
349 external sources. Used, for example, to include diary entries
350 from other files or to sort the diary entries. Invoked *once* only,
351 before the display hook is run.
353 `diary-display-hook' does the actual display of information. If this is
354 nil, simple-diary-display will be used. Use add-hook to set this to
355 fancy-diary-display, if desired. If you want no diary display, use
356 add-hook to set this to ignore.
358 `diary-hook' is run last. This can be used for an appointment
359 notification function.
361 If LIST-ONLY is non-nil don't modify or display the buffer, only return a list."
363 (setq number
(if (vectorp number-of-diary-entries
)
364 (aref number-of-diary-entries
(calendar-day-of-week date
))
365 number-of-diary-entries
)))
367 (let ((original-date date
);; save for possible use in the hooks
370 (date-string (calendar-date-string date
))
371 (d-file (substitute-in-file-name diary-file
)))
372 (message "Preparing diary...")
374 (let ((diary-buffer (find-buffer-visiting d-file
)))
375 (if (not diary-buffer
)
376 (set-buffer (find-file-noselect d-file t
))
377 (set-buffer diary-buffer
)
378 (or (verify-visited-file-modtime diary-buffer
)
379 (revert-buffer t t
))))
380 ;; Setup things like the header-line-format and invisibility-spec.
381 (when (eq major-mode
'fundamental-mode
) (diary-mode))
382 ;; d-s-p is passed to the diary display function.
383 (let ((diary-saved-point (point)))
385 (setq file-glob-attrs
(nth 1 (diary-pull-attrs nil
"")))
386 (with-syntax-table diary-syntax-table
387 (let ((mark (regexp-quote diary-nonmarking-symbol
)))
388 (goto-char (point-min))
390 (let ((ol (make-overlay (point-min) (point-max) nil t nil
)))
391 (set (make-local-variable 'diary-selective-display
) t
)
392 (overlay-put ol
'invisible
'diary
)
393 (overlay-put ol
'evaporate t
)))
395 i from
1 to number do
396 (let ((month (extract-calendar-month date
))
397 (day (extract-calendar-day date
))
398 (year (extract-calendar-year date
))
399 (entry-found (list-sexp-diary-entries date
)))
400 (dolist (date-form diary-date-forms
)
402 ((backup (when (eq (car date-form
) 'backup
)
403 (setq date-form
(cdr date-form
))
406 (format "%s\\|%s\\.?"
407 (calendar-day-name date
)
408 (calendar-day-name date
'abbrev
)))
410 (format "\\*\\|%s\\|%s\\.?"
411 (calendar-month-name month
)
412 (calendar-month-name month
'abbrev
)))
413 (month (concat "\\*\\|0*" (int-to-string month
)))
414 (day (concat "\\*\\|0*" (int-to-string day
)))
417 "\\*\\|0*" (int-to-string year
)
418 (if abbreviated-calendar-year
419 (concat "\\|" (format "%02d" (% year
100)))
423 "\\(\\`\\|\^M\\|\n\\)" mark
"?\\("
424 (mapconcat 'eval date-form
"\\)\\(?:")
426 (case-fold-search t
))
427 (goto-char (point-min))
428 (while (re-search-forward regexp nil t
)
429 (if backup
(re-search-backward "\\<" nil t
))
430 (if (and (or (char-equal (preceding-char) ?\^M
)
431 (char-equal (preceding-char) ?
\n))
432 (not (looking-at " \\|\^I")))
433 ;; Diary entry that consists only of date.
435 ;; Found a nonempty diary entry--make it
436 ;; visible and add it to the list.
438 (let ((entry-start (point))
440 (re-search-backward "\^M\\|\n\\|\\`")
441 (setq date-start
(point))
442 (re-search-forward "\^M\\|\n" nil t
2)
443 (while (looking-at " \\|\^I")
444 (re-search-forward "\^M\\|\n" nil t
))
447 (remove-overlays date-start
(point)
449 (setq entry
(buffer-substring entry-start
(point))
450 temp
(diary-pull-attrs entry file-glob-attrs
)
456 (1+ date-start
) (1- entry-start
))
457 (copy-marker entry-start
) (nth 1 temp
)))))))
459 (not diary-list-include-blanks
)
460 (setq diary-entries-list
461 (append diary-entries-list
462 (list (list date
"" "" "" "")))))
464 (calendar-gregorian-from-absolute
465 (1+ (calendar-absolute-from-gregorian date
))))
466 (setq entry-found nil
)))))
467 (goto-char (point-min))
468 (run-hooks 'nongregorian-diary-listing-hook
469 'list-diary-entries-hook
)
471 (if diary-display-hook
472 (run-hooks 'diary-display-hook
)
473 (simple-diary-display)))
474 (run-hooks 'diary-hook
)
475 diary-entries-list
))))))
477 (defun diary-unhide-everything ()
478 (kill-local-variable 'diary-selective-display
)
479 (remove-overlays (point-min) (point-max) 'invisible
'diary
)
480 (kill-local-variable 'mode-line-format
))
482 (defun include-other-diary-files ()
483 "Include the diary entries from other diary files with those of diary-file.
484 This function is suitable for use in `list-diary-entries-hook';
485 it enables you to use shared diary files together with your own.
486 The files included are specified in the diaryfile by lines of this form:
487 #include \"filename\"
488 This is recursive; that is, #include directives in diary files thus included
489 are obeyed. You can change the `#include' to some other string by
490 changing the variable `diary-include-string'."
491 (goto-char (point-min))
492 (while (re-search-forward
494 "\\(?:\\`\\|\^M\\|\n\\)"
495 (regexp-quote diary-include-string
)
498 (let* ((diary-file (substitute-in-file-name
499 (match-string-no-properties 1)))
500 (diary-list-include-blanks nil
)
501 (list-diary-entries-hook 'include-other-diary-files
)
502 (diary-display-hook 'ignore
)
504 (if (file-exists-p diary-file
)
505 (if (file-readable-p diary-file
)
507 (setq diary-entries-list
508 (append diary-entries-list
509 (list-diary-entries original-date number
)))
510 (with-current-buffer (find-buffer-visiting diary-file
)
511 (diary-unhide-everything)))
513 (message "Can't read included diary file %s" diary-file
)
516 (message "Can't find included diary file %s" diary-file
)
518 (goto-char (point-min)))
520 (defun simple-diary-display ()
521 "Display the diary buffer if there are any relevant entries or holidays."
522 (let* ((holiday-list (if holidays-in-diary-buffer
523 (check-calendar-holidays original-date
)))
524 (hol-string (format "%s%s%s"
526 (if holiday-list
": " "")
527 (mapconcat 'identity holiday-list
"; ")))
528 (msg (format "No diary entries for %s" hol-string
))
529 ;; If selected window is dedicated (to the calendar),
530 ;; need a new one to display the diary.
531 (pop-up-frames (window-dedicated-p (selected-window))))
532 (calendar-set-mode-line (format "Diary for %s" hol-string
))
533 (if (or (not diary-entries-list
)
534 (and (not (cdr diary-entries-list
))
535 (string-equal (car (cdr (car diary-entries-list
))) "")))
536 (if (< (length msg
) (frame-width))
538 (set-buffer (get-buffer-create holiday-buffer
))
539 (setq buffer-read-only nil
)
540 (calendar-set-mode-line date-string
)
542 (insert (mapconcat 'identity holiday-list
"\n"))
543 (goto-char (point-min))
544 (set-buffer-modified-p nil
)
545 (setq buffer-read-only t
)
546 (display-buffer holiday-buffer
)
547 (message "No diary entries for %s" date-string
))
549 (find-buffer-visiting (substitute-in-file-name diary-file
))
550 (let ((window (display-buffer (current-buffer))))
551 ;; d-s-p is passed from list-diary-entries.
552 (set-window-point window diary-saved-point
)
553 (set-window-start window
(point-min))))
554 (message "Preparing diary...done"))))
556 (defface diary-button
'((((type pc
) (class color
))
557 (:foreground
"lightblue")))
558 "Default face used for buttons."
561 ;; backward-compatibility alias
562 (put 'diary-button-face
'face-alias
'diary-button
)
564 (define-button-type 'diary-entry
565 'action
#'diary-goto-entry
568 (defun diary-goto-entry (button)
569 (let ((marker (button-get button
'marker
)))
571 (pop-to-buffer (marker-buffer marker
))
572 (goto-char (marker-position marker
)))))
574 (defun fancy-diary-display ()
575 "Prepare a diary buffer with relevant entries in a fancy, noneditable form.
576 This function is provided for optional use as the `diary-display-hook'."
577 (with-current-buffer ;; Turn off selective-display in the diary file's buffer.
578 (find-buffer-visiting (substitute-in-file-name diary-file
))
579 (diary-unhide-everything))
580 (if (or (not diary-entries-list
)
581 (and (not (cdr diary-entries-list
))
582 (string-equal (car (cdr (car diary-entries-list
))) "")))
583 (let* ((holiday-list (if holidays-in-diary-buffer
584 (check-calendar-holidays original-date
)))
585 (msg (format "No diary entries for %s %s"
586 (concat date-string
(if holiday-list
":" ""))
587 (mapconcat 'identity holiday-list
"; "))))
588 (if (<= (length msg
) (frame-width))
590 (set-buffer (get-buffer-create holiday-buffer
))
591 (setq buffer-read-only nil
)
593 (insert (mapconcat 'identity holiday-list
"\n"))
594 (goto-char (point-min))
595 (set-buffer-modified-p nil
)
596 (setq buffer-read-only t
)
597 (display-buffer holiday-buffer
)
598 (message "No diary entries for %s" date-string
)))
599 (with-current-buffer;; Prepare the fancy diary buffer.
600 (make-fancy-diary-buffer)
601 (setq buffer-read-only nil
)
602 (let ((entry-list diary-entries-list
)
604 (holiday-list-last-month 1)
605 (holiday-list-last-year 1)
608 (if (not (calendar-date-equal date
(car (car entry-list
))))
610 (setq date
(car (car entry-list
)))
611 (and holidays-in-diary-buffer
612 (calendar-date-compare
613 (list (list holiday-list-last-month
614 (calendar-last-day-of-month
615 holiday-list-last-month
616 holiday-list-last-year
)
617 holiday-list-last-year
))
619 ;; We need to get the holidays for the next 3 months.
620 (setq holiday-list-last-month
621 (extract-calendar-month date
))
622 (setq holiday-list-last-year
623 (extract-calendar-year date
))
625 (increment-calendar-month
626 holiday-list-last-month holiday-list-last-year
1)
629 (let ((displayed-month holiday-list-last-month
)
630 (displayed-year holiday-list-last-year
))
631 (calendar-holiday-list)))
632 (increment-calendar-month
633 holiday-list-last-month holiday-list-last-year
1))
634 (let* ((date-string (calendar-date-string date
))
636 (let ((h holiday-list
)
638 ;; Make a list of all holidays for date.
640 (if (calendar-date-equal date
(car (car h
)))
641 (setq d
(append d
(cdr (car h
)))))
644 (insert (if (= (point) (point-min)) "" ?
\n) date-string
)
645 (if date-holiday-list
(insert ": "))
646 (let* ((l (current-column))
648 (insert (mapconcat (lambda (x)
649 (if (< longest
(length x
))
650 (setq longest
(length x
)))
653 (concat "\n" (make-string l ?
))))
654 (insert ?
\n (make-string (+ l longest
) ?
=) ?
\n)))))
656 (setq entry
(car (cdr (car entry-list
))))
657 (if (< 0 (length entry
))
659 (if (nth 3 (car entry-list
))
660 (insert-button (concat entry
"\n")
661 'marker
(nth 3 (car entry-list
))
665 (let* ((marks (nth 4 (car entry-list
)))
666 (temp-face (make-symbol
669 (mapcar (lambda (sym)
675 (make-face temp-face
)
676 ;; Remove :face info from the marks,
677 ;; copy the face info into temp-face
678 (while (setq faceinfo
(memq :face faceinfo
))
679 (copy-face (read (nth 1 faceinfo
)) temp-face
)
680 (setcar faceinfo nil
)
681 (setcar (cdr faceinfo
) nil
))
682 (setq marks
(delq nil marks
))
683 ;; Apply the font aspects.
684 (apply 'set-face-attribute temp-face nil marks
)
685 (search-backward entry
)
687 (make-overlay (match-beginning 0) (match-end 0))
689 (setq entry-list
(cdr entry-list
))))
690 (set-buffer-modified-p nil
)
691 (goto-char (point-min))
692 (setq buffer-read-only t
)
693 (display-buffer fancy-diary-buffer
)
694 (fancy-diary-display-mode)
695 (calendar-set-mode-line date-string
)
696 (message "Preparing diary...done"))))
698 (defun make-fancy-diary-buffer ()
699 "Create and return the initial fancy diary buffer."
700 (with-current-buffer (get-buffer-create fancy-diary-buffer
)
701 (setq buffer-read-only nil
)
702 (calendar-set-mode-line "Diary Entries")
704 (set-buffer-modified-p nil
)
705 (setq buffer-read-only t
)
706 (get-buffer fancy-diary-buffer
)))
708 (defun print-diary-entries ()
709 "Print a hard copy of the diary display.
711 If the simple diary display is being used, prepare a temp buffer with the
712 visible lines of the diary buffer, add a heading line composed from the mode
713 line, print the temp buffer, and destroy it.
715 If the fancy diary display is being used, just print the buffer.
717 The hooks given by the variable `print-diary-entries-hook' are called to do
718 the actual printing."
720 (if (bufferp (get-buffer fancy-diary-buffer
))
721 (with-current-buffer (get-buffer fancy-diary-buffer
)
722 (run-hooks 'print-diary-entries-hook
))
724 (find-buffer-visiting (substitute-in-file-name diary-file
))))
726 (let ((temp-buffer (get-buffer-create " *Printable Diary Entries*"))
728 (with-current-buffer diary-buffer
730 (if (not (stringp mode-line-format
))
732 (string-match "^-*\\([^-].*[^-]\\)-*$" mode-line-format
)
733 (match-string 1 mode-line-format
)))
734 (let ((start (point-min))
738 (setq end
(next-single-char-property-change
740 (if (get-char-property start
'invisible
)
742 (with-current-buffer temp-buffer
743 (insert-buffer-substring diary-buffer
744 start
(or end
(point-max)))))
746 (and end
(< end
(point-max))))))
747 (set-buffer temp-buffer
)
748 (goto-char (point-min))
750 (make-string (length heading
) ?
=) "\n")
751 (run-hooks 'print-diary-entries-hook
)
752 (kill-buffer temp-buffer
)))
753 (error "You don't have a diary buffer!")))))
755 (define-obsolete-function-alias 'show-all-diary-entries
'diary-show-all-entries
)
756 (defun diary-show-all-entries ()
757 "Show all of the diary entries in the diary file.
758 This function gets rid of the selective display of the diary file so that
759 all entries, not just some, are visible. If there is no diary buffer, one
762 (let ((d-file (diary-check-diary-file))
763 (pop-up-frames (window-dedicated-p (selected-window))))
764 (with-current-buffer (or (find-buffer-visiting d-file
)
765 (find-file-noselect d-file t
))
766 (when (eq major-mode
'fundamental-mode
) (diary-mode))
767 (diary-unhide-everything)
768 (display-buffer (current-buffer)))))
770 (defcustom diary-mail-addr
771 (if (boundp 'user-mail-address
) user-mail-address
"")
772 "Email address that `diary-mail-entries' will send email to."
777 (defcustom diary-mail-days
7
778 "Default number of days for `diary-mail-entries' to check."
784 (defun diary-mail-entries (&optional ndays
)
785 "Send a mail message showing diary entries for next NDAYS days.
786 If no prefix argument is given, NDAYS is set to `diary-mail-days'.
787 Mail is sent to the address specified by `diary-mail-addr'.
789 You can call `diary-mail-entries' every night using an at/cron job.
790 For example, this script will run the program at 2am daily. Since
791 `emacs -batch' does not load your `.emacs' file, you must ensure that
792 all relevant variables are set, as done here.
795 # diary-rem.sh -- repeatedly run the Emacs diary-reminder
797 -eval \"(setq diary-mail-days 3 \\
798 diary-file \\\"/path/to/diary.file\\\" \\
799 european-calendar-style t \\
800 diary-mail-addr \\\"user@host.name\\\" )\" \\
801 -l diary-lib -f diary-mail-entries
802 at -f diary-rem.sh 0200 tomorrow
804 You may have to tweak the syntax of the `at' command to suit your
805 system. Alternatively, you can specify a cron entry:
806 0 1 * * * diary-rem.sh
807 to run it every morning at 1am."
809 (if (string-equal diary-mail-addr
"")
810 (error "You must set `diary-mail-addr' to use this command")
811 (let ((diary-display-hook 'fancy-diary-display
))
812 (list-diary-entries (calendar-current-date) (or ndays diary-mail-days
)))
813 (compose-mail diary-mail-addr
814 (concat "Diary entries generated "
815 (calendar-date-string (calendar-current-date))))
817 (if (get-buffer fancy-diary-buffer
)
818 (with-current-buffer fancy-diary-buffer
(buffer-string))
820 (call-interactively (get mail-user-agent
'sendfunc
))))
822 (defun diary-name-pattern (string-array &optional abbrev-array paren
)
823 "Return a regexp matching the strings in the array STRING-ARRAY.
824 If the optional argument ABBREV-ARRAY is present, then the function
825 `calendar-abbrev-construct' is used to construct abbreviations from the
826 two supplied arrays. The returned regexp will then also match these
827 abbreviations, with or without final `.' characters. If the optional
828 argument PAREN is non-nil, the regexp is surrounded by parentheses."
829 (regexp-opt (append string-array
831 (calendar-abbrev-construct abbrev-array
834 (calendar-abbrev-construct abbrev-array
840 (defvar marking-diary-entries nil
841 "True during the marking of diary entries, nil otherwise.")
843 (defvar marking-diary-entry nil
844 "True during the marking of diary entries, if current entry is marking.")
846 (defun mark-diary-entries (&optional redraw
)
847 "Mark days in the calendar window that have diary entries.
848 Each entry in the diary file visible in the calendar window is
849 marked. After the entries are marked, the hooks
850 `nongregorian-diary-marking-hook' and `mark-diary-entries-hook'
851 are run. If the optional argument REDRAW is non-nil (which is
852 the case interactively, for example) then any existing diary
853 marks are first removed. This is intended to deal with deleted
856 ;; To remove any deleted diary entries. Do not redraw when:
857 ;; i) processing #include diary files (else only get the marks from
858 ;; the last #include file processed).
859 ;; ii) called via calendar-redraw (since calendar has already been
861 ;; Use of REDRAW handles both of these cases.
862 (when (and redraw mark-diary-entries-in-calendar
)
863 (setq mark-diary-entries-in-calendar nil
)
865 (let ((marking-diary-entries t
)
866 file-glob-attrs marks
)
867 (with-current-buffer (find-file-noselect (diary-check-diary-file) t
)
869 (when (eq major-mode
'fundamental-mode
) (diary-mode))
870 (setq mark-diary-entries-in-calendar t
)
871 (message "Marking diary entries...")
872 (setq file-glob-attrs
(nth 1 (diary-pull-attrs nil
'())))
873 (with-syntax-table diary-syntax-table
874 (dolist (date-form diary-date-forms
)
875 (if (eq (car date-form
) 'backup
)
876 (setq date-form
(cdr date-form
))) ;; ignore 'backup directive
878 (diary-name-pattern calendar-day-name-array
879 calendar-day-abbrev-array
))
882 (diary-name-pattern calendar-month-name-array
883 calendar-month-abbrev-array
)))
884 (month "[0-9]+\\|\\*")
886 (year "[0-9]+\\|\\*")
887 (l (length date-form
))
888 (d-name-pos (- l
(length (memq 'dayname date-form
))))
889 (d-name-pos (if (/= l d-name-pos
) (+ 2 d-name-pos
)))
890 (m-name-pos (- l
(length (memq 'monthname date-form
))))
891 (m-name-pos (if (/= l m-name-pos
) (+ 2 m-name-pos
)))
892 (d-pos (- l
(length (memq 'day date-form
))))
893 (d-pos (if (/= l d-pos
) (+ 2 d-pos
)))
894 (m-pos (- l
(length (memq 'month date-form
))))
895 (m-pos (if (/= l m-pos
) (+ 2 m-pos
)))
896 (y-pos (- l
(length (memq 'year date-form
))))
897 (y-pos (if (/= l y-pos
) (+ 2 y-pos
)))
900 "\\(\\`\\|\^M\\|\n\\)\\("
901 (mapconcat 'eval date-form
"\\)\\(")
903 (case-fold-search t
))
904 (goto-char (point-min))
905 (while (re-search-forward regexp nil t
)
908 (match-string-no-properties d-name-pos
)))
911 (match-string-no-properties m-name-pos
)))
912 (mm (string-to-number
914 (match-string-no-properties m-pos
)
916 (dd (string-to-number
918 (match-string-no-properties d-pos
)
921 (match-string-no-properties y-pos
)))
924 (if (and (= (length y-str
) 2)
925 abbreviated-calendar-year
)
927 (extract-calendar-year
928 (calendar-current-date)))
929 (y (+ (string-to-number y-str
)
931 (/ current-y
100)))))
932 (if (> (- y current-y
) 50)
934 (if (> (- current-y y
) 50)
937 (string-to-number y-str
)))))
938 (let ((tmp (diary-pull-attrs (buffer-substring-no-properties
939 (point) (line-end-position))
941 (setq entry
(nth 0 tmp
)
944 (mark-calendar-days-named
948 calendar-day-name-array
949 0 nil calendar-day-abbrev-array
) t
)) marks
)
952 (if (string-equal mm-name
"*") 0
956 calendar-month-name-array
957 1 nil calendar-month-abbrev-array
) t
)))))
958 (mark-calendar-date-pattern mm dd yy marks
))))))
959 (mark-sexp-diary-entries)
960 (run-hooks 'nongregorian-diary-marking-hook
961 'mark-diary-entries-hook
))
962 (message "Marking diary entries...done")))))
964 (defun mark-sexp-diary-entries ()
965 "Mark days in the calendar window that have sexp diary entries.
966 Each entry in the diary file (or included files) visible in the calendar window
967 is marked. See the documentation for the function `list-sexp-diary-entries'."
968 (let* ((sexp-mark (regexp-quote sexp-diary-entry-symbol
))
969 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)\\("
970 sexp-mark
"(\\)\\|\\("
971 (regexp-quote diary-nonmarking-symbol
)
972 sexp-mark
"(diary-remind\\)"))
973 (file-glob-attrs (nth 1 (diary-pull-attrs nil
'())))
974 m y first-date last-date mark file-glob-attrs
)
975 (with-current-buffer calendar-buffer
976 (setq m displayed-month
)
977 (setq y displayed-year
))
978 (increment-calendar-month m y -
1)
980 (calendar-absolute-from-gregorian (list m
1 y
)))
981 (increment-calendar-month m y
2)
983 (calendar-absolute-from-gregorian
984 (list m
(calendar-last-day-of-month m y
) y
)))
985 (goto-char (point-min))
986 (while (re-search-forward s-entry nil t
)
987 (setq marking-diary-entry
(char-equal (preceding-char) ?\
())
988 (re-search-backward "(")
989 (let ((sexp-start (point))
990 sexp entry entry-start line-start marks
)
992 (setq sexp
(buffer-substring-no-properties sexp-start
(point)))
994 (re-search-backward "\^M\\|\n\\|\\`")
995 (setq line-start
(point)))
997 (if (and (or (char-equal (preceding-char) ?\^M
)
998 (char-equal (preceding-char) ?
\n))
999 (not (looking-at " \\|\^I")))
1000 (progn;; Diary entry consists only of the sexp
1003 (setq entry-start
(point))
1004 ;; Find end of entry
1005 (re-search-forward "\^M\\|\n" nil t
)
1006 (while (looking-at " \\|\^I")
1007 (or (re-search-forward "\^M\\|\n" nil t
)
1008 (re-search-forward "$" nil t
)))
1009 (if (or (char-equal (preceding-char) ?\^M
)
1010 (char-equal (preceding-char) ?
\n))
1012 (setq entry
(buffer-substring-no-properties entry-start
(point)))
1013 (while (string-match "[\^M]" entry
)
1014 (aset entry
(match-beginning 0) ?
\n )))
1015 (calendar-for-loop date from first-date to last-date do
1016 (if (setq mark
(diary-sexp-entry sexp entry
1017 (calendar-gregorian-from-absolute date
)))
1019 (setq marks
(diary-pull-attrs entry file-glob-attrs
)
1020 marks
(nth 1 (diary-pull-attrs entry file-glob-attrs
)))
1021 (mark-visible-calendar-date
1022 (calendar-gregorian-from-absolute date
)
1023 (if (< 0 (length marks
))
1026 (car mark
)))))))))))
1028 (defun mark-included-diary-files ()
1029 "Mark the diary entries from other diary files with those of the diary file.
1030 This function is suitable for use as the `mark-diary-entries-hook'; it enables
1031 you to use shared diary files together with your own. The files included are
1032 specified in the diary-file by lines of this form:
1033 #include \"filename\"
1034 This is recursive; that is, #include directives in diary files thus included
1035 are obeyed. You can change the `#include' to some other string by
1036 changing the variable `diary-include-string'."
1037 (goto-char (point-min))
1038 (while (re-search-forward
1040 "\\(?:\\`\\|\^M\\|\n\\)"
1041 (regexp-quote diary-include-string
)
1042 " \"\\([^\"]*\\)\"")
1044 (let* ((diary-file (substitute-in-file-name
1045 (match-string-no-properties 1)))
1046 (mark-diary-entries-hook 'mark-included-diary-files
)
1047 (dbuff (find-buffer-visiting diary-file
)))
1048 (if (file-exists-p diary-file
)
1049 (if (file-readable-p diary-file
)
1051 (mark-diary-entries)
1053 (kill-buffer (find-buffer-visiting diary-file
))))
1055 (message "Can't read included diary file %s" diary-file
)
1058 (message "Can't find included diary file %s" diary-file
)
1060 (goto-char (point-min)))
1062 (defun mark-calendar-days-named (dayname &optional color
)
1063 "Mark all dates in the calendar window that are day DAYNAME of the week.
1064 0 means all Sundays, 1 means all Mondays, and so on."
1065 (with-current-buffer calendar-buffer
1066 (let ((prev-month displayed-month
)
1067 (prev-year displayed-year
)
1068 (succ-month displayed-month
)
1069 (succ-year displayed-year
)
1072 (increment-calendar-month succ-month succ-year
1)
1073 (increment-calendar-month prev-month prev-year -
1)
1074 (setq day
(calendar-absolute-from-gregorian
1075 (calendar-nth-named-day 1 dayname prev-month prev-year
)))
1076 (setq last-day
(calendar-absolute-from-gregorian
1077 (calendar-nth-named-day -
1 dayname succ-month succ-year
)))
1078 (while (<= day last-day
)
1079 (mark-visible-calendar-date (calendar-gregorian-from-absolute day
) color
)
1080 (setq day
(+ day
7))))))
1082 (defun mark-calendar-date-pattern (month day year
&optional color
)
1083 "Mark all dates in the calendar window that conform to MONTH/DAY/YEAR.
1084 A value of 0 in any position is a wildcard."
1085 (with-current-buffer calendar-buffer
1086 (let ((m displayed-month
)
1088 (increment-calendar-month m y -
1)
1089 (calendar-for-loop i from
0 to
2 do
1090 (mark-calendar-month m y month day year color
)
1091 (increment-calendar-month m y
1)))))
1093 (defun mark-calendar-month (month year p-month p-day p-year
&optional color
)
1094 "Mark dates in the MONTH/YEAR that conform to pattern P-MONTH/P_DAY/P-YEAR.
1095 A value of 0 in any position of the pattern is a wildcard."
1096 (if (or (and (= month p-month
)
1097 (or (= p-year
0) (= year p-year
)))
1099 (or (= p-year
0) (= year p-year
))))
1102 i from
1 to
(calendar-last-day-of-month month year
) do
1103 (mark-visible-calendar-date (list month i year
) color
))
1104 (mark-visible-calendar-date (list month p-day year
) color
))))
1106 (defun sort-diary-entries ()
1107 "Sort the list of diary entries by time of day."
1108 (setq diary-entries-list
(sort diary-entries-list
'diary-entry-compare
)))
1110 (defun diary-entry-compare (e1 e2
)
1111 "Returns t if E1 is earlier than E2."
1112 (or (calendar-date-compare e1 e2
)
1113 (and (calendar-date-equal (car e1
) (car e2
))
1114 (let* ((ts1 (cadr e1
)) (t1 (diary-entry-time ts1
))
1115 (ts2 (cadr e2
)) (t2 (diary-entry-time ts2
)))
1118 (string-lessp ts1 ts2
)))))))
1120 (defcustom diary-unknown-time
1122 "Value returned by diary-entry-time when no time is found.
1123 The default value -9999 causes entries with no recognizable time to be placed
1124 before those with times; 9999 would place entries with no recognizable time
1125 after those with times."
1130 (defun diary-entry-time (s)
1131 "Return time at the beginning of the string S as a military-style integer.
1132 For example, returns 1325 for 1:25pm.
1134 Returns `diary-unknown-time' (default value -9999) if no time is recognized.
1135 The recognized forms are XXXX, X:XX, or XX:XX (military time), and XXam,
1136 XXAM, XXpm, XXPM, XX:XXam, XX:XXAM XX:XXpm, or XX:XXPM. A period (.) can
1137 be used instead of a colon (:) to separate the hour and minute parts."
1138 (let ((case-fold-search nil
))
1139 (cond ((string-match ; Military time
1140 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\)[:.]?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)"
1142 (+ (* 100 (string-to-number (match-string 1 s
)))
1143 (string-to-number (match-string 2 s
))))
1144 ((string-match ; Hour only XXam or XXpm
1145 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s
)
1146 (+ (* 100 (%
(string-to-number (match-string 1 s
)) 12))
1147 (if (equal ?a
(downcase (aref s
(match-beginning 2))))
1149 ((string-match ; Hour and minute XX:XXam or XX:XXpm
1150 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\)[:.]\\([0-9][0-9]\\)\\([ap]\\)m\\>" s
)
1151 (+ (* 100 (%
(string-to-number (match-string 1 s
)) 12))
1152 (string-to-number (match-string 2 s
))
1153 (if (equal ?a
(downcase (aref s
(match-beginning 3))))
1155 (t diary-unknown-time
)))) ; Unrecognizable
1159 (defun list-sexp-diary-entries (date)
1160 "Add sexp entries for DATE from the diary file to `diary-entries-list'.
1161 Also, Make them visible in the diary file. Returns t if any entries were
1164 Sexp diary entries must be prefaced by a `sexp-diary-entry-symbol' (normally
1165 `%%'). The form of a sexp diary entry is
1169 Both ENTRY and DATE are globally available when the SEXP is evaluated. If the
1170 SEXP yields the value nil, the diary entry does not apply. If it yields a
1171 non-nil value, ENTRY will be taken to apply to DATE; if the non-nil value is a
1172 string, that string will be the diary entry in the fancy diary display.
1174 For example, the following diary entry will apply to the 21st of the month
1175 if it is a weekday and the Friday before if the 21st is on a weekend:
1177 &%%(let ((dayname (calendar-day-of-week date))
1178 (day (extract-calendar-day date)))
1180 (and (= day 21) (memq dayname '(1 2 3 4 5)))
1181 (and (memq day '(19 20)) (= dayname 5)))
1182 ) UIUC pay checks deposited
1184 A number of built-in functions are available for this type of diary entry:
1186 %%(diary-date MONTH DAY YEAR &optional MARK) text
1187 Entry applies if date is MONTH, DAY, YEAR if
1188 `european-calendar-style' is nil, and DAY, MONTH, YEAR if
1189 `european-calendar-style' is t. DAY, MONTH, and YEAR
1190 can be lists of integers, the constant t, or an integer.
1191 The constant t means all values. An optional parameter
1192 MARK specifies a face or single-character string to use
1193 when highlighting the day in the calendar.
1195 %%(diary-float MONTH DAYNAME N &optional DAY MARK) text
1196 Entry will appear on the Nth DAYNAME of MONTH.
1197 (DAYNAME=0 means Sunday, 1 means Monday, and so on;
1198 if N is negative it counts backward from the end of
1199 the month. MONTH can be a list of months, a single
1200 month, or t to specify all months. Optional DAY means
1201 Nth DAYNAME of MONTH on or after/before DAY. DAY defaults
1202 to 1 if N>0 and the last day of the month if N<0. An
1203 optional parameter MARK specifies a face or single-character
1204 string to use when highlighting the day in the calendar.
1206 %%(diary-block M1 D1 Y1 M2 D2 Y2 &optional MARK) text
1207 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2,
1208 inclusive. (If `european-calendar-style' is t, the
1209 order of the parameters should be changed to D1, M1, Y1,
1210 D2, M2, Y2.) An optional parameter MARK specifies a face
1211 or single-character string to use when highlighting the
1212 day in the calendar.
1214 %%(diary-anniversary MONTH DAY YEAR &optional MARK) text
1215 Entry will appear on anniversary dates of MONTH DAY, YEAR.
1216 (If `european-calendar-style' is t, the order of the
1217 parameters should be changed to DAY, MONTH, YEAR.) Text
1218 can contain %d or %d%s; %d will be replaced by the number
1219 of years since the MONTH DAY, YEAR and %s will be replaced
1220 by the ordinal ending of that number (that is, `st', `nd',
1221 `rd' or `th', as appropriate. The anniversary of February
1222 29 is considered to be March 1 in a non-leap year. An
1223 optional parameter MARK specifies a face or single-character
1224 string to use when highlighting the day in the calendar.
1226 %%(diary-cyclic N MONTH DAY YEAR &optional MARK) text
1227 Entry will appear every N days, starting MONTH DAY, YEAR.
1228 (If `european-calendar-style' is t, the order of the
1229 parameters should be changed to N, DAY, MONTH, YEAR.) Text
1230 can contain %d or %d%s; %d will be replaced by the number
1231 of repetitions since the MONTH DAY, YEAR and %s will
1232 be replaced by the ordinal ending of that number (that is,
1233 `st', `nd', `rd' or `th', as appropriate. An optional
1234 parameter MARK specifies a face or single-character string
1235 to use when highlighting the day in the calendar.
1237 %%(diary-remind SEXP DAYS &optional MARKING) text
1238 Entry is a reminder for diary sexp SEXP. DAYS is either a
1239 single number or a list of numbers indicating the number(s)
1240 of days before the event that the warning(s) should occur.
1241 If the current date is (one of) DAYS before the event
1242 indicated by EXPR, then a suitable message (as specified
1243 by `diary-remind-message') appears. In addition to the
1244 reminders beforehand, the diary entry also appears on
1245 the date itself. If optional MARKING is non-nil then the
1246 *reminders* are marked on the calendar. Marking of
1247 reminders is independent of whether the entry *itself* is
1248 a marking or nonmarking one.
1250 %%(diary-day-of-year)
1251 Diary entries giving the day of the year and the number of
1252 days remaining in the year will be made every day. Note
1253 that since there is no text, it makes sense only if the
1254 fancy diary display is used.
1257 Diary entries giving the corresponding ISO commercial date
1258 will be made every day. Note that since there is no text,
1259 it makes sense only if the fancy diary display is used.
1261 %%(diary-french-date)
1262 Diary entries giving the corresponding French Revolutionary
1263 date will be made every day. Note that since there is no
1264 text, it makes sense only if the fancy diary display is used.
1266 %%(diary-islamic-date)
1267 Diary entries giving the corresponding Islamic date will be
1268 made every day. Note that since there is no text, it
1269 makes sense only if the fancy diary display is used.
1271 %%(diary-hebrew-date)
1272 Diary entries giving the corresponding Hebrew date will be
1273 made every day. Note that since there is no text, it
1274 makes sense only if the fancy diary display is used.
1276 %%(diary-astro-day-number) Diary entries giving the corresponding
1277 astronomical (Julian) day number will be made every day.
1278 Note that since there is no text, it makes sense only if the
1279 fancy diary display is used.
1281 %%(diary-julian-date) Diary entries giving the corresponding
1282 Julian date will be made every day. Note that since
1283 there is no text, it makes sense only if the fancy diary
1286 %%(diary-sunrise-sunset)
1287 Diary entries giving the local times of sunrise and sunset
1288 will be made every day. Note that since there is no text,
1289 it makes sense only if the fancy diary display is used.
1290 Floating point required.
1292 %%(diary-phases-of-moon)
1293 Diary entries giving the times of the phases of the moon
1294 will be when appropriate. Note that since there is no text,
1295 it makes sense only if the fancy diary display is used.
1296 Floating point required.
1298 %%(diary-yahrzeit MONTH DAY YEAR) text
1299 Text is assumed to be the name of the person; the date is
1300 the date of death on the *civil* calendar. The diary entry
1301 will appear on the proper Hebrew-date anniversary and on the
1302 day before. (If `european-calendar-style' is t, the order
1303 of the parameters should be changed to DAY, MONTH, YEAR.)
1305 %%(diary-rosh-hodesh)
1306 Diary entries will be made on the dates of Rosh Hodesh on
1307 the Hebrew calendar. Note that since there is no text, it
1308 makes sense only if the fancy diary display is used.
1311 Diary entries giving the weekly parasha will be made on
1312 every Saturday. Note that since there is no text, it
1313 makes sense only if the fancy diary display is used.
1316 Diary entries giving the omer count will be made every day
1317 from Passover to Shavuot. Note that since there is no text,
1318 it makes sense only if the fancy diary display is used.
1320 Marking these entries is *extremely* time consuming, so these entries are
1321 best if they are nonmarking."
1322 (let ((s-entry (concat "\\(\\`\\|\^M\\|\n\\)"
1323 (regexp-quote diary-nonmarking-symbol
)
1325 (regexp-quote sexp-diary-entry-symbol
)
1327 entry-found file-glob-attrs marks
)
1328 (goto-char (point-min))
1330 (setq file-glob-attrs
(nth 1 (diary-pull-attrs nil
'()))))
1331 (while (re-search-forward s-entry nil t
)
1333 (let ((sexp-start (point))
1334 sexp entry specifier entry-start line-start
)
1336 (setq sexp
(buffer-substring-no-properties sexp-start
(point)))
1338 (re-search-backward "\^M\\|\n\\|\\`")
1339 (setq line-start
(point)))
1341 (buffer-substring-no-properties (1+ line-start
) (point))
1342 entry-start
(1+ line-start
))
1344 (if (and (or (char-equal (preceding-char) ?\^M
)
1345 (char-equal (preceding-char) ?
\n))
1346 (not (looking-at " \\|\^I")))
1347 (progn;; Diary entry consists only of the sexp
1350 (setq entry-start
(point))
1351 (re-search-forward "\^M\\|\n" nil t
)
1352 (while (looking-at " \\|\^I")
1353 (re-search-forward "\^M\\|\n" nil t
))
1355 (setq entry
(buffer-substring-no-properties entry-start
(point)))
1356 (while (string-match "[\^M]" entry
)
1357 (aset entry
(match-beginning 0) ?
\n )))
1358 (let ((diary-entry (diary-sexp-entry sexp entry date
))
1360 (setq entry
(if (consp diary-entry
)
1365 (remove-overlays line-start
(point) 'invisible
'diary
)
1366 (if (< 0 (length entry
))
1367 (setq temp
(diary-pull-attrs entry file-glob-attrs
)
1369 marks
(nth 1 temp
)))))
1370 (add-to-diary-list date
1373 (if entry-start
(copy-marker entry-start
)
1376 (setq entry-found
(or entry-found diary-entry
)))))
1379 (defun diary-sexp-entry (sexp entry date
)
1380 "Process a SEXP diary ENTRY for DATE."
1381 (let ((result (if calendar-debug-sexp
1382 (let ((stack-trace-on-error t
))
1383 (eval (car (read-from-string sexp
))))
1385 (eval (car (read-from-string sexp
)))
1388 (message "Bad sexp at line %d in %s: %s"
1389 (count-lines (point-min) (point))
1392 (cond ((stringp result
) result
)
1393 ((and (consp result
)
1394 (stringp (cdr result
))) result
)
1398 (defun diary-date (month day year
&optional mark
)
1399 "Specific date(s) diary entry.
1400 Entry applies if date is MONTH, DAY, YEAR if `european-calendar-style' is nil,
1401 and DAY, MONTH, YEAR if `european-calendar-style' is t. DAY, MONTH, and YEAR
1402 can be lists of integers, the constant t, or an integer. The constant t means
1405 An optional parameter MARK specifies a face or single-character string to
1406 use when highlighting the day in the calendar."
1407 (let ((dd (if european-calendar-style
1410 (mm (if european-calendar-style
1413 (m (extract-calendar-month date
))
1414 (y (extract-calendar-year date
))
1415 (d (extract-calendar-day date
)))
1417 (or (and (listp dd
) (memq d dd
))
1420 (or (and (listp mm
) (memq m mm
))
1423 (or (and (listp year
) (memq y year
))
1426 (cons mark entry
))))
1428 (defun diary-block (m1 d1 y1 m2 d2 y2
&optional mark
)
1430 Entry applies if date is between, or on one of, two dates.
1431 The order of the parameters is
1432 M1, D1, Y1, M2, D2, Y2 if `european-calendar-style' is nil, and
1433 D1, M1, Y1, D2, M2, Y2 if `european-calendar-style' is t.
1435 An optional parameter MARK specifies a face or single-character string to
1436 use when highlighting the day in the calendar."
1438 (let ((date1 (calendar-absolute-from-gregorian
1439 (if european-calendar-style
1442 (date2 (calendar-absolute-from-gregorian
1443 (if european-calendar-style
1446 (d (calendar-absolute-from-gregorian date
)))
1447 (if (and (<= date1 d
) (<= d date2
))
1448 (cons mark entry
))))
1450 (defun diary-float (month dayname n
&optional day mark
)
1451 "Floating diary entry--entry applies if date is the nth dayname of month.
1452 Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant
1453 t, or an integer. The constant t means all months. If N is negative, count
1454 backward from the end of the month.
1456 An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY.
1457 Optional MARK specifies a face or single-character string to use when
1458 highlighting the day in the calendar."
1459 ;; This is messy because the diary entry may apply, but the date on which it
1460 ;; is based can be in a different month/year. For example, asking for the
1461 ;; first Monday after December 30. For large values of |n| the problem is
1463 (and (= dayname
(calendar-day-of-week date
))
1464 (let* ((m (extract-calendar-month date
))
1465 (d (extract-calendar-day date
))
1466 (y (extract-calendar-year date
))
1467 (limit; last (n>0) or first (n<0) possible base date for entry
1468 (calendar-nth-named-absday (- n
) dayname m y d
))
1469 (last-abs (if (> n
0) limit
(+ limit
6)))
1470 (first-abs (if (> n
0) (- limit
6) limit
))
1471 (last (calendar-gregorian-from-absolute last-abs
))
1472 (first (calendar-gregorian-from-absolute first-abs
))
1473 ; m1, d1 is first possible base date
1474 (m1 (extract-calendar-month first
))
1475 (d1 (extract-calendar-day first
))
1476 (y1 (extract-calendar-year first
))
1477 ; m2, d2 is last possible base date
1478 (m2 (extract-calendar-month last
))
1479 (d2 (extract-calendar-day last
))
1480 (y2 (extract-calendar-year last
)))
1481 (if (or (and (= m1 m2
) ; only possible base dates in one month
1486 (let ((d (or day
(if (> n
0)
1488 (calendar-last-day-of-month m1 y1
)))))
1489 (and (<= d1 d
) (<= d d2
))))
1490 ;; only possible base dates straddle two months
1492 (and (= y1 y2
) (< m1 m2
)))
1494 ;; m1, d1 works as a base date
1500 (<= d1
(or day
(if (> n
0)
1502 (calendar-last-day-of-month m1 y1
)))))
1503 ;; m2, d2 works as a base date
1504 (and (or (eq month t
)
1508 (<= (or day
(if (> n
0)
1510 (calendar-last-day-of-month m2 y2
)))
1512 (cons mark entry
)))))
1515 (defun diary-anniversary (month day
&optional year mark
)
1516 "Anniversary diary entry.
1517 Entry applies if date is the anniversary of MONTH, DAY, YEAR if
1518 `european-calendar-style' is nil, and DAY, MONTH, YEAR if
1519 `european-calendar-style' is t. Diary entry can contain `%d' or `%d%s'; the
1520 %d will be replaced by the number of years since the MONTH DAY, YEAR and the
1521 %s will be replaced by the ordinal ending of that number (that is, `st', `nd',
1522 `rd' or `th', as appropriate. The anniversary of February 29 is considered
1523 to be March 1 in non-leap years.
1525 An optional parameter MARK specifies a face or single-character string to
1526 use when highlighting the day in the calendar."
1527 (let* ((d (if european-calendar-style
1530 (m (if european-calendar-style
1533 (y (extract-calendar-year date
))
1534 (diff (if year
(- y year
) 100)))
1535 (if (and (= m
2) (= d
29) (not (calendar-leap-year-p y
)))
1538 (if (and (> diff
0) (calendar-date-equal (list m d y
) date
))
1539 (cons mark
(format entry diff
(diary-ordinal-suffix diff
))))))
1541 (defun diary-cyclic (n month day year
&optional mark
)
1542 "Cycle diary entry--entry applies every N days starting at MONTH, DAY, YEAR.
1543 If `european-calendar-style' is t, parameters are N, DAY, MONTH, YEAR.
1544 ENTRY can contain `%d' or `%d%s'; the %d will be replaced by the number of
1545 repetitions since the MONTH DAY, YEAR and %s will be replaced by the
1546 ordinal ending of that number (that is, `st', `nd', `rd' or `th', as
1549 An optional parameter MARK specifies a face or single-character string to
1550 use when highlighting the day in the calendar."
1551 (let* ((d (if european-calendar-style
1554 (m (if european-calendar-style
1557 (diff (- (calendar-absolute-from-gregorian date
)
1558 (calendar-absolute-from-gregorian
1561 (if (and (>= diff
0) (zerop (% diff n
)))
1562 (cons mark
(format entry cycle
(diary-ordinal-suffix cycle
))))))
1564 (defun diary-ordinal-suffix (n)
1565 "Ordinal suffix for N. (That is, `st', `nd', `rd', or `th', as appropriate.)"
1566 (if (or (memq (% n
100) '(11 12 13))
1569 (aref ["th" "st" "nd" "rd"] (% n
10))))
1571 (defun diary-day-of-year ()
1572 "Day of year and number of days remaining in the year of date diary entry."
1573 (calendar-day-of-year-string date
))
1575 (defcustom diary-remind-message
1577 (if (= 0 (% days
7))
1578 (concat (int-to-string (/ days
7)) (if (= 7 days
) " week" " weeks"))
1579 (concat (int-to-string days
) (if (= 1 days
) " day" " days")))
1582 "Pseudo-pattern giving form of reminder messages in the fancy diary
1585 Used by the function `diary-remind', a pseudo-pattern is a list of
1586 expressions that can involve the keywords `days' (a number), `date' (a list of
1587 month, day, year), and `diary-entry' (a string)."
1591 (defun diary-remind (sexp days
&optional marking
)
1592 "Provide a reminder of a diary entry.
1593 SEXP is a diary-sexp. DAYS is either a single number or a list of numbers
1594 indicating the number(s) of days before the event that the warning(s) should
1595 occur on. If the current date is (one of) DAYS before the event indicated by
1596 SEXP, then a suitable message (as specified by `diary-remind-message' is
1599 In addition to the reminders beforehand, the diary entry also appears on the
1602 A `diary-nonmarking-symbol' at the beginning of the line of the diary-remind
1603 entry specifies that the diary entry (not the reminder) is non-marking.
1604 Marking of reminders is independent of whether the entry itself is a marking
1605 or nonmarking; if optional parameter MARKING is non-nil then the reminders are
1606 marked on the calendar."
1607 (let ((diary-entry (eval sexp
)))
1609 ;; Diary entry applies on date
1611 (or (not marking-diary-entries
) marking-diary-entry
))
1613 ;; Diary entry may apply to `days' before date
1614 ((and (integerp days
)
1615 (not diary-entry
); Diary entry does not apply to date
1616 (or (not marking-diary-entries
) marking
))
1617 (let ((date (calendar-gregorian-from-absolute
1618 (+ (calendar-absolute-from-gregorian date
) days
))))
1619 (when (setq diary-entry
(eval sexp
)) ; re-evaluate with adjusted date
1620 ;; Discard any mark portion from diary-anniversary, etc.
1621 (if (consp diary-entry
) (setq diary-entry
(cdr diary-entry
)))
1622 (mapconcat 'eval diary-remind-message
""))))
1623 ;; Diary entry may apply to one of a list of days before date
1624 ((and (listp days
) days
)
1625 (or (diary-remind sexp
(car days
) marking
)
1626 (diary-remind sexp
(cdr days
) marking
))))))
1628 (defvar diary-modify-entry-list-string-function nil
1629 "Function applied to entry string before putting it into the entries list.
1630 Can be used by programs integrating a diary list into other buffers (e.g.
1631 org.el and planner.el) to modify the string or add properties to it.
1632 The function takes a string argument and must return a string.")
1634 (defun add-to-diary-list (date string specifier
&optional marker globcolor
)
1635 "Add the entry (DATE STRING SPECIFIER MARKER GLOBCOLOR) to `diary-entries-list'.
1636 Do nothing if DATE or STRING is nil."
1637 (when (and date string
)
1638 (if diary-file-name-prefix
1639 (let ((prefix (funcall diary-file-name-prefix-function
1640 (buffer-file-name))))
1641 (or (string= prefix
"")
1642 (setq string
(format "[%s] %s" prefix string
)))))
1643 (and diary-modify-entry-list-string-function
1644 (setq string
(funcall diary-modify-entry-list-string-function
1646 (setq diary-entries-list
1647 (append diary-entries-list
1648 (list (list date string specifier marker globcolor
))))))
1650 (defun diary-redraw-calendar ()
1651 "If `calendar-buffer' is live and diary entries are marked, redraw it."
1652 (and mark-diary-entries-in-calendar
1655 ;; Return value suitable for `write-contents-functions'.
1658 (defun make-diary-entry (string &optional nonmarking file
)
1659 "Insert a diary entry STRING which may be NONMARKING in FILE.
1660 If omitted, NONMARKING defaults to nil and FILE defaults to
1662 (let ((pop-up-frames (window-dedicated-p (selected-window))))
1663 (find-file-other-window (substitute-in-file-name (or file diary-file
))))
1664 (when (eq major-mode
'fundamental-mode
) (diary-mode))
1666 (diary-unhide-everything)
1667 (goto-char (point-max))
1668 (when (let ((case-fold-search t
))
1669 (search-backward "Local Variables:"
1670 (max (- (point-max) 3000) (point-min))
1677 (if nonmarking diary-nonmarking-symbol
"")
1680 (defun insert-diary-entry (arg)
1681 "Insert a diary entry for the date indicated by point.
1682 Prefix arg will make the entry nonmarking."
1684 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t
) t t
)
1687 (defun insert-weekly-diary-entry (arg)
1688 "Insert a weekly diary entry for the day of the week indicated by point.
1689 Prefix arg will make the entry nonmarking."
1691 (make-diary-entry (calendar-day-name (calendar-cursor-to-date t
))
1694 (defun insert-monthly-diary-entry (arg)
1695 "Insert a monthly diary entry for the day of the month indicated by point.
1696 Prefix arg will make the entry nonmarking."
1698 (let ((calendar-date-display-form
1699 (if european-calendar-style
1702 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t
) t
)
1705 (defun insert-yearly-diary-entry (arg)
1706 "Insert an annual diary entry for the day of the year indicated by point.
1707 Prefix arg will make the entry nonmarking."
1709 (let ((calendar-date-display-form
1710 (if european-calendar-style
1711 '(day " " monthname
)
1712 '(monthname " " day
))))
1713 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t
) t
)
1716 (defun insert-anniversary-diary-entry (arg)
1717 "Insert an anniversary diary entry for the date given by point.
1718 Prefix arg will make the entry nonmarking."
1720 (let ((calendar-date-display-form
1721 (if european-calendar-style
1722 '(day " " month
" " year
)
1723 '(month " " day
" " year
))))
1725 (format "%s(diary-anniversary %s)"
1726 sexp-diary-entry-symbol
1727 (calendar-date-string (calendar-cursor-to-date t
) nil t
))
1730 (defun insert-block-diary-entry (arg)
1731 "Insert a block diary entry for the days between the point and marked date.
1732 Prefix arg will make the entry nonmarking."
1734 (let ((calendar-date-display-form
1735 (if european-calendar-style
1736 '(day " " month
" " year
)
1737 '(month " " day
" " year
)))
1738 (cursor (calendar-cursor-to-date t
))
1739 (mark (or (car calendar-mark-ring
)
1740 (error "No mark set in this buffer")))
1742 (if (< (calendar-absolute-from-gregorian mark
)
1743 (calendar-absolute-from-gregorian cursor
))
1749 (format "%s(diary-block %s %s)"
1750 sexp-diary-entry-symbol
1751 (calendar-date-string start nil t
)
1752 (calendar-date-string end nil t
))
1755 (defun insert-cyclic-diary-entry (arg)
1756 "Insert a cyclic diary entry starting at the date given by point.
1757 Prefix arg will make the entry nonmarking."
1759 (let ((calendar-date-display-form
1760 (if european-calendar-style
1761 '(day " " month
" " year
)
1762 '(month " " day
" " year
))))
1764 (format "%s(diary-cyclic %d %s)"
1765 sexp-diary-entry-symbol
1766 (calendar-read "Repeat every how many days: "
1767 (lambda (x) (> x
0)))
1768 (calendar-date-string (calendar-cursor-to-date t
) nil t
))
1771 (defvar diary-mode-map
1772 (let ((map (make-sparse-keymap)))
1773 (define-key map
"\C-c\C-s" 'diary-show-all-entries
)
1774 (define-key map
"\C-c\C-q" 'quit-window
)
1776 "Keymap for `diary-mode'.")
1779 (define-derived-mode diary-mode fundamental-mode
"Diary"
1780 "Major mode for editing the diary file."
1781 (set (make-local-variable 'font-lock-defaults
)
1782 '(diary-font-lock-keywords t
))
1783 (add-to-invisibility-spec '(diary . nil
))
1784 (add-hook 'after-save-hook
'diary-redraw-calendar nil t
)
1785 (if diary-header-line-flag
1786 (setq header-line-format diary-header-line-format
)))
1788 (define-derived-mode fancy-diary-display-mode fundamental-mode
1790 "Major mode used while displaying diary entries using Fancy Display."
1791 (set (make-local-variable 'font-lock-defaults
)
1792 '(fancy-diary-font-lock-keywords t
))
1793 (local-set-key "q" 'quit-window
))
1796 (defvar fancy-diary-font-lock-keywords
1800 (let ((dayname (diary-name-pattern calendar-day-name-array nil t
))
1801 (monthname (diary-name-pattern calendar-month-name-array nil t
))
1805 (mapconcat 'eval calendar-date-display-form
""))
1806 "\\(\\(: .*\\)\\|\\(\n +.*\\)\\)*\n=+$")
1808 '("^.*anniversary.*$" . font-lock-keyword-face
)
1809 '("^.*birthday.*$" . font-lock-keyword-face
)
1810 '("^.*Yahrzeit.*$" . font-lock-reference-face
)
1811 '("^\\(Erev \\)?Rosh Hodesh.*" . font-lock-function-name-face
)
1812 '("^Day.*omer.*$" . font-lock-builtin-face
)
1813 '("^Parashat.*$" . font-lock-comment-face
)
1814 '("^[ \t]*[0-9]?[0-9]\\([:.]?[0-9][0-9]\\)?\\(am\\|pm\\|AM\\|PM\\)?\\(-[0-9]?[0-9]\\([:.]?[0-9][0-9]\\)?\\(am\\|pm\\|AM\\|PM\\)?\\)?"
1815 . font-lock-variable-name-face
))
1816 "Keywords to highlight in fancy diary display")
1819 (defun diary-font-lock-sexps (limit)
1820 "Recognize sexp diary entry for font-locking."
1821 (if (re-search-forward
1822 (concat "^" (regexp-quote diary-nonmarking-symbol
)
1823 "?\\(" (regexp-quote sexp-diary-entry-symbol
) "\\)")
1827 (narrow-to-region (point-min) limit
)
1828 (let ((start (point)))
1830 (store-match-data (list start
(point)))
1834 (defun diary-font-lock-date-forms (month-array &optional symbol abbrev-array
)
1835 "Create font-lock patterns for `diary-date-forms' using MONTH-ARRAY.
1836 If given, optional SYMBOL must be a prefix to entries.
1837 If optional ABBREV-ARRAY is present, the abbreviations constructed
1838 from this array by the function `calendar-abbrev-construct' are
1839 matched (with or without a final `.'), in addition to the full month
1841 (let ((dayname (diary-name-pattern calendar-day-name-array
1842 calendar-day-abbrev-array t
))
1843 (monthname (format "\\(%s\\|\\*\\)"
1844 (diary-name-pattern month-array abbrev-array
)))
1845 (month "\\([0-9]+\\|\\*\\)")
1846 (day "\\([0-9]+\\|\\*\\)")
1847 (year "-?\\([0-9]+\\|\\*\\)"))
1850 (concat "^" (regexp-quote diary-nonmarking-symbol
) "?"
1851 (if symbol
(regexp-quote symbol
) "") "\\("
1853 ;; If backup, omit first item (backup)
1854 ;; and last item (not part of date)
1855 (if (equal (car x
) 'backup
)
1856 (nreverse (cdr (reverse (cdr x
))))
1859 ;; With backup, last item is not part of date
1860 (if (equal (car x
) 'backup
)
1861 (concat "\\)" (eval (car (reverse x
))))
1866 (eval-when-compile (require 'cal-hebrew
)
1867 (require 'cal-islam
))
1869 (defconst diary-time-regexp
1870 ;; Formats that should be accepted:
1871 ;; 10:00 10.00 10h00 10h 10am 10:00am 10.00am
1872 (concat "[0-9]?[0-9]\\([AaPp][mM]\\|\\("
1873 "[Hh]\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]"
1874 "\\)\\([AaPp][Mm]\\)?\\)"))
1876 (defvar diary-font-lock-keywords
1878 (diary-font-lock-date-forms calendar-month-name-array
1879 nil calendar-month-abbrev-array
)
1880 (when (or (memq 'mark-hebrew-diary-entries
1881 nongregorian-diary-marking-hook
)
1882 (memq 'list-hebrew-diary-entries
1883 nongregorian-diary-listing-hook
))
1884 (require 'cal-hebrew
)
1885 (diary-font-lock-date-forms
1886 calendar-hebrew-month-name-array-leap-year
1887 hebrew-diary-entry-symbol
))
1888 (when (or (memq 'mark-islamic-diary-entries
1889 nongregorian-diary-marking-hook
)
1890 (memq 'list-islamic-diary-entries
1891 nongregorian-diary-listing-hook
))
1892 (require 'cal-islam
)
1893 (diary-font-lock-date-forms
1894 calendar-islamic-month-name-array
1895 islamic-diary-entry-symbol
))
1898 (concat "^" (regexp-quote diary-include-string
) ".*$")
1899 'font-lock-keyword-face
)
1901 (concat "^" (regexp-quote diary-nonmarking-symbol
)
1902 "?\\(" (regexp-quote sexp-diary-entry-symbol
) "\\)")
1903 '(1 font-lock-reference-face
))
1905 (concat "^" (regexp-quote diary-nonmarking-symbol
))
1906 'font-lock-reference-face
)
1908 (concat "^" (regexp-quote diary-nonmarking-symbol
)
1909 "?\\(" (regexp-quote hebrew-diary-entry-symbol
) "\\)")
1910 '(1 font-lock-reference-face
))
1912 (concat "^" (regexp-quote diary-nonmarking-symbol
)
1913 "?\\(" (regexp-quote islamic-diary-entry-symbol
) "\\)")
1914 '(1 font-lock-reference-face
))
1915 '(diary-font-lock-sexps . font-lock-keyword-face
)
1917 (concat ;; "^[ \t]+"
1918 diary-time-regexp
"\\(-" diary-time-regexp
"\\)?")
1919 'font-lock-function-name-face
)))
1920 "Forms to highlight in `diary-mode'.")
1923 ;; Following code from Dave Love <fx@gnu.org>.
1924 ;; Import Outlook-format appointments from mail messages in Gnus or
1925 ;; Rmail using command `diary-from-outlook'. This, or the specialized
1926 ;; functions `diary-from-outlook-gnus' and `diary-from-outlook-rmail',
1927 ;; could be run from hooks to notice appointments automatically (in
1928 ;; which case they will prompt about adding to the diary). The
1929 ;; message formats recognized are customizable through
1930 ;; `diary-outlook-formats'.
1932 (defcustom diary-outlook-formats
1934 ;; When: 11 October 2001 12:00-14:00 (GMT) Greenwich Mean Time : Dublin, ...
1935 ;; [Current UK format? The timezone is meaningless. Sometimes the
1936 ;; Where is missing.]
1937 ("When: \\([0-9]+ [[:alpha:]]+ [0-9]+\\) \
1940 \\(?:Where: \\([^\n]+\\)\n+\\)?
1941 \\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*"
1942 .
"\\1\n \\2 %s, \\3")
1943 ;; When: Tuesday, April 30, 2002 03:00 PM-03:30 PM (GMT) Greenwich Mean ...
1945 ("^When: [[:alpha:]]+, \\([[:alpha:]]+\\) \\([0-9][0-9]*\\), \\([0-9]\\{4\\}\\) \
1948 \\(?:Where: \\([^\n]+\\)\\)?\n+"
1949 .
"\\2 \\1 \\3\n \\4 %s, \\5")
1951 ;; German format, apparently.
1952 "^Zeit: [^ ]+, +\\([0-9]+\\)\. +\\([[:upper:]][[:lower:]][[:lower:]]\\)[^ ]* +\\([0-9]+\\) +\\([^ ]+\\).*$"
1953 .
"\\1 \\2 \\3\n \\4 %s"))
1954 "Alist of regexps matching message text and replacement text.
1956 The regexp must match the start of the message text containing an
1957 appointment, but need not include a leading `^'. If it matches the
1958 current message, a diary entry is made from the corresponding
1959 template. If the template is a string, it should be suitable for
1960 passing to `replace-match', and so will have occurrences of `\\D' to
1961 substitute the match for the Dth subexpression. It must also contain
1962 a single `%s' which will be replaced with the text of the message's
1963 Subject field. Any other `%' characters must be doubled, so that the
1964 template can be passed to `format'.
1966 If the template is actually a function, it is called with the message
1967 body text as argument, and may use `match-string' etc. to make a
1968 template following the rules above."
1969 :type
'(alist :key-type
(regexp :tag
"Regexp matching time/place")
1971 (string :tag
"Template for entry")
1972 (function :tag
"Unary function providing template")))
1977 ;; Dynamically bound.
1981 (defun diary-from-outlook-internal (&optional test-only
)
1982 "Snarf a diary entry from a message assumed to be from MS Outlook.
1983 Assumes `body' is bound to a string comprising the body of the message and
1984 `subject' is bound to a string comprising its subject.
1985 Arg TEST-ONLY non-nil means return non-nil if and only if the
1986 message contains an appointment, don't make a diary entry."
1988 (let (format-string)
1989 (dotimes (i (length diary-outlook-formats
))
1990 (when (eq 0 (string-match (car (nth i diary-outlook-formats
))
1993 (setq format-string
(cdr (nth i diary-outlook-formats
)))
1995 (save-window-excursion
1996 ;; Fixme: References to optional fields in the format
1997 ;; are treated literally, not replaced by the empty
1998 ;; string. I think this is an Emacs bug.
2000 (format (replace-match (if (functionp format-string
)
2001 (funcall format-string body
)
2003 t nil
(match-string 0 body
))
2006 (throw 'finished t
))))
2009 (defun diary-from-outlook (&optional noconfirm
)
2010 "Maybe snarf diary entry from current Outlook-generated message.
2011 Currently knows about Gnus and Rmail modes. Unless the optional
2012 argument NOCONFIRM is non-nil (which is the case when this
2013 function is called interactively), then if an entry is found the
2014 user is asked to confirm its addition."
2017 ((eq major-mode
'rmail-mode
)
2018 #'diary-from-outlook-rmail
)
2019 ((memq major-mode
'(gnus-summary-mode gnus-article-mode
))
2020 #'diary-from-outlook-gnus
)
2021 (t (error "Don't know how to snarf in `%s'" major-mode
)))))
2022 (funcall func noconfirm
)))
2025 (defvar gnus-article-mime-handles
)
2026 (defvar gnus-article-buffer
)
2028 (autoload 'gnus-fetch-field
"gnus-util")
2029 (autoload 'gnus-narrow-to-body
"gnus")
2030 (autoload 'mm-get-part
"mm-decode")
2032 (defun diary-from-outlook-gnus (&optional noconfirm
)
2033 "Maybe snarf diary entry from Outlook-generated message in Gnus.
2034 Unless the optional argument NOCONFIRM is non-nil (which is the case when
2035 this function is called interactively), then if an entry is found the
2036 user is asked to confirm its addition.
2037 Add this function to `gnus-article-prepare-hook' to notice appointments
2040 (with-current-buffer gnus-article-buffer
2041 (let ((subject (gnus-fetch-field "subject"))
2042 (body (if gnus-article-mime-handles
2043 ;; We're multipart. Don't get confused by part
2044 ;; buttons &c. Assume info is in first part.
2045 (mm-get-part (nth 1 gnus-article-mime-handles
))
2047 (gnus-narrow-to-body)
2049 (when (diary-from-outlook-internal t
)
2050 (when (or noconfirm
(y-or-n-p "Snarf diary entry? "))
2051 (diary-from-outlook-internal)
2052 (message "Diary entry added"))))))
2054 (custom-add-option 'gnus-article-prepare-hook
'diary-from-outlook-gnus
)
2057 (defvar rmail-buffer
)
2059 (defun diary-from-outlook-rmail (&optional noconfirm
)
2060 "Maybe snarf diary entry from Outlook-generated message in Rmail.
2061 Unless the optional argument NOCONFIRM is non-nil (which is the case when
2062 this function is called interactively), then if an entry is found the
2063 user is asked to confirm its addition."
2065 (with-current-buffer rmail-buffer
2066 (let ((subject (mail-fetch-field "subject"))
2067 (body (buffer-substring (save-excursion
2071 (when (diary-from-outlook-internal t
)
2072 (when (or noconfirm
(y-or-n-p "Snarf diary entry? "))
2073 (diary-from-outlook-internal)
2074 (message "Diary entry added"))))))
2077 (provide 'diary-lib
)
2079 ;; arch-tag: 22dd506e-2e33-410d-9ae1-095a0c1b2010
2080 ;;; diary-lib.el ends here