(calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
[emacs.git] / lisp / calendar / diary-lib.el
blobdae56f9428d9d936e9b026043206d8b2b1bf69be
1 ;;; diary-lib.el --- diary functions
3 ;; Copyright (C) 1989, 1990, 1992, 1993, 1994, 1995, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
8 ;; Keywords: calendar
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 3, or (at your option)
15 ;; any later version.
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.
27 ;;; Commentary:
29 ;; This collection of functions implements the diary features as described
30 ;; in calendar.el.
32 ;;; Code:
34 (require 'calendar)
36 (eval-and-compile
37 (load "diary-loaddefs" nil 'quiet))
39 (defcustom diary-include-string "#include"
40 "The string indicating inclusion of another file of diary entries.
41 See the documentation for the function `include-other-diary-files'."
42 :type 'string
43 :group 'diary)
45 (defcustom diary-list-include-blanks nil
46 "If nil, do not include days with no diary entry in the list of diary entries.
47 Such days will then not be shown in the fancy diary buffer, even if they
48 are holidays."
49 :type 'boolean
50 :group 'diary)
52 (defcustom diary-face 'diary
53 "Face name to use for diary entries."
54 :type 'face
55 :group 'diary)
56 (make-obsolete-variable 'diary-face "customize the face `diary' instead."
57 "23.1")
59 ;; Face markup of calendar and diary displays: Any entry line that
60 ;; ends with [foo:value] where foo is a face attribute (except :box
61 ;; :stipple) or with [face:blah] tags, will have these values applied
62 ;; to the calendar and fancy diary displays. These attributes "stack"
63 ;; on calendar displays. File-wide attributes can be defined as
64 ;; follows: the first line matching "^# [tag:value]" defines the value
65 ;; for that particular tag.
66 (defcustom diary-face-attrs
67 '((" *\\[foreground:\\([-a-z]+\\)\\]$" 1 :foreground string)
68 (" *\\[background:\\([-a-z]+\\)\\]$" 1 :background string)
69 (" *\\[width:\\([-a-z]+\\)\\]$" 1 :width symbol)
70 (" *\\[height:\\([-0-9a-z]+\\)\\]$" 1 :height int)
71 (" *\\[weight:\\([-a-z]+\\)\\]$" 1 :weight symbol)
72 (" *\\[slant:\\([-a-z]+\\)\\]$" 1 :slant symbol)
73 (" *\\[underline:\\([-a-z]+\\)\\]$" 1 :underline stringtnil)
74 (" *\\[overline:\\([-a-z]+\\)\\]$" 1 :overline stringtnil)
75 (" *\\[strike-through:\\([-a-z]+\\)\\]$" 1 :strike-through stringtnil)
76 (" *\\[inverse-video:\\([-a-z]+\\)\\]$" 1 :inverse-video tnil)
77 (" *\\[face:\\([-0-9a-z]+\\)\\]$" 1 :face string)
78 (" *\\[font:\\([-a-z0-9]+\\)\\]$" 1 :font string)
79 ;; Unsupported.
80 ;;; (" *\\[box:\\([-a-z]+\\)\\]$" 1 :box)
81 ;;; (" *\\[stipple:\\([-a-z]+\\)\\]$" 1 :stipple)
83 "Alist of (REGEXP SUBEXP ATTRIBUTE TYPE) elements.
84 This is used by `diary-pull-attrs' to fontify certain diary
85 elements. REGEXP is a regular expression to for, and SUBEXP is
86 the numbered sub-expression to extract. `diary-glob-file-regexp-prefix'
87 is prepended to REGEXP for file-wide specifiers. ATTRIBUTE
88 specifies which face attribute (e.g. `:foreground') to modify, or
89 that this is a face (`:face') to apply. TYPE is the type of
90 attribute being applied. Available TYPES (see `diary-attrtype-convert')
91 are: `string', `symbol', `int', `tnil',`stringtnil.'"
92 :type '(repeat (list (string :tag "Regular expression")
93 (integer :tag "Sub-expression")
94 (symbol :tag "Attribute (e.g. :foreground)")
95 (choice (const string :tag "A string")
96 (const symbol :tag "A symbol")
97 (const int :tag "An integer")
98 (const tnil :tag "`t' or `nil'")
99 (const stringtnil
100 :tag "A string, `t', or `nil'"))))
101 :group 'diary)
103 (defcustom diary-glob-file-regexp-prefix "^\\#"
104 "Regular expression prepended to `diary-face-attrs' for file-wide specifiers."
105 :type 'regexp
106 :group 'diary)
108 (defcustom diary-file-name-prefix nil
109 "Non-nil means prefix each diary entry with the name of the file defining it."
110 :type 'boolean
111 :group 'diary)
113 (defcustom diary-file-name-prefix-function 'identity
114 "The function that will take a diary file name and return the desired prefix."
115 :type 'function
116 :group 'diary)
118 (defcustom sexp-diary-entry-symbol "%%"
119 "The string used to indicate a sexp diary entry in `diary-file'.
120 See the documentation for the function `list-sexp-diary-entries'."
121 :type 'string
122 :group 'diary)
124 (defcustom list-diary-entries-hook nil
125 "List of functions called after diary file is culled for relevant entries.
126 It is to be used for diary entries that are not found in the diary file.
128 A function `include-other-diary-files' is provided for use as the value of
129 this hook. This function enables you to use shared diary files together
130 with your own. The files included are specified in the diary file by lines
131 of the form
133 #include \"filename\"
135 This is recursive; that is, #include directives in files thus included are
136 obeyed. You can change the \"#include\" to some other string by changing
137 the variable `diary-include-string'. When you use `include-other-diary-files'
138 as part of the list-diary-entries-hook, you will probably also want to use the
139 function `mark-included-diary-files' as part of `mark-diary-entries-hook'.
141 For example, you could use
143 (add-hook 'list-diary-entries-hook 'include-other-diary-files)
144 (add-hook 'list-diary-entries-hook 'sort-diary-entries)
145 (add-hook 'diary-display-hook 'fancy-diary-display)
147 in your `.emacs' file to cause the fancy diary buffer to be displayed with
148 diary entries from various included files, each day's entries sorted into
149 lexicographic order."
150 :type 'hook
151 :options '(include-other-diary-files sort-diary-entries)
152 :group 'diary)
154 (defcustom mark-diary-entries-hook nil
155 "List of functions called after marking diary entries in the calendar.
157 A function `mark-included-diary-files' is also provided for use as the
158 `mark-diary-entries-hook'; it enables you to use shared diary files together
159 with your own. The files included are specified in the diary file by lines
160 of the form
161 #include \"filename\"
162 This is recursive; that is, #include directives in files thus included are
163 obeyed. You can change the \"#include\" to some other string by changing the
164 variable `diary-include-string'. When you use `mark-included-diary-files' as
165 part of the mark-diary-entries-hook, you will probably also want to use the
166 function `include-other-diary-files' as part of `list-diary-entries-hook'."
167 :type 'hook
168 :options '(mark-included-diary-files)
169 :group 'diary)
171 (defcustom nongregorian-diary-listing-hook nil
172 "List of functions called for listing diary file and included files.
173 As the files are processed for diary entries, these functions are used
174 to cull relevant entries. You can use either or both of
175 `list-hebrew-diary-entries', `list-islamic-diary-entries' and
176 `diary-bahai-list-entries'. The documentation for these functions
177 describes the style of such diary entries."
178 :type 'hook
179 :options '(list-hebrew-diary-entries
180 list-islamic-diary-entries
181 diary-bahai-list-entries)
182 :group 'diary)
184 (defcustom nongregorian-diary-marking-hook nil
185 "List of functions called for marking diary file and included files.
186 As the files are processed for diary entries, these functions are used
187 to cull relevant entries. You can use either or both of
188 `mark-hebrew-diary-entries', `mark-islamic-diary-entries' and
189 `bahai-mark-diary-entries'. The documentation for these functions
190 describes the style of such diary entries."
191 :type 'hook
192 :options '(mark-hebrew-diary-entries
193 mark-islamic-diary-entries
194 diary-bahai-mark-entries)
195 :group 'diary)
197 (defcustom print-diary-entries-hook 'lpr-buffer
198 "List of functions called after a temporary diary buffer is prepared.
199 The buffer shows only the diary entries currently visible in the diary
200 buffer. The default just does the printing. Other uses might include, for
201 example, rearranging the lines into order by day and time, saving the buffer
202 instead of deleting it, or changing the function used to do the printing."
203 :type 'hook
204 :group 'diary)
206 (defcustom diary-unknown-time -9999
207 "Value returned by `diary-entry-time' when no time is found.
208 The default value -9999 causes entries with no recognizable time to be placed
209 before those with times; 9999 would place entries with no recognizable time
210 after those with times."
211 :type 'integer
212 :group 'diary
213 :version "20.3")
215 (defcustom diary-mail-addr
216 (if (boundp 'user-mail-address) user-mail-address "")
217 "Email address that `diary-mail-entries' will send email to."
218 :group 'diary
219 :type 'string
220 :version "20.3")
222 (defcustom diary-mail-days 7
223 "Default number of days for `diary-mail-entries' to check."
224 :group 'diary
225 :type 'integer
226 :version "20.3")
228 (defcustom diary-remind-message
229 '("Reminder: Only "
230 (if (zerop (% days 7))
231 (concat (int-to-string (/ days 7)) (if (= 7 days) " week" " weeks"))
232 (concat (int-to-string days) (if (= 1 days) " day" " days")))
233 " until "
234 diary-entry)
235 "Pseudo-pattern giving form of reminder messages in the fancy diary display.
237 Used by the function `diary-remind', a pseudo-pattern is a list of
238 expressions that can involve the keywords `days' (a number), `date' (a list of
239 month, day, year), and `diary-entry' (a string)."
240 :type 'sexp
241 :group 'diary)
243 (defcustom diary-outlook-formats
245 ;; When: 11 October 2001 12:00-14:00 (GMT) Greenwich Mean Time : Dublin, ...
246 ;; [Current UK format? The timezone is meaningless. Sometimes the
247 ;; Where is missing.]
248 ("When: \\([0-9]+ [[:alpha:]]+ [0-9]+\\) \
249 \\([^ ]+\\) [^\n]+
250 \[^\n]+
251 \\(?:Where: \\([^\n]+\\)\n+\\)?
252 \\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*"
253 . "\\1\n \\2 %s, \\3")
254 ;; When: Tuesday, April 30, 2002 03:00 PM-03:30 PM (GMT) Greenwich Mean ...
255 ;; [Old UK format?]
256 ("^When: [[:alpha:]]+, \\([[:alpha:]]+\\) \\([0-9][0-9]*\\), \\([0-9]\\{4\\}\\) \
257 \\([^ ]+\\) [^\n]+
258 \[^\n]+
259 \\(?:Where: \\([^\n]+\\)\\)?\n+"
260 . "\\2 \\1 \\3\n \\4 %s, \\5")
262 ;; German format, apparently.
263 "^Zeit: [^ ]+, +\\([0-9]+\\)\. +\\([[:upper:]][[:lower:]][[:lower:]]\\)[^ ]* +\\([0-9]+\\) +\\([^ ]+\\).*$"
264 . "\\1 \\2 \\3\n \\4 %s"))
265 "Alist of regexps matching message text and replacement text.
267 The regexp must match the start of the message text containing an
268 appointment, but need not include a leading `^'. If it matches the
269 current message, a diary entry is made from the corresponding
270 template. If the template is a string, it should be suitable for
271 passing to `replace-match', and so will have occurrences of `\\D' to
272 substitute the match for the Dth subexpression. It must also contain
273 a single `%s' which will be replaced with the text of the message's
274 Subject field. Any other `%' characters must be doubled, so that the
275 template can be passed to `format'.
277 If the template is actually a function, it is called with the message
278 body text as argument, and may use `match-string' etc. to make a
279 template following the rules above."
280 :type '(alist :key-type (regexp :tag "Regexp matching time/place")
281 :value-type (choice
282 (string :tag "Template for entry")
283 (function :tag
284 "Unary function providing template")))
285 :version "22.1"
286 :group 'diary)
288 ;;; More user options below and in calendar.el.
291 (defun diary-check-diary-file ()
292 "Check that the file specified by `diary-file' exists and is readable.
293 If so, return the expanded file name, otherwise signal an error."
294 (let ((d-file (substitute-in-file-name diary-file)))
295 (if (and d-file (file-exists-p d-file))
296 (if (file-readable-p d-file)
297 d-file
298 (error "Diary file `%s' is not readable" diary-file))
299 (error "Diary file `%s' does not exist" diary-file))))
301 ;;;###autoload
302 (defun diary (&optional arg)
303 "Generate the diary window for ARG days starting with the current date.
304 If no argument is provided, the number of days of diary entries is governed
305 by the variable `number-of-diary-entries'. A value of ARG less than 1
306 does nothing. This function is suitable for execution in a `.emacs' file."
307 (interactive "P")
308 (diary-check-diary-file)
309 (let ((date (calendar-current-date)))
310 (diary-list-entries date (if arg (prefix-numeric-value arg)))))
312 (define-obsolete-function-alias 'view-diary-entries 'diary-view-entries)
313 ;;;###cal-autoload
314 (defun diary-view-entries (&optional arg)
315 "Prepare and display a buffer with diary entries.
316 Searches the file named in `diary-file' for entries that
317 match ARG days starting with the date indicated by the cursor position
318 in the displayed three-month calendar."
319 (interactive "p")
320 (diary-check-diary-file)
321 (diary-list-entries (calendar-cursor-to-date t) arg))
323 ;;;###cal-autoload
324 (defun view-other-diary-entries (arg d-file)
325 "Prepare and display buffer of diary entries from an alternative diary file.
326 Searches for entries that match ARG days, starting with the date indicated
327 by the cursor position in the displayed three-month calendar.
328 D-FILE specifies the file to use as the diary file."
329 (interactive
330 (list (prefix-numeric-value current-prefix-arg)
331 (read-file-name "Enter diary file name: " default-directory nil t)))
332 (let ((diary-file d-file))
333 (diary-view-entries arg)))
335 (defvar diary-syntax-table
336 (let ((st (copy-syntax-table (standard-syntax-table))))
337 (modify-syntax-entry ?* "w" st)
338 (modify-syntax-entry ?: "w" st)
340 "The syntax table used when parsing dates in the diary file.
341 It is the standard syntax table used in Fundamental mode, but with the
342 syntax of `*' and `:' changed to be word constituents.")
344 (defun diary-attrtype-convert (attrvalue type)
345 "Convert string ATTRVALUE to TYPE appropriate for a face description.
346 Valid TYPEs are: string, symbol, int, stringtnil, tnil."
347 (cond ((eq type 'string) attrvalue)
348 ((eq type 'symbol) (read attrvalue)) ; FIXME intern-soft?
349 ((eq type 'int) (string-to-number attrvalue))
350 ((eq type 'stringtnil)
351 (cond ((string-equal "t" attrvalue) t)
352 ((string-equal "nil" attrvalue) nil)
353 (t attrvalue)))
354 ((eq type 'tnil) (string-equal "t" attrvalue))))
356 (defun diary-pull-attrs (entry fileglobattrs)
357 "Search for matches for regexps from `diary-face-attrs'.
358 If ENTRY is nil, searches from the start of the current buffer, and
359 prepends all regexps with `diary-glob-file-regexp-prefix'.
360 If ENTRY is a string, search for matches in that string, and remove them.
361 Returns a list of ENTRY followed by (ATTRIBUTE VALUE) pairs.
362 When ENTRY is non-nil, FILEGLOBATTRS forms the start of the (ATTRIBUTE VALUE)
363 pairs."
364 (let (regexp regnum attrname attrname attrvalue type ret-attr)
365 (if (null entry)
366 (save-excursion
367 (dolist (attr diary-face-attrs)
368 ;; FIXME inefficient searching.
369 (goto-char (point-min))
370 (setq regexp (concat diary-glob-file-regexp-prefix (car attr))
371 regnum (cadr attr)
372 attrname (nth 2 attr)
373 type (nth 3 attr)
374 attrvalue (if (re-search-forward regexp nil t)
375 (match-string-no-properties regnum)))
376 (and attrvalue
377 (setq attrvalue (diary-attrtype-convert attrvalue type))
378 (setq ret-attr (append ret-attr
379 (list attrname attrvalue))))))
380 (setq ret-attr fileglobattrs)
381 (dolist (attr diary-face-attrs)
382 (setq regexp (car attr)
383 regnum (cadr attr)
384 attrname (nth 2 attr)
385 type (nth 3 attr)
386 attrvalue nil)
387 ;; FIXME multiple matches?
388 (if (string-match regexp entry)
389 (setq attrvalue (match-string-no-properties regnum entry)
390 entry (replace-match "" t t entry)))
391 (and attrvalue
392 (setq attrvalue (diary-attrtype-convert attrvalue type))
393 (setq ret-attr (append ret-attr (list attrname attrvalue))))))
394 (list entry ret-attr)))
396 ;;;###cal-autoload
397 (defun diary-set-maybe-redraw (symbol value)
398 "Set SYMBOL's value to VALUE, and redraw the diary if necessary.
399 Redraws the diary if it is being displayed (note this is not the same as
400 just visiting the `diary-file'), and SYMBOL's value is to be changed."
401 (let ((oldvalue (eval symbol)))
402 (custom-set-default symbol value)
403 (and (not (equal value oldvalue))
404 (diary-live-p)
405 ;; Note this assumes diary was called without prefix arg.
406 (diary))))
408 ;; This can be removed once the kill/yank treatment of invisible text
409 ;; (see etc/TODO) is fixed. -- gm
410 (defcustom diary-header-line-flag t
411 "Non-nil means `simple-diary-display' will show a header line.
412 The format of the header is specified by `diary-header-line-format'."
413 :group 'diary
414 :type 'boolean
415 :initialize 'custom-initialize-default
416 ;; FIXME overkill.
417 :set 'diary-set-maybe-redraw
418 :version "22.1")
420 (defvar diary-selective-display nil)
422 (defcustom diary-header-line-format
423 '(:eval (calendar-string-spread
424 (list (if diary-selective-display
425 "Selective display active - press \"s\" in calendar \
426 before edit/copy"
427 "Diary"))
428 ?\s (frame-width)))
429 "Format of the header line displayed by `simple-diary-display'.
430 Only used if `diary-header-line-flag' is non-nil."
431 :group 'diary
432 :type 'sexp
433 :initialize 'custom-initialize-default
434 ;; FIXME overkill.
435 :set 'diary-set-maybe-redraw
436 :version "22.1")
438 ;; The first version of this also checked for diary-selective-display
439 ;; in the non-fancy case. This was an attempt to distinguish between
440 ;; displaying the diary and just visiting the diary file. However,
441 ;; when using fancy diary, calling diary when there are no entries to
442 ;; display does not create the fancy buffer, nor does it switch on
443 ;; selective-display in the diary buffer. This means some
444 ;; customizations will not take effect, eg:
445 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-03/msg00466.html
446 ;; So the check for selective-display was dropped. This means the
447 ;; diary will be displayed if one customizes a diary variable while
448 ;; just visiting the diary-file. This is i) unlikely, and ii) no great loss.
449 ;;;###cal-autoload
450 (defun diary-live-p ()
451 "Return non-nil if the diary is being displayed."
452 (or (get-buffer fancy-diary-buffer)
453 (and diary-file
454 (find-buffer-visiting (substitute-in-file-name diary-file)))))
456 (defcustom number-of-diary-entries 1
457 "Specifies how many days of diary entries are to be displayed initially.
458 This variable affects the diary display when the command \\[diary] is used,
459 or if the value of the variable `view-diary-entries-initially' is t. For
460 example, if the default value 1 is used, then only the current day's diary
461 entries will be displayed. If the value 2 is used, then both the current
462 day's and the next day's entries will be displayed.
464 The value can also be a vector such as [0 2 2 2 2 4 1]; this value
465 says to display no diary entries on Sunday, the entries for
466 the current date and the day after on Monday through Thursday,
467 Friday through Monday's entries on Friday, and only Saturday's
468 entries on Saturday.
470 This variable does not affect the diary display with the `d' command
471 from the calendar; in that case, the prefix argument controls the
472 number of days of diary entries displayed."
473 :type '(choice (integer :tag "Entries")
474 (vector :value [0 0 0 0 0 0 0]
475 (integer :tag "Sunday")
476 (integer :tag "Monday")
477 (integer :tag "Tuesday")
478 (integer :tag "Wednesday")
479 (integer :tag "Thursday")
480 (integer :tag "Friday")
481 (integer :tag "Saturday")))
482 :initialize 'custom-initialize-default
483 :set 'diary-set-maybe-redraw
484 :group 'diary)
487 (defvar diary-modify-entry-list-string-function nil
488 "Function applied to entry string before putting it into the entries list.
489 Can be used by programs integrating a diary list into other buffers (e.g.
490 org.el and planner.el) to modify the string or add properties to it.
491 The function takes a string argument and must return a string.")
493 (defvar diary-entries-list) ; bound in diary-list-entries
495 (defun add-to-diary-list (date string specifier &optional marker
496 globcolor literal)
497 "Add an entry to `diary-entries-list'.
498 Do nothing if DATE or STRING is nil. DATE is the (MONTH DAY
499 YEAR) for which the entry applies; STRING is the text of the
500 entry as it will appear in the diary (i.e. with any format
501 strings such as \"%d\" expanded); SPECIFIER is the date part of
502 the entry as it appears in the diary-file; LITERAL is the entry
503 as it appears in the diary-file (i.e. before expansion). If
504 LITERAL is nil, it is taken to be the same as STRING.
506 The entry is added to the list as (DATE STRING SPECIFIER LOCATOR
507 GLOBCOLOR), where LOCATOR has the form (MARKER FILENAME LITERAL),
508 FILENAME being the file containing the diary entry."
509 (when (and date string)
510 (if diary-file-name-prefix
511 (let ((prefix (funcall diary-file-name-prefix-function
512 (buffer-file-name))))
513 (or (string-equal prefix "")
514 (setq string (format "[%s] %s" prefix string)))))
515 (and diary-modify-entry-list-string-function
516 (setq string (funcall diary-modify-entry-list-string-function
517 string)))
518 (setq diary-entries-list
519 (append diary-entries-list
520 (list (list date string specifier
521 (list marker (buffer-file-name) literal)
522 globcolor))))))
524 (define-obsolete-function-alias 'list-diary-entries 'diary-list-entries)
525 (defun diary-list-entries (date number &optional list-only)
526 "Create and display a buffer containing the relevant lines in `diary-file'.
527 The arguments are DATE and NUMBER; the entries selected are those
528 for NUMBER days starting with date DATE. The other entries are hidden
529 using selective display. If NUMBER is less than 1, this function does nothing.
531 Returns a list of all relevant diary entries found, if any, in order by date.
532 The list entries have the form ((MONTH DAY YEAR) STRING SPECIFIER) where
533 \(MONTH DAY YEAR) is the date of the entry, STRING is the entry text, and
534 SPECIFIER is the applicability. If the variable `diary-list-include-blanks'
535 is t, this list includes a dummy diary entry consisting of the empty string
536 for a date with no diary entries.
538 After the list is prepared, the hooks `nongregorian-diary-listing-hook',
539 `list-diary-entries-hook', `diary-display-hook', and `diary-hook' are run.
540 These hooks have the following distinct roles:
542 `nongregorian-diary-listing-hook' can cull dates from the diary
543 and each included file. Usually used for Hebrew or Islamic
544 diary entries in files. Applied to *each* file.
546 `list-diary-entries-hook' adds or manipulates diary entries from
547 external sources. Used, for example, to include diary entries
548 from other files or to sort the diary entries. Invoked *once* only,
549 before the display hook is run.
551 `diary-display-hook' does the actual display of information. If this is
552 nil, `simple-diary-display' will be used. Use `add-hook' to use
553 `fancy-diary-display', if desired. If you want no diary display, use
554 add-hook to set this to `ignore'.
556 `diary-hook' is run last. This can be used for an appointment
557 notification function.
559 Functions called by these hooks may use the variables ORIGINAL-DATE
560 and NUMBER, which are the arguments with which this function was called.
561 Note that hook functions should _not_ use DATE, but ORIGINAL-DATE.
562 \(Sexp diary entries may use DATE - see `list-sexp-diary-entries'.)
564 If LIST-ONLY is non-nil don't modify or display the buffer, only return a list."
565 (unless number
566 (setq number (if (vectorp number-of-diary-entries)
567 (aref number-of-diary-entries (calendar-day-of-week date))
568 number-of-diary-entries)))
569 (when (> number 0)
570 (let ((original-date date) ; save for possible use in the hooks
571 diary-entries-list
572 file-glob-attrs
573 (date-string (calendar-date-string date))
574 (d-file (substitute-in-file-name diary-file)))
575 (message "Preparing diary...")
576 (save-excursion
577 (let ((diary-buffer (find-buffer-visiting d-file)))
578 (if (not diary-buffer)
579 (set-buffer (find-file-noselect d-file t))
580 (set-buffer diary-buffer)
581 (or (verify-visited-file-modtime diary-buffer)
582 (revert-buffer t t))))
583 ;; Setup things like the header-line-format and invisibility-spec.
584 (if (eq major-mode default-major-mode)
585 (diary-mode)
586 ;; This kludge is to make customizations to
587 ;; diary-header-line-flag after diary has been displayed
588 ;; take effect. Unconditionally calling (diary-mode)
589 ;; clobbers file local variables.
590 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-03/msg00363.html
591 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-04/msg00404.html
592 (if (eq major-mode 'diary-mode)
593 (setq header-line-format (and diary-header-line-flag
594 diary-header-line-format))))
595 ;; d-s-p is passed to the diary display function.
596 (let ((diary-saved-point (point)))
597 (save-excursion
598 (setq file-glob-attrs (nth 1 (diary-pull-attrs nil "")))
599 (with-syntax-table diary-syntax-table
600 (let ((mark (regexp-quote diary-nonmarking-symbol)))
601 (goto-char (point-min))
602 (unless list-only
603 (let ((ol (make-overlay (point-min) (point-max) nil t nil)))
604 (set (make-local-variable 'diary-selective-display) t)
605 (overlay-put ol 'invisible 'diary)
606 (overlay-put ol 'evaporate t)))
607 (dotimes (idummy number)
608 (let ((month (extract-calendar-month date))
609 (day (extract-calendar-day date))
610 (year (extract-calendar-year date))
611 (entry-found (list-sexp-diary-entries date)))
612 (dolist (date-form diary-date-forms)
613 (let* ((backup (when (eq (car date-form) 'backup)
614 (setq date-form (cdr date-form))
616 (dayname
617 (format "%s\\|%s\\.?"
618 (calendar-day-name date)
619 (calendar-day-name date 'abbrev)))
620 (monthname
621 (format "\\*\\|%s\\|%s\\.?"
622 (calendar-month-name month)
623 (calendar-month-name month 'abbrev)))
624 (month (concat "\\*\\|0*" (int-to-string month)))
625 (day (concat "\\*\\|0*" (int-to-string day)))
626 (year
627 (concat
628 "\\*\\|0*" (int-to-string year)
629 (if abbreviated-calendar-year
630 (concat "\\|" (format "%02d" (% year 100)))
631 "")))
632 (regexp
633 (concat
634 "^" mark "?\\("
635 ;; This must be let* so that date-form
636 ;; can use day etc.
637 (mapconcat 'eval date-form "\\)\\(?:")
638 "\\)"))
639 (case-fold-search t))
640 (goto-char (point-min))
641 (while (re-search-forward regexp nil t)
642 (if backup (re-search-backward "\\<" nil t))
643 (if (and (bolp) (not (looking-at "[ \t]")))
644 ;; Diary entry that consists only of date.
645 (backward-char 1)
646 ;; Found a nonempty diary entry--make it
647 ;; visible and add it to the list.
648 (setq entry-found t)
649 (if (looking-at "[ \t]*\n[ \t]") (forward-line 1))
650 (let ((entry-start (point))
651 date-start temp)
652 (setq date-start
653 (line-end-position
654 (if (and (bolp) (> number 1)) -1 0)))
655 (forward-line 1)
656 (while (looking-at "[ \t]")
657 (forward-line 1))
658 (unless (and (eobp) (not (bolp)))
659 (backward-char 1))
660 (unless list-only
661 (remove-overlays date-start (point)
662 'invisible 'diary))
663 (setq temp (diary-pull-attrs
664 (buffer-substring entry-start (point))
665 file-glob-attrs))
666 (add-to-diary-list
667 date
668 (car temp)
669 (buffer-substring
670 (1+ date-start) (1- entry-start))
671 (copy-marker entry-start) (nth 1 temp)))))))
672 (or entry-found
673 (not diary-list-include-blanks)
674 (add-to-diary-list date "" "" "" ""))
675 (setq date
676 (calendar-gregorian-from-absolute
677 (1+ (calendar-absolute-from-gregorian date))))
678 (setq entry-found nil)))))
679 (goto-char (point-min))
680 (run-hooks 'nongregorian-diary-listing-hook
681 'list-diary-entries-hook)
682 (unless list-only
683 (if diary-display-hook
684 (run-hooks 'diary-display-hook)
685 (simple-diary-display)))
686 (run-hooks 'diary-hook)
687 diary-entries-list))))))
689 (defun diary-unhide-everything ()
690 "Show all invisible text in the diary."
691 (kill-local-variable 'diary-selective-display)
692 (remove-overlays (point-min) (point-max) 'invisible 'diary)
693 (kill-local-variable 'mode-line-format))
695 (defvar original-date) ; bound in diary-list-entries
696 (defvar number)
698 (defun include-other-diary-files ()
699 "Include the diary entries from other diary files with those of `diary-file'.
700 This function is suitable for use in `list-diary-entries-hook';
701 it enables you to use shared diary files together with your own.
702 The files included are specified in the `diary-file' by lines of this form:
703 #include \"filename\"
704 This is recursive; that is, #include directives in diary files thus included
705 are obeyed. You can change the `#include' to some other string by
706 changing the variable `diary-include-string'."
707 (goto-char (point-min))
708 (while (re-search-forward
709 (concat
711 (regexp-quote diary-include-string)
712 " \"\\([^\"]*\\)\"")
713 nil t)
714 (let ((diary-file (substitute-in-file-name
715 (match-string-no-properties 1)))
716 (diary-list-include-blanks nil)
717 (list-diary-entries-hook 'include-other-diary-files)
718 (diary-display-hook 'ignore)
719 (diary-hook nil))
720 (if (file-exists-p diary-file)
721 (if (file-readable-p diary-file)
722 (unwind-protect
723 (setq diary-entries-list
724 (append diary-entries-list
725 (diary-list-entries original-date number)))
726 (with-current-buffer (find-buffer-visiting diary-file)
727 (diary-unhide-everything)))
728 (beep)
729 (message "Can't read included diary file %s" diary-file)
730 (sleep-for 2))
731 (beep)
732 (message "Can't find included diary file %s" diary-file)
733 (sleep-for 2))))
734 (goto-char (point-min)))
736 ;; Bound in diary-list-entries.
737 (defvar date-string)
738 (defvar diary-saved-point)
740 (defun simple-diary-display ()
741 "Display the diary buffer if there are any relevant entries or holidays."
742 (let* ((holiday-list (if holidays-in-diary-buffer
743 (calendar-check-holidays original-date)))
744 (hol-string (format "%s%s%s"
745 date-string
746 (if holiday-list ": " "")
747 (mapconcat 'identity holiday-list "; ")))
748 (msg (format "No diary entries for %s" hol-string))
749 ;; If selected window is dedicated (to the calendar),
750 ;; need a new one to display the diary.
751 (pop-up-frames (or pop-up-frames
752 (window-dedicated-p (selected-window)))))
753 (calendar-set-mode-line (format "Diary for %s" hol-string))
754 (if (or (not diary-entries-list)
755 (and (not (cdr diary-entries-list))
756 (string-equal (car (cdr (car diary-entries-list))) "")))
757 (if (< (length msg) (frame-width))
758 (message "%s" msg)
759 (set-buffer (get-buffer-create holiday-buffer))
760 (setq buffer-read-only nil)
761 (calendar-set-mode-line date-string)
762 (erase-buffer)
763 (insert (mapconcat 'identity holiday-list "\n"))
764 (goto-char (point-min))
765 (set-buffer-modified-p nil)
766 (setq buffer-read-only t)
767 (display-buffer holiday-buffer)
768 (message "No diary entries for %s" date-string))
769 (with-current-buffer
770 (find-buffer-visiting (substitute-in-file-name diary-file))
771 (let ((window (display-buffer (current-buffer))))
772 ;; d-s-p is passed from diary-list-entries.
773 (set-window-point window diary-saved-point)
774 (set-window-start window (point-min))))
775 (message "Preparing diary...done"))))
777 (defface diary-button '((((type pc) (class color))
778 (:foreground "lightblue")))
779 "Default face used for buttons."
780 :version "22.1"
781 :group 'diary)
782 ;; Backward-compatibility alias. FIXME make obsolete.
783 (put 'diary-button-face 'face-alias 'diary-button)
785 (define-button-type 'diary-entry
786 'action #'diary-goto-entry
787 'face 'diary-button)
789 (defun diary-goto-entry (button)
790 "Jump to the diary entry for the button at point."
791 (let* ((locator (button-get button 'locator))
792 (marker (car locator))
793 markbuf file)
794 ;; If marker pointing to diary location is valid, use that.
795 (if (and marker (setq markbuf (marker-buffer marker)))
796 (progn
797 (pop-to-buffer markbuf)
798 (goto-char (marker-position marker)))
799 ;; Marker is invalid (eg buffer has been killed).
800 (or (and (setq file (cadr locator))
801 (file-exists-p file)
802 (find-file-other-window file)
803 (progn
804 (when (eq major-mode default-major-mode) (diary-mode))
805 (goto-char (point-min))
806 (if (re-search-forward (format "%s.*\\(%s\\)"
807 (regexp-quote (nth 2 locator))
808 (regexp-quote (nth 3 locator)))
809 nil t)
810 (goto-char (match-beginning 1)))))
811 (message "Unable to locate this diary entry")))))
813 (defun fancy-diary-display ()
814 "Prepare a diary buffer with relevant entries in a fancy, noneditable form.
815 This function is provided for optional use as the `diary-display-hook'."
816 ;; Turn off selective-display in the diary file's buffer.
817 (with-current-buffer
818 (find-buffer-visiting (substitute-in-file-name diary-file))
819 (diary-unhide-everything))
820 (if (or (not diary-entries-list)
821 (and (not (cdr diary-entries-list))
822 (string-equal (car (cdr (car diary-entries-list))) "")))
823 (let* ((holiday-list (if holidays-in-diary-buffer
824 (calendar-check-holidays original-date)))
825 (msg (format "No diary entries for %s %s"
826 (concat date-string (if holiday-list ":" ""))
827 (mapconcat 'identity holiday-list "; "))))
828 (if (<= (length msg) (frame-width))
829 (message "%s" msg)
830 (set-buffer (get-buffer-create holiday-buffer))
831 (setq buffer-read-only nil)
832 (erase-buffer)
833 (insert (mapconcat 'identity holiday-list "\n"))
834 (goto-char (point-min))
835 (set-buffer-modified-p nil)
836 (setq buffer-read-only t)
837 (display-buffer holiday-buffer)
838 (message "No diary entries for %s" date-string)))
839 ;; Prepare the fancy diary buffer.
840 (with-current-buffer
841 (make-fancy-diary-buffer)
842 (setq buffer-read-only nil)
843 (let ((entry-list diary-entries-list)
844 (holiday-list)
845 (holiday-list-last-month 1)
846 (holiday-list-last-year 1)
847 (date (list 0 0 0)))
848 (dolist (entry entry-list)
849 (if (not (calendar-date-equal date (car entry)))
850 (progn
851 (setq date (car entry))
852 (and holidays-in-diary-buffer
853 (calendar-date-compare
854 (list (list holiday-list-last-month
855 (calendar-last-day-of-month
856 holiday-list-last-month
857 holiday-list-last-year)
858 holiday-list-last-year))
859 (list date))
860 ;; We need to get the holidays for the next 3 months.
861 (setq holiday-list-last-month
862 (extract-calendar-month date)
863 holiday-list-last-year
864 (extract-calendar-year date))
865 (progn
866 (increment-calendar-month
867 holiday-list-last-month holiday-list-last-year 1)
869 (setq holiday-list
870 (let ((displayed-month holiday-list-last-month)
871 (displayed-year holiday-list-last-year))
872 (calendar-holiday-list)))
873 (increment-calendar-month
874 holiday-list-last-month holiday-list-last-year 1))
875 (let (date-holiday-list)
876 ;; Make a list of all holidays for date.
877 (dolist (h holiday-list)
878 (if (calendar-date-equal date (car h))
879 (setq date-holiday-list (append date-holiday-list
880 (cdr h)))))
881 (insert (if (bobp) "" ?\n) (calendar-date-string date))
882 (if date-holiday-list (insert ": "))
883 (let ((l (current-column))
884 (longest 0))
885 (insert (mapconcat (lambda (x)
886 (if (< longest (length x))
887 (setq longest (length x)))
889 date-holiday-list
890 (concat "\n" (make-string l ? ))))
891 (insert ?\n (make-string (+ l longest) ?=) ?\n)))))
892 (let ((this-entry (cadr entry))
893 this-loc)
894 (unless (zerop (length this-entry))
895 (if (setq this-loc (nth 3 entry))
896 (insert-button (concat this-entry "\n")
897 ;; (MARKER FILENAME SPECIFIER LITERAL)
898 'locator (list (car this-loc)
899 (cadr this-loc)
900 (nth 2 entry)
901 (or (nth 2 this-loc)
902 (nth 1 entry)))
903 :type 'diary-entry)
904 (insert this-entry ?\n))
905 (save-excursion
906 (let* ((marks (nth 4 entry))
907 (faceinfo marks)
908 temp-face)
909 (when marks
910 (setq temp-face (make-symbol
911 (apply
912 'concat "temp-face-"
913 (mapcar (lambda (sym)
914 (if (stringp sym)
916 (symbol-name sym)))
917 marks))))
918 (make-face temp-face)
919 ;; Remove :face info from the marks,
920 ;; copy the face info into temp-face
921 (while (setq faceinfo (memq :face faceinfo))
922 (copy-face (read (nth 1 faceinfo)) temp-face)
923 (setcar faceinfo nil)
924 (setcar (cdr faceinfo) nil))
925 (setq marks (delq nil marks))
926 ;; Apply the font aspects.
927 (apply 'set-face-attribute temp-face nil marks)
928 (search-backward this-entry)
929 (overlay-put
930 (make-overlay (match-beginning 0) (match-end 0))
931 'face temp-face))))))))
932 (set-buffer-modified-p nil)
933 (goto-char (point-min))
934 (setq buffer-read-only t)
935 (display-buffer fancy-diary-buffer)
936 (fancy-diary-display-mode)
937 (calendar-set-mode-line date-string)
938 (message "Preparing diary...done"))))
940 (defun make-fancy-diary-buffer ()
941 "Create and return the initial fancy diary buffer."
942 (with-current-buffer (get-buffer-create fancy-diary-buffer)
943 (setq buffer-read-only nil)
944 (calendar-set-mode-line "Diary Entries")
945 (erase-buffer)
946 (set-buffer-modified-p nil)
947 (setq buffer-read-only t)
948 (get-buffer fancy-diary-buffer)))
950 (defun print-diary-entries ()
951 "Print a hard copy of the diary display.
953 If the simple diary display is being used, prepare a temp buffer with the
954 visible lines of the diary buffer, add a heading line composed from the mode
955 line, print the temp buffer, and destroy it.
957 If the fancy diary display is being used, just print the buffer.
959 The hooks given by the variable `print-diary-entries-hook' are called to do
960 the actual printing."
961 (interactive)
962 (if (bufferp (get-buffer fancy-diary-buffer))
963 (with-current-buffer (get-buffer fancy-diary-buffer)
964 (run-hooks 'print-diary-entries-hook))
965 (let ((diary-buffer
966 (find-buffer-visiting (substitute-in-file-name diary-file))))
967 (if diary-buffer
968 (let ((temp-buffer (get-buffer-create " *Printable Diary Entries*"))
969 (heading))
970 (with-current-buffer diary-buffer
971 (setq heading
972 (if (not (stringp mode-line-format))
973 "All Diary Entries"
974 (string-match "^-*\\([^-].*[^-]\\)-*$" mode-line-format)
975 (match-string 1 mode-line-format)))
976 (let ((start (point-min))
977 end)
978 (while
979 (progn
980 (setq end (next-single-char-property-change
981 start 'invisible))
982 (if (get-char-property start 'invisible)
984 (with-current-buffer temp-buffer
985 (insert-buffer-substring diary-buffer
986 start (or end (point-max)))))
987 (setq start end)
988 (and end (< end (point-max))))))
989 (set-buffer temp-buffer)
990 (goto-char (point-min))
991 (insert heading "\n"
992 (make-string (length heading) ?=) "\n")
993 (run-hooks 'print-diary-entries-hook)
994 (kill-buffer temp-buffer)))
995 (error "You don't have a diary buffer!")))))
997 (define-obsolete-function-alias 'show-all-diary-entries 'diary-show-all-entries)
998 ;;;###cal-autoload
999 (defun diary-show-all-entries ()
1000 "Show all of the diary entries in the diary file.
1001 This function gets rid of the selective display of the diary file so that
1002 all entries, not just some, are visible. If there is no diary buffer, one
1003 is created."
1004 (interactive)
1005 (let ((d-file (diary-check-diary-file))
1006 (pop-up-frames (window-dedicated-p (selected-window))))
1007 (with-current-buffer (or (find-buffer-visiting d-file)
1008 (find-file-noselect d-file t))
1009 (when (eq major-mode default-major-mode) (diary-mode))
1010 (diary-unhide-everything)
1011 (display-buffer (current-buffer)))))
1013 ;;;###autoload
1014 (defun diary-mail-entries (&optional ndays)
1015 "Send a mail message showing diary entries for next NDAYS days.
1016 If no prefix argument is given, NDAYS is set to `diary-mail-days'.
1017 Mail is sent to the address specified by `diary-mail-addr'.
1019 You can call `diary-mail-entries' every night using an at/cron job.
1020 For example, this script will run the program at 2am daily. Since
1021 `emacs -batch' does not load your `.emacs' file, you must ensure that
1022 all relevant variables are set, as done here.
1024 #!/bin/sh
1025 # diary-rem.sh -- repeatedly run the Emacs diary-reminder
1026 emacs -batch \\
1027 -eval \"(setq diary-mail-days 3 \\
1028 diary-file \\\"/path/to/diary.file\\\" \\
1029 european-calendar-style t \\
1030 diary-mail-addr \\\"user@host.name\\\" )\" \\
1031 -l diary-lib -f diary-mail-entries
1032 at -f diary-rem.sh 0200 tomorrow
1034 You may have to tweak the syntax of the `at' command to suit your
1035 system. Alternatively, you can specify a cron entry:
1036 0 1 * * * diary-rem.sh
1037 to run it every morning at 1am."
1038 (interactive "P")
1039 (if (string-equal diary-mail-addr "")
1040 (error "You must set `diary-mail-addr' to use this command")
1041 (let ((diary-display-hook 'fancy-diary-display))
1042 (diary-list-entries (calendar-current-date) (or ndays diary-mail-days)))
1043 (compose-mail diary-mail-addr
1044 (concat "Diary entries generated "
1045 (calendar-date-string (calendar-current-date))))
1046 (insert
1047 (if (get-buffer fancy-diary-buffer)
1048 (with-current-buffer fancy-diary-buffer (buffer-string))
1049 "No entries found"))
1050 (call-interactively (get mail-user-agent 'sendfunc))))
1052 (defun diary-name-pattern (string-array &optional abbrev-array paren)
1053 "Return a regexp matching the strings in the array STRING-ARRAY.
1054 If the optional argument ABBREV-ARRAY is present, then the function
1055 `calendar-abbrev-construct' is used to construct abbreviations from the
1056 two supplied arrays. The returned regexp will then also match these
1057 abbreviations, with or without final `.' characters. If the optional
1058 argument PAREN is non-nil, the regexp is surrounded by parentheses."
1059 (regexp-opt (append string-array
1060 (if abbrev-array
1061 (calendar-abbrev-construct abbrev-array
1062 string-array))
1063 (if abbrev-array
1064 (calendar-abbrev-construct abbrev-array
1065 string-array
1066 'period))
1067 nil)
1068 paren))
1070 (defvar marking-diary-entries nil
1071 "True during the marking of diary entries, nil otherwise.")
1073 (defvar marking-diary-entry nil
1074 "True during the marking of diary entries, if current entry is marking.")
1076 ;;;###cal-autoload
1077 (defun mark-diary-entries (&optional redraw)
1078 "Mark days in the calendar window that have diary entries.
1079 Each entry in the diary file visible in the calendar window is
1080 marked. After the entries are marked, the hooks
1081 `nongregorian-diary-marking-hook' and `mark-diary-entries-hook'
1082 are run. If the optional argument REDRAW is non-nil (which is
1083 the case interactively, for example) then any existing diary
1084 marks are first removed. This is intended to deal with deleted
1085 diary entries."
1086 (interactive "p")
1087 ;; To remove any deleted diary entries. Do not redraw when:
1088 ;; i) processing #include diary files (else only get the marks from
1089 ;; the last #include file processed).
1090 ;; ii) called via calendar-redraw (since calendar has already been
1091 ;; erased).
1092 ;; Use of REDRAW handles both of these cases.
1093 (when (and redraw mark-diary-entries-in-calendar)
1094 (setq mark-diary-entries-in-calendar nil)
1095 (redraw-calendar))
1096 (let ((marking-diary-entries t)
1097 (dayname
1098 (diary-name-pattern calendar-day-name-array
1099 calendar-day-abbrev-array))
1100 (monthname
1101 (format "%s\\|\\*"
1102 (diary-name-pattern calendar-month-name-array
1103 calendar-month-abbrev-array)))
1104 (month "[0-9]+\\|\\*")
1105 (day "[0-9]+\\|\\*")
1106 (year "[0-9]+\\|\\*")
1107 file-glob-attrs marks)
1108 (with-current-buffer (find-file-noselect (diary-check-diary-file) t)
1109 (save-excursion
1110 (when (eq major-mode default-major-mode) (diary-mode))
1111 (setq mark-diary-entries-in-calendar t)
1112 (message "Marking diary entries...")
1113 (setq file-glob-attrs (nth 1 (diary-pull-attrs nil '())))
1114 (with-syntax-table diary-syntax-table
1115 (dolist (date-form diary-date-forms)
1116 (if (eq (car date-form) 'backup)
1117 (setq date-form (cdr date-form))) ; ignore 'backup directive
1118 (let* ((l (length date-form))
1119 (d-name-pos (- l (length (memq 'dayname date-form))))
1120 (d-name-pos (if (/= l d-name-pos) (+ 1 d-name-pos)))
1121 (m-name-pos (- l (length (memq 'monthname date-form))))
1122 (m-name-pos (if (/= l m-name-pos) (+ 1 m-name-pos)))
1123 (d-pos (- l (length (memq 'day date-form))))
1124 (d-pos (if (/= l d-pos) (+ 1 d-pos)))
1125 (m-pos (- l (length (memq 'month date-form))))
1126 (m-pos (if (/= l m-pos) (+ 1 m-pos)))
1127 (y-pos (- l (length (memq 'year date-form))))
1128 (y-pos (if (/= l y-pos) (+ 1 y-pos)))
1129 (regexp
1130 (concat
1131 "^\\("
1132 (mapconcat 'eval date-form "\\)\\(")
1133 "\\)"))
1134 (case-fold-search t))
1135 (goto-char (point-min))
1136 (while (re-search-forward regexp nil t)
1137 (let* ((dd-name
1138 (if d-name-pos
1139 (match-string-no-properties d-name-pos)))
1140 (mm-name
1141 (if m-name-pos
1142 (match-string-no-properties m-name-pos)))
1143 (mm (string-to-number
1144 (if m-pos
1145 (match-string-no-properties m-pos)
1146 "")))
1147 (dd (string-to-number
1148 (if d-pos
1149 (match-string-no-properties d-pos)
1150 "")))
1151 (y-str (if y-pos
1152 (match-string-no-properties y-pos)))
1153 (yy (if (not y-str)
1155 (if (and (= (length y-str) 2)
1156 abbreviated-calendar-year)
1157 (let* ((current-y
1158 (extract-calendar-year
1159 (calendar-current-date)))
1160 (y (+ (string-to-number y-str)
1161 (* 100
1162 (/ current-y 100)))))
1163 (if (> (- y current-y) 50)
1164 (- y 100)
1165 (if (> (- current-y y) 50)
1166 (+ y 100)
1167 y)))
1168 (string-to-number y-str)))))
1169 (setq marks (nth 1
1170 (diary-pull-attrs
1171 (buffer-substring-no-properties
1172 (point) (line-end-position))
1173 file-glob-attrs)))
1174 (if dd-name
1175 (mark-calendar-days-named
1176 (cdr (assoc-string
1177 dd-name
1178 (calendar-make-alist
1179 calendar-day-name-array
1180 0 nil calendar-day-abbrev-array) t)) marks)
1181 (if mm-name
1182 (setq mm
1183 (if (string-equal mm-name "*") 0
1184 (cdr (assoc-string
1185 mm-name
1186 (calendar-make-alist
1187 calendar-month-name-array
1188 1 nil calendar-month-abbrev-array) t)))))
1189 (mark-calendar-date-pattern mm dd yy marks))))))
1190 (mark-sexp-diary-entries)
1191 (run-hooks 'nongregorian-diary-marking-hook
1192 'mark-diary-entries-hook))
1193 (message "Marking diary entries...done")))))
1195 (defvar displayed-year) ; bound in generate-calendar
1196 (defvar displayed-month)
1198 (defun mark-sexp-diary-entries ()
1199 "Mark days in the calendar window that have sexp diary entries.
1200 Each entry in the diary file (or included files) visible in the calendar window
1201 is marked. See the documentation for the function `list-sexp-diary-entries'."
1202 (let* ((sexp-mark (regexp-quote sexp-diary-entry-symbol))
1203 (s-entry (concat "^\\("
1204 sexp-mark "(\\)\\|\\("
1205 (regexp-quote diary-nonmarking-symbol)
1206 sexp-mark "(diary-remind\\)"))
1207 (file-glob-attrs (nth 1 (diary-pull-attrs nil '())))
1208 m y first-date last-date mark file-glob-attrs)
1209 (with-current-buffer calendar-buffer
1210 (setq m displayed-month)
1211 (setq y displayed-year))
1212 (increment-calendar-month m y -1)
1213 (setq first-date
1214 (calendar-absolute-from-gregorian (list m 1 y)))
1215 (increment-calendar-month m y 2)
1216 (setq last-date
1217 (calendar-absolute-from-gregorian
1218 (list m (calendar-last-day-of-month m y) y)))
1219 (goto-char (point-min))
1220 (while (re-search-forward s-entry nil t)
1221 (setq marking-diary-entry (char-equal (preceding-char) ?\())
1222 (re-search-backward "(")
1223 (let ((sexp-start (point))
1224 sexp entry entry-start marks)
1225 (forward-sexp)
1226 (setq sexp (buffer-substring-no-properties sexp-start (point)))
1227 (forward-char 1)
1228 (if (and (bolp) (not (looking-at "[ \t]")))
1229 ;; Diary entry consists only of the sexp.
1230 (progn
1231 (backward-char 1)
1232 (setq entry ""))
1233 (setq entry-start (point))
1234 ;; Find end of entry.
1235 (forward-line 1)
1236 (while (looking-at "[ \t]")
1237 (forward-line 1))
1238 (if (bolp) (backward-char 1))
1239 (setq entry (buffer-substring-no-properties entry-start (point))))
1240 (calendar-for-loop date from first-date to last-date do
1241 (if (setq mark
1242 (diary-sexp-entry sexp entry
1243 (calendar-gregorian-from-absolute date)))
1244 (progn
1245 ;; FIXME what?
1246 (setq marks (diary-pull-attrs
1247 entry file-glob-attrs)
1248 marks (nth 1 (diary-pull-attrs
1249 entry file-glob-attrs)))
1250 (mark-visible-calendar-date
1251 (calendar-gregorian-from-absolute date)
1252 (if (< 0 (length marks))
1253 marks
1254 (if (consp mark)
1255 (car mark)))))))))))
1257 (defun mark-included-diary-files ()
1258 "Mark the diary entries from other diary files with those of the diary file.
1259 This function is suitable for use as the `mark-diary-entries-hook'; it enables
1260 you to use shared diary files together with your own. The files included are
1261 specified in the `diary-file' by lines of this form:
1262 #include \"filename\"
1263 This is recursive; that is, #include directives in diary files thus included
1264 are obeyed. You can change the `#include' to some other string by
1265 changing the variable `diary-include-string'."
1266 (goto-char (point-min))
1267 (while (re-search-forward
1268 (concat
1270 (regexp-quote diary-include-string)
1271 " \"\\([^\"]*\\)\"")
1272 nil t)
1273 (let* ((diary-file (substitute-in-file-name
1274 (match-string-no-properties 1)))
1275 (mark-diary-entries-hook 'mark-included-diary-files)
1276 (dbuff (find-buffer-visiting diary-file)))
1277 (if (file-exists-p diary-file)
1278 (if (file-readable-p diary-file)
1279 (progn
1280 (mark-diary-entries)
1281 (unless dbuff
1282 (kill-buffer (find-buffer-visiting diary-file))))
1283 (beep)
1284 (message "Can't read included diary file %s" diary-file)
1285 (sleep-for 2))
1286 (beep)
1287 (message "Can't find included diary file %s" diary-file)
1288 (sleep-for 2))))
1289 (goto-char (point-min)))
1291 (defun mark-calendar-days-named (dayname &optional color)
1292 "Mark all dates in the calendar window that are day DAYNAME of the week.
1293 0 means all Sundays, 1 means all Mondays, and so on.
1294 Optional argument COLOR is passed to `mark-visible-calendar-date' as MARK."
1295 (with-current-buffer calendar-buffer
1296 (let ((prev-month displayed-month)
1297 (prev-year displayed-year)
1298 (succ-month displayed-month)
1299 (succ-year displayed-year)
1300 (last-day)
1301 (day))
1302 (increment-calendar-month succ-month succ-year 1)
1303 (increment-calendar-month prev-month prev-year -1)
1304 (setq day (calendar-absolute-from-gregorian
1305 (calendar-nth-named-day 1 dayname prev-month prev-year))
1306 last-day (calendar-absolute-from-gregorian
1307 (calendar-nth-named-day -1 dayname succ-month succ-year)))
1308 (while (<= day last-day)
1309 (mark-visible-calendar-date (calendar-gregorian-from-absolute day)
1310 color)
1311 (setq day (+ day 7))))))
1313 (defun mark-calendar-date-pattern (month day year &optional color)
1314 "Mark all dates in the calendar window that conform to MONTH/DAY/YEAR.
1315 A value of 0 in any position is a wildcard.
1316 Optional argument COLOR is passed to `mark-visible-calendar-date' as MARK."
1317 (with-current-buffer calendar-buffer
1318 (let ((m displayed-month)
1319 (y displayed-year))
1320 (increment-calendar-month m y -1)
1321 (dotimes (idummy 3)
1322 (mark-calendar-month m y month day year color)
1323 (increment-calendar-month m y 1)))))
1325 (defun mark-calendar-month (month year p-month p-day p-year &optional color)
1326 "Mark dates in the MONTH/YEAR that conform to pattern P-MONTH/P-DAY/P-YEAR.
1327 A value of 0 in any position of the pattern is a wildcard.
1328 Optional argument COLOR is passed to `mark-visible-calendar-date' as MARK."
1329 (if (or (and (= month p-month)
1330 (or (zerop p-year) (= year p-year)))
1331 (and (zerop p-month)
1332 (or (zerop p-year) (= year p-year))))
1333 (if (zerop p-day)
1334 (calendar-for-loop
1335 i from 1 to (calendar-last-day-of-month month year) do
1336 (mark-visible-calendar-date (list month i year) color))
1337 (mark-visible-calendar-date (list month p-day year) color))))
1339 (defun sort-diary-entries ()
1340 "Sort the list of diary entries by time of day."
1341 (setq diary-entries-list (sort diary-entries-list 'diary-entry-compare)))
1343 (defun diary-entry-compare (e1 e2)
1344 "Return t if E1 is earlier than E2."
1345 (or (calendar-date-compare e1 e2)
1346 (and (calendar-date-equal (car e1) (car e2))
1347 (let* ((ts1 (cadr e1)) (t1 (diary-entry-time ts1))
1348 (ts2 (cadr e2)) (t2 (diary-entry-time ts2)))
1349 (or (< t1 t2)
1350 (and (= t1 t2)
1351 (string-lessp ts1 ts2)))))))
1353 (defun diary-entry-time (s)
1354 "Return time at the beginning of the string S as a military-style integer.
1355 For example, returns 1325 for 1:25pm.
1357 Returns `diary-unknown-time' (default value -9999) if no time is recognized.
1358 The recognized forms are XXXX, X:XX, or XX:XX (military time), and XXam,
1359 XXAM, XXpm, XXPM, XX:XXam, XX:XXAM XX:XXpm, or XX:XXPM. A period (.) can
1360 be used instead of a colon (:) to separate the hour and minute parts."
1361 (let ((case-fold-search nil))
1362 (cond ((string-match ; military time
1363 "\\`[ \t\n]*\\([0-9]?[0-9]\\)[:.]?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)"
1365 (+ (* 100 (string-to-number (match-string 1 s)))
1366 (string-to-number (match-string 2 s))))
1367 ((string-match ; hour only (XXam or XXpm)
1368 "\\`[ \t\n]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s)
1369 (+ (* 100 (% (string-to-number (match-string 1 s)) 12))
1370 (if (equal ?a (downcase (aref s (match-beginning 2))))
1371 0 1200)))
1372 ((string-match ; hour and minute (XX:XXam or XX:XXpm)
1373 "\\`[ \t\n]*\\([0-9]?[0-9]\\)[:.]\\([0-9][0-9]\\)\\([ap]\\)m\\>" s)
1374 (+ (* 100 (% (string-to-number (match-string 1 s)) 12))
1375 (string-to-number (match-string 2 s))
1376 (if (equal ?a (downcase (aref s (match-beginning 3))))
1377 0 1200)))
1378 (t diary-unknown-time)))) ; unrecognizable
1380 (defun list-sexp-diary-entries (date)
1381 "Add sexp entries for DATE from the diary file to `diary-entries-list'.
1382 Also, make them visible in the diary file. Returns t if any entries were
1383 found.
1385 Sexp diary entries must be prefaced by a `sexp-diary-entry-symbol' (normally
1386 `%%'). The form of a sexp diary entry is
1388 %%(SEXP) ENTRY
1390 Both ENTRY and DATE are globally available when the SEXP is evaluated. If the
1391 SEXP yields the value nil, the diary entry does not apply. If it yields a
1392 non-nil value, ENTRY will be taken to apply to DATE; if the non-nil value is a
1393 string, that string will be the diary entry in the fancy diary display.
1395 For example, the following diary entry will apply to the 21st of the month
1396 if it is a weekday and the Friday before if the 21st is on a weekend:
1398 &%%(let ((dayname (calendar-day-of-week date))
1399 (day (extract-calendar-day date)))
1401 (and (= day 21) (memq dayname '(1 2 3 4 5)))
1402 (and (memq day '(19 20)) (= dayname 5)))
1403 ) UIUC pay checks deposited
1405 A number of built-in functions are available for this type of diary entry:
1407 %%(diary-date MONTH DAY YEAR &optional MARK) text
1408 Entry applies if date is MONTH, DAY, YEAR if
1409 `european-calendar-style' is nil, and DAY, MONTH, YEAR if
1410 `european-calendar-style' is t. DAY, MONTH, and YEAR
1411 can be lists of integers, the constant t, or an integer.
1412 The constant t means all values. An optional parameter
1413 MARK specifies a face or single-character string to use
1414 when highlighting the day in the calendar.
1416 %%(diary-float MONTH DAYNAME N &optional DAY MARK) text
1417 Entry will appear on the Nth DAYNAME of MONTH.
1418 (DAYNAME=0 means Sunday, 1 means Monday, and so on;
1419 if N is negative it counts backward from the end of
1420 the month. MONTH can be a list of months, a single
1421 month, or t to specify all months. Optional DAY means
1422 Nth DAYNAME of MONTH on or after/before DAY. DAY defaults
1423 to 1 if N>0 and the last day of the month if N<0. An
1424 optional parameter MARK specifies a face or single-character
1425 string to use when highlighting the day in the calendar.
1427 %%(diary-block M1 D1 Y1 M2 D2 Y2 &optional MARK) text
1428 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2,
1429 inclusive. (If `european-calendar-style' is t, the
1430 order of the parameters should be changed to D1, M1, Y1,
1431 D2, M2, Y2.) An optional parameter MARK specifies a face
1432 or single-character string to use when highlighting the
1433 day in the calendar.
1435 %%(diary-anniversary MONTH DAY YEAR &optional MARK) text
1436 Entry will appear on anniversary dates of MONTH DAY, YEAR.
1437 (If `european-calendar-style' is t, the order of the
1438 parameters should be changed to DAY, MONTH, YEAR.) Text
1439 can contain %d or %d%s; %d will be replaced by the number
1440 of years since the MONTH DAY, YEAR and %s will be replaced
1441 by the ordinal ending of that number (that is, `st', `nd',
1442 `rd' or `th', as appropriate. The anniversary of February
1443 29 is considered to be March 1 in a non-leap year. An
1444 optional parameter MARK specifies a face or single-character
1445 string to use when highlighting the day in the calendar.
1447 %%(diary-cyclic N MONTH DAY YEAR &optional MARK) text
1448 Entry will appear every N days, starting MONTH DAY, YEAR.
1449 (If `european-calendar-style' is t, the order of the
1450 parameters should be changed to N, DAY, MONTH, YEAR.) Text
1451 can contain %d or %d%s; %d will be replaced by the number
1452 of repetitions since the MONTH DAY, YEAR and %s will
1453 be replaced by the ordinal ending of that number (that is,
1454 `st', `nd', `rd' or `th', as appropriate. An optional
1455 parameter MARK specifies a face or single-character string
1456 to use when highlighting the day in the calendar.
1458 %%(diary-remind SEXP DAYS &optional MARKING) text
1459 Entry is a reminder for diary sexp SEXP. DAYS is either a
1460 single number or a list of numbers indicating the number(s)
1461 of days before the event that the warning(s) should occur.
1462 If the current date is (one of) DAYS before the event
1463 indicated by EXPR, then a suitable message (as specified
1464 by `diary-remind-message') appears. In addition to the
1465 reminders beforehand, the diary entry also appears on
1466 the date itself. If optional MARKING is non-nil then the
1467 *reminders* are marked on the calendar. Marking of
1468 reminders is independent of whether the entry *itself* is
1469 a marking or nonmarking one.
1471 %%(diary-day-of-year)
1472 Diary entries giving the day of the year and the number of
1473 days remaining in the year will be made every day. Note
1474 that since there is no text, it makes sense only if the
1475 fancy diary display is used.
1477 %%(diary-iso-date)
1478 Diary entries giving the corresponding ISO commercial date
1479 will be made every day. Note that since there is no text,
1480 it makes sense only if the fancy diary display is used.
1482 %%(diary-french-date)
1483 Diary entries giving the corresponding French Revolutionary
1484 date will be made every day. Note that since there is no
1485 text, it makes sense only if the fancy diary display is used.
1487 %%(diary-islamic-date)
1488 Diary entries giving the corresponding Islamic date will be
1489 made every day. Note that since there is no text, it
1490 makes sense only if the fancy diary display is used.
1492 %%(diary-hebrew-date)
1493 Diary entries giving the corresponding Hebrew date will be
1494 made every day. Note that since there is no text, it
1495 makes sense only if the fancy diary display is used.
1497 %%(diary-astro-day-number) Diary entries giving the corresponding
1498 astronomical (Julian) day number will be made every day.
1499 Note that since there is no text, it makes sense only if the
1500 fancy diary display is used.
1502 %%(diary-julian-date) Diary entries giving the corresponding
1503 Julian date will be made every day. Note that since
1504 there is no text, it makes sense only if the fancy diary
1505 display is used.
1507 %%(diary-sunrise-sunset)
1508 Diary entries giving the local times of sunrise and sunset
1509 will be made every day. Note that since there is no text,
1510 it makes sense only if the fancy diary display is used.
1511 Floating point required.
1513 %%(diary-phases-of-moon)
1514 Diary entries giving the times of the phases of the moon
1515 will be when appropriate. Note that since there is no text,
1516 it makes sense only if the fancy diary display is used.
1517 Floating point required.
1519 %%(diary-yahrzeit MONTH DAY YEAR) text
1520 Text is assumed to be the name of the person; the date is
1521 the date of death on the *civil* calendar. The diary entry
1522 will appear on the proper Hebrew-date anniversary and on the
1523 day before. (If `european-calendar-style' is t, the order
1524 of the parameters should be changed to DAY, MONTH, YEAR.)
1526 %%(diary-rosh-hodesh)
1527 Diary entries will be made on the dates of Rosh Hodesh on
1528 the Hebrew calendar. Note that since there is no text, it
1529 makes sense only if the fancy diary display is used.
1531 %%(diary-parasha)
1532 Diary entries giving the weekly parasha will be made on
1533 every Saturday. Note that since there is no text, it
1534 makes sense only if the fancy diary display is used.
1536 %%(diary-omer)
1537 Diary entries giving the omer count will be made every day
1538 from Passover to Shavuot. Note that since there is no text,
1539 it makes sense only if the fancy diary display is used.
1541 Marking these entries is *extremely* time consuming, so these entries are
1542 best if they are nonmarking."
1543 (let ((s-entry (concat "^"
1544 (regexp-quote diary-nonmarking-symbol)
1546 (regexp-quote sexp-diary-entry-symbol)
1547 "("))
1548 entry-found file-glob-attrs marks)
1549 (goto-char (point-min))
1550 (save-excursion
1551 (setq file-glob-attrs (nth 1 (diary-pull-attrs nil '()))))
1552 (while (re-search-forward s-entry nil t)
1553 (backward-char 1)
1554 (let ((sexp-start (point))
1555 sexp entry specifier entry-start line-start)
1556 (forward-sexp)
1557 (setq sexp (buffer-substring-no-properties sexp-start (point)))
1558 (setq line-start (line-end-position 0))
1559 (setq specifier
1560 (buffer-substring-no-properties (1+ line-start) (point))
1561 entry-start (1+ line-start))
1562 (forward-char 1)
1563 (if (and (bolp) (not (looking-at "[ \t]")))
1564 ;; Diary entry consists only of the sexp.
1565 (progn
1566 (backward-char 1)
1567 (setq entry ""))
1568 (setq entry-start (point))
1569 (forward-line 1)
1570 (while (looking-at "[ \t]")
1571 (forward-line 1))
1572 (backward-char 1)
1573 (setq entry (buffer-substring-no-properties entry-start (point))))
1574 (let ((diary-entry (diary-sexp-entry sexp entry date))
1575 temp literal)
1576 (setq literal entry ; before evaluation
1577 entry (if (consp diary-entry)
1578 (cdr diary-entry)
1579 diary-entry))
1580 (if diary-entry
1581 (progn
1582 (remove-overlays line-start (point) 'invisible 'diary)
1583 (if (< 0 (length entry))
1584 (setq temp (diary-pull-attrs entry file-glob-attrs)
1585 entry (nth 0 temp)
1586 marks (nth 1 temp)))))
1587 (add-to-diary-list date
1588 entry
1589 specifier
1590 (if entry-start (copy-marker entry-start)
1591 nil)
1592 marks
1593 literal)
1594 (setq entry-found (or entry-found diary-entry)))))
1595 entry-found))
1597 (defun diary-sexp-entry (sexp entry date)
1598 "Process a SEXP diary ENTRY for DATE."
1599 (let ((result (if calendar-debug-sexp
1600 (let ((stack-trace-on-error t))
1601 (eval (car (read-from-string sexp))))
1602 (condition-case nil
1603 (eval (car (read-from-string sexp)))
1604 (error
1605 (beep)
1606 (message "Bad sexp at line %d in %s: %s"
1607 (count-lines (point-min) (point))
1608 diary-file sexp)
1609 (sleep-for 2))))))
1610 (cond ((stringp result) result)
1611 ((and (consp result)
1612 (stringp (cdr result))) result)
1613 (result entry)
1614 (t nil))))
1616 (defvar date)
1617 (defvar entry)
1619 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
1620 (defun diary-date (month day year &optional mark)
1621 "Specific date(s) diary entry.
1622 Entry applies if date is MONTH, DAY, YEAR if `european-calendar-style' is nil,
1623 and DAY, MONTH, YEAR if `european-calendar-style' is t. DAY, MONTH, and YEAR
1624 can be lists of integers, the constant t, or an integer. The constant t means
1625 all values.
1627 An optional parameter MARK specifies a face or single-character string to
1628 use when highlighting the day in the calendar."
1629 (let ((dd (if european-calendar-style
1630 month
1631 day))
1632 (mm (if european-calendar-style
1634 month))
1635 (m (extract-calendar-month date))
1636 (y (extract-calendar-year date))
1637 (d (extract-calendar-day date)))
1638 (if (and
1639 (or (and (listp dd) (memq d dd))
1640 (equal d dd)
1641 (eq dd t))
1642 (or (and (listp mm) (memq m mm))
1643 (equal m mm)
1644 (eq mm t))
1645 (or (and (listp year) (memq y year))
1646 (equal y year)
1647 (eq year t)))
1648 (cons mark entry))))
1650 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
1651 (defun diary-block (m1 d1 y1 m2 d2 y2 &optional mark)
1652 "Block diary entry.
1653 Entry applies if date is between, or on one of, two dates.
1654 The order of the parameters is
1655 M1, D1, Y1, M2, D2, Y2 if `european-calendar-style' is nil, and
1656 D1, M1, Y1, D2, M2, Y2 if `european-calendar-style' is t.
1658 An optional parameter MARK specifies a face or single-character string to
1659 use when highlighting the day in the calendar."
1661 (let ((date1 (calendar-absolute-from-gregorian
1662 (if european-calendar-style
1663 (list d1 m1 y1)
1664 (list m1 d1 y1))))
1665 (date2 (calendar-absolute-from-gregorian
1666 (if european-calendar-style
1667 (list d2 m2 y2)
1668 (list m2 d2 y2))))
1669 (d (calendar-absolute-from-gregorian date)))
1670 (if (and (<= date1 d) (<= d date2))
1671 (cons mark entry))))
1673 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
1674 (defun diary-float (month dayname n &optional day mark)
1675 "Floating diary entry--entry applies if date is the nth dayname of month.
1676 Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant
1677 t, or an integer. The constant t means all months. If N is negative, count
1678 backward from the end of the month.
1680 An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY.
1681 Optional MARK specifies a face or single-character string to use when
1682 highlighting the day in the calendar."
1683 ;; This is messy because the diary entry may apply, but the date on which it
1684 ;; is based can be in a different month/year. For example, asking for the
1685 ;; first Monday after December 30. For large values of |n| the problem is
1686 ;; more grotesque.
1687 (and (= dayname (calendar-day-of-week date))
1688 (let* ((m (extract-calendar-month date))
1689 (d (extract-calendar-day date))
1690 (y (extract-calendar-year date))
1691 ;; Last (n>0) or first (n<0) possible base date for entry.
1692 (limit
1693 (calendar-nth-named-absday (- n) dayname m y d))
1694 (last-abs (if (> n 0) limit (+ limit 6)))
1695 (first-abs (if (> n 0) (- limit 6) limit))
1696 (last (calendar-gregorian-from-absolute last-abs))
1697 (first (calendar-gregorian-from-absolute first-abs))
1698 ;; m1, d1 is first possible base date.
1699 (m1 (extract-calendar-month first))
1700 (d1 (extract-calendar-day first))
1701 (y1 (extract-calendar-year first))
1702 ;; m2, d2 is last possible base date.
1703 (m2 (extract-calendar-month last))
1704 (d2 (extract-calendar-day last))
1705 (y2 (extract-calendar-year last)))
1706 (if (or (and (= m1 m2) ; only possible base dates in one month
1707 (or (eq month t)
1708 (if (listp month)
1709 (memq m1 month)
1710 (= m1 month)))
1711 (let ((d (or day (if (> n 0)
1713 (calendar-last-day-of-month m1 y1)))))
1714 (and (<= d1 d) (<= d d2))))
1715 ;; Only possible base dates straddle two months.
1716 (and (or (< y1 y2)
1717 (and (= y1 y2) (< m1 m2)))
1719 ;; m1, d1 works as a base date.
1720 (and
1721 (or (eq month t)
1722 (if (listp month)
1723 (memq m1 month)
1724 (= m1 month)))
1725 (<= d1 (or day (if (> n 0)
1727 (calendar-last-day-of-month m1 y1)))))
1728 ;; m2, d2 works as a base date.
1729 (and (or (eq month t)
1730 (if (listp month)
1731 (memq m2 month)
1732 (= m2 month)))
1733 (<= (or day (if (> n 0)
1735 (calendar-last-day-of-month m2 y2)))
1736 d2)))))
1737 (cons mark entry)))))
1739 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
1740 (defun diary-anniversary (month day &optional year mark)
1741 "Anniversary diary entry.
1742 Entry applies if date is the anniversary of MONTH, DAY, YEAR if
1743 `european-calendar-style' is nil, and DAY, MONTH, YEAR if
1744 `european-calendar-style' is t. Diary entry can contain `%d' or `%d%s'; the
1745 %d will be replaced by the number of years since the MONTH DAY, YEAR and the
1746 %s will be replaced by the ordinal ending of that number (that is, `st', `nd',
1747 `rd' or `th', as appropriate. The anniversary of February 29 is considered
1748 to be March 1 in non-leap years.
1750 An optional parameter MARK specifies a face or single-character string to
1751 use when highlighting the day in the calendar."
1752 (let* ((d (if european-calendar-style
1753 month
1754 day))
1755 (m (if european-calendar-style
1757 month))
1758 (y (extract-calendar-year date))
1759 (diff (if year (- y year) 100)))
1760 (if (and (= m 2) (= d 29) (not (calendar-leap-year-p y)))
1761 (setq m 3
1762 d 1))
1763 (if (and (> diff 0) (calendar-date-equal (list m d y) date))
1764 (cons mark (format entry diff (diary-ordinal-suffix diff))))))
1766 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
1767 (defun diary-cyclic (n month day year &optional mark)
1768 "Cycle diary entry--entry applies every N days starting at MONTH, DAY, YEAR.
1769 If `european-calendar-style' is t, parameters are N, DAY, MONTH, YEAR.
1770 ENTRY can contain `%d' or `%d%s'; the %d will be replaced by the number of
1771 repetitions since the MONTH DAY, YEAR and %s will be replaced by the
1772 ordinal ending of that number (that is, `st', `nd', `rd' or `th', as
1773 appropriate.
1775 An optional parameter MARK specifies a face or single-character string to
1776 use when highlighting the day in the calendar."
1777 (let* ((d (if european-calendar-style
1778 month
1779 day))
1780 (m (if european-calendar-style
1782 month))
1783 (diff (- (calendar-absolute-from-gregorian date)
1784 (calendar-absolute-from-gregorian
1785 (list m d year))))
1786 (cycle (/ diff n)))
1787 (if (and (>= diff 0) (zerop (% diff n)))
1788 (cons mark (format entry cycle (diary-ordinal-suffix cycle))))))
1790 (defun diary-ordinal-suffix (n)
1791 "Ordinal suffix for N. (That is, `st', `nd', `rd', or `th', as appropriate.)"
1792 (if (or (memq (% n 100) '(11 12 13))
1793 (< 3 (% n 10)))
1794 "th"
1795 (aref ["th" "st" "nd" "rd"] (% n 10))))
1797 (defun diary-day-of-year ()
1798 "Day of year and number of days remaining in the year of date diary entry."
1799 (calendar-day-of-year-string date))
1801 (defun diary-remind (sexp days &optional marking)
1802 "Provide a reminder of a diary entry.
1803 SEXP is a diary-sexp. DAYS is either a single number or a list of numbers
1804 indicating the number(s) of days before the event that the warning(s) should
1805 occur on. If the current date is (one of) DAYS before the event indicated by
1806 SEXP, then a suitable message (as specified by `diary-remind-message' is
1807 returned.
1809 In addition to the reminders beforehand, the diary entry also appears on the
1810 date itself.
1812 A `diary-nonmarking-symbol' at the beginning of the line of the `diary-remind'
1813 entry specifies that the diary entry (not the reminder) is non-marking.
1814 Marking of reminders is independent of whether the entry itself is a marking
1815 or nonmarking; if optional parameter MARKING is non-nil then the reminders are
1816 marked on the calendar."
1817 (let ((diary-entry (eval sexp)))
1818 (cond
1819 ;; Diary entry applies on date.
1820 ((and diary-entry
1821 (or (not marking-diary-entries) marking-diary-entry))
1822 diary-entry)
1823 ;; Diary entry may apply to `days' before date.
1824 ((and (integerp days)
1825 (not diary-entry) ; diary entry does not apply to date
1826 (or (not marking-diary-entries) marking))
1827 (let ((date (calendar-gregorian-from-absolute
1828 (+ (calendar-absolute-from-gregorian date) days))))
1829 (when (setq diary-entry (eval sexp)) ; re-evaluate with adjusted date
1830 ;; Discard any mark portion from diary-anniversary, etc.
1831 (if (consp diary-entry) (setq diary-entry (cdr diary-entry)))
1832 (mapconcat 'eval diary-remind-message ""))))
1833 ;; Diary entry may apply to one of a list of days before date.
1834 ((and (listp days) days)
1835 (or (diary-remind sexp (car days) marking)
1836 (diary-remind sexp (cdr days) marking))))))
1838 (defun diary-redraw-calendar ()
1839 "If `calendar-buffer' is live and diary entries are marked, redraw it."
1840 (and mark-diary-entries-in-calendar
1841 (save-excursion
1842 (redraw-calendar)))
1843 ;; Return value suitable for `write-contents-functions'.
1844 nil)
1846 ;;;###cal-autoload
1847 (defun make-diary-entry (string &optional nonmarking file)
1848 "Insert a diary entry STRING which may be NONMARKING in FILE.
1849 If omitted, NONMARKING defaults to nil and FILE defaults to
1850 `diary-file'."
1851 (let ((pop-up-frames (window-dedicated-p (selected-window))))
1852 (find-file-other-window (substitute-in-file-name (or file diary-file))))
1853 (when (eq major-mode default-major-mode) (diary-mode))
1854 (widen)
1855 (diary-unhide-everything)
1856 (goto-char (point-max))
1857 (when (let ((case-fold-search t))
1858 (search-backward "Local Variables:"
1859 (max (- (point-max) 3000) (point-min))
1861 (beginning-of-line)
1862 (insert "\n")
1863 (forward-line -1))
1864 (insert
1865 (if (bolp) "" "\n")
1866 (if nonmarking diary-nonmarking-symbol "")
1867 string " "))
1869 ;;;###cal-autoload
1870 (defun insert-diary-entry (arg)
1871 "Insert a diary entry for the date indicated by point.
1872 Prefix argument ARG makes the entry nonmarking."
1873 (interactive "P")
1874 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t t)
1875 arg))
1877 ;;;###cal-autoload
1878 (defun insert-weekly-diary-entry (arg)
1879 "Insert a weekly diary entry for the day of the week indicated by point.
1880 Prefix argument ARG makes the entry nonmarking."
1881 (interactive "P")
1882 (make-diary-entry (calendar-day-name (calendar-cursor-to-date t))
1883 arg))
1885 ;;;###cal-autoload
1886 (defun insert-monthly-diary-entry (arg)
1887 "Insert a monthly diary entry for the day of the month indicated by point.
1888 Prefix argument ARG makes the entry nonmarking."
1889 (interactive "P")
1890 (let ((calendar-date-display-form
1891 (if european-calendar-style
1892 '(day " * ")
1893 '("* " day))))
1894 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t)
1895 arg)))
1897 ;;;###cal-autoload
1898 (defun insert-yearly-diary-entry (arg)
1899 "Insert an annual diary entry for the day of the year indicated by point.
1900 Prefix argument ARG makes the entry nonmarking."
1901 (interactive "P")
1902 (let ((calendar-date-display-form
1903 (if european-calendar-style
1904 '(day " " monthname)
1905 '(monthname " " day))))
1906 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t)
1907 arg)))
1909 ;;;###cal-autoload
1910 (defun insert-anniversary-diary-entry (arg)
1911 "Insert an anniversary diary entry for the date given by point.
1912 Prefix argument ARG makes the entry nonmarking."
1913 (interactive "P")
1914 (let ((calendar-date-display-form
1915 (if european-calendar-style
1916 '(day " " month " " year)
1917 '(month " " day " " year))))
1918 (make-diary-entry
1919 (format "%s(diary-anniversary %s)"
1920 sexp-diary-entry-symbol
1921 (calendar-date-string (calendar-cursor-to-date t) nil t))
1922 arg)))
1924 ;;;###cal-autoload
1925 (defun insert-block-diary-entry (arg)
1926 "Insert a block diary entry for the days between the point and marked date.
1927 Prefix argument ARG makes the entry nonmarking."
1928 (interactive "P")
1929 (let ((calendar-date-display-form
1930 (if european-calendar-style
1931 '(day " " month " " year)
1932 '(month " " day " " year)))
1933 (cursor (calendar-cursor-to-date t))
1934 (mark (or (car calendar-mark-ring)
1935 (error "No mark set in this buffer")))
1936 start end)
1937 (if (< (calendar-absolute-from-gregorian mark)
1938 (calendar-absolute-from-gregorian cursor))
1939 (setq start mark
1940 end cursor)
1941 (setq start cursor
1942 end mark))
1943 (make-diary-entry
1944 (format "%s(diary-block %s %s)"
1945 sexp-diary-entry-symbol
1946 (calendar-date-string start nil t)
1947 (calendar-date-string end nil t))
1948 arg)))
1950 ;;;###cal-autoload
1951 (defun insert-cyclic-diary-entry (arg)
1952 "Insert a cyclic diary entry starting at the date given by point.
1953 Prefix argument ARG makes the entry nonmarking."
1954 (interactive "P")
1955 (let ((calendar-date-display-form
1956 (if european-calendar-style
1957 '(day " " month " " year)
1958 '(month " " day " " year))))
1959 (make-diary-entry
1960 (format "%s(diary-cyclic %d %s)"
1961 sexp-diary-entry-symbol
1962 (calendar-read "Repeat every how many days: "
1963 (lambda (x) (> x 0)))
1964 (calendar-date-string (calendar-cursor-to-date t) nil t))
1965 arg)))
1967 (defvar diary-mode-map
1968 (let ((map (make-sparse-keymap)))
1969 (define-key map "\C-c\C-s" 'diary-show-all-entries)
1970 (define-key map "\C-c\C-q" 'quit-window)
1971 map)
1972 "Keymap for `diary-mode'.")
1974 ;;;###autoload
1975 (define-derived-mode diary-mode fundamental-mode "Diary"
1976 "Major mode for editing the diary file."
1977 (set (make-local-variable 'font-lock-defaults)
1978 '(diary-font-lock-keywords t))
1979 (add-to-invisibility-spec '(diary . nil))
1980 (add-hook 'after-save-hook 'diary-redraw-calendar nil t)
1981 (if diary-header-line-flag
1982 (setq header-line-format diary-header-line-format)))
1985 (defvar diary-fancy-date-pattern
1986 (concat
1987 (let ((dayname (diary-name-pattern calendar-day-name-array nil t))
1988 (monthname (diary-name-pattern calendar-month-name-array nil t))
1989 (day "[0-9]+")
1990 (month "[0-9]+")
1991 (year "-?[0-9]+"))
1992 (mapconcat 'eval calendar-date-display-form ""))
1993 ;; Optional ": holiday name" after the date.
1994 "\\(: .*\\)?")
1995 "Regular expression matching a date header in Fancy Diary.")
1997 (defconst diary-time-regexp
1998 ;; Accepted formats: 10:00 10.00 10h00 10h 10am 10:00am 10.00am
1999 ;; Use of "." as a separator annoyingly matches numbers, eg "123.45".
2000 ;; Hence often prefix this with "\\(^\\|\\s-\\)."
2001 (concat "[0-9]?[0-9]\\([AaPp][mM]\\|\\("
2002 "[Hh]\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]"
2003 "\\)\\([AaPp][Mm]\\)?\\)")
2004 "Regular expression matching a time of day.")
2006 (defface diary-anniversary '((t :inherit font-lock-keyword-face))
2007 "Face used for anniversaries in the diary."
2008 :version "22.1"
2009 :group 'diary)
2011 (defface diary-time '((t :inherit font-lock-variable-name-face))
2012 "Face used for times of day in the diary."
2013 :version "22.1"
2014 :group 'diary)
2016 (defvar fancy-diary-font-lock-keywords
2017 (list
2018 (list
2019 ;; Any number of " other holiday name" lines, followed by "==" line.
2020 (concat diary-fancy-date-pattern "\\(\n +.*\\)*\n=+$")
2021 '(0 (progn (put-text-property (match-beginning 0) (match-end 0)
2022 'font-lock-multiline t)
2023 diary-face)))
2024 '("^.*\\([aA]nniversary\\|[bB]irthday\\).*$" . 'diary-anniversary)
2025 '("^.*Yahrzeit.*$" . font-lock-reference-face)
2026 '("^\\(Erev \\)?Rosh Hodesh.*" . font-lock-function-name-face)
2027 '("^Day.*omer.*$" . font-lock-builtin-face)
2028 '("^Parashat.*$" . font-lock-comment-face)
2029 `(,(format "\\(^\\|\\s-\\)%s\\(-%s\\)?" diary-time-regexp
2030 diary-time-regexp) . 'diary-time))
2031 "Keywords to highlight in fancy diary display.")
2033 ;; If region looks like it might start or end in the middle of a
2034 ;; multiline pattern, extend the region to encompass the whole pattern.
2035 (defun diary-fancy-font-lock-fontify-region-function (beg end &optional verbose)
2036 "Function to use for `font-lock-fontify-region-function' in Fancy Diary.
2037 Needed to handle multiline keyword in `fancy-diary-font-lock-keywords'."
2038 (goto-char beg)
2039 (forward-line 0)
2040 (if (looking-at "=+$") (forward-line -1))
2041 (while (and (looking-at " +[^ ]")
2042 (zerop (forward-line -1))))
2043 ;; This check not essential.
2044 (if (looking-at diary-fancy-date-pattern)
2045 (setq beg (line-beginning-position)))
2046 (goto-char end)
2047 (forward-line 0)
2048 (while (and (looking-at " +[^ ]")
2049 (zerop (forward-line 1))))
2050 (if (looking-at "=+$")
2051 (setq end (line-beginning-position 2)))
2052 (font-lock-default-fontify-region beg end verbose))
2054 (define-derived-mode fancy-diary-display-mode fundamental-mode
2055 "Diary"
2056 "Major mode used while displaying diary entries using Fancy Display."
2057 (set (make-local-variable 'font-lock-defaults)
2058 '(fancy-diary-font-lock-keywords
2059 t nil nil nil
2060 (font-lock-fontify-region-function
2061 . diary-fancy-font-lock-fontify-region-function)))
2062 (local-set-key "q" 'quit-window))
2065 (defun diary-font-lock-sexps (limit)
2066 "Recognize sexp diary entry up to LIMIT for font-locking."
2067 (if (re-search-forward
2068 (concat "^" (regexp-quote diary-nonmarking-symbol)
2069 "?\\(" (regexp-quote sexp-diary-entry-symbol) "\\)")
2070 limit t)
2071 (condition-case nil
2072 (save-restriction
2073 (narrow-to-region (point-min) limit)
2074 (let ((start (point)))
2075 (forward-sexp 1)
2076 (store-match-data (list start (point)))
2078 (error t))))
2080 (defun diary-font-lock-date-forms (month-array &optional symbol abbrev-array)
2081 "Create font-lock patterns for `diary-date-forms' using MONTH-ARRAY.
2082 If given, optional SYMBOL must be a prefix to entries.
2083 If optional ABBREV-ARRAY is present, the abbreviations constructed
2084 from this array by the function `calendar-abbrev-construct' are
2085 matched (with or without a final `.'), in addition to the full month
2086 names."
2087 (let ((dayname (diary-name-pattern calendar-day-name-array
2088 calendar-day-abbrev-array t))
2089 (monthname (format "\\(%s\\|\\*\\)"
2090 (diary-name-pattern month-array abbrev-array)))
2091 (month "\\([0-9]+\\|\\*\\)")
2092 (day "\\([0-9]+\\|\\*\\)")
2093 (year "-?\\([0-9]+\\|\\*\\)"))
2094 (mapcar (lambda (x)
2095 (cons
2096 (concat "^" (regexp-quote diary-nonmarking-symbol) "?"
2097 (if symbol (regexp-quote symbol) "") "\\("
2098 (mapconcat 'eval
2099 ;; If backup, omit first item (backup)
2100 ;; and last item (not part of date).
2101 (if (equal (car x) 'backup)
2102 (nreverse (cdr (reverse (cdr x))))
2105 ;; With backup, last item is not part of date.
2106 (if (equal (car x) 'backup)
2107 (concat "\\)" (eval (car (reverse x))))
2108 "\\)"))
2109 '(1 diary-face)))
2110 diary-date-forms)))
2112 (defvar calendar-hebrew-month-name-array-leap-year)
2113 (defvar calendar-islamic-month-name-array)
2114 (defvar calendar-bahai-month-name-array)
2116 ;;;###cal-autoload
2117 (defun diary-font-lock-keywords ()
2118 "Return a value for the variable `diary-font-lock-keywords'."
2119 (append
2120 (diary-font-lock-date-forms calendar-month-name-array
2121 nil calendar-month-abbrev-array)
2122 (when (or (memq 'mark-hebrew-diary-entries
2123 nongregorian-diary-marking-hook)
2124 (memq 'list-hebrew-diary-entries
2125 nongregorian-diary-listing-hook))
2126 (require 'cal-hebrew)
2127 (diary-font-lock-date-forms
2128 calendar-hebrew-month-name-array-leap-year hebrew-diary-entry-symbol))
2129 (when (or (memq 'mark-islamic-diary-entries
2130 nongregorian-diary-marking-hook)
2131 (memq 'list-islamic-diary-entries
2132 nongregorian-diary-listing-hook))
2133 (require 'cal-islam)
2134 (diary-font-lock-date-forms
2135 calendar-islamic-month-name-array islamic-diary-entry-symbol))
2136 (when (or (memq 'diary-bahai-mark-entries
2137 nongregorian-diary-marking-hook)
2138 (memq 'diary-bahai-list-entries
2139 nongregorian-diary-marking-hook))
2140 (require 'cal-bahai)
2141 (diary-font-lock-date-forms
2142 calendar-bahai-month-name-array bahai-diary-entry-symbol))
2143 (list
2144 (cons
2145 (format "^%s.*$" (regexp-quote diary-include-string))
2146 'font-lock-keyword-face)
2147 (cons
2148 (format "^%s?\\(%s\\)" (regexp-quote diary-nonmarking-symbol)
2149 (regexp-quote sexp-diary-entry-symbol))
2150 '(1 font-lock-reference-face))
2151 (cons
2152 (format "^%s" (regexp-quote diary-nonmarking-symbol))
2153 'font-lock-reference-face)
2154 (cons
2155 (format "^%s?%s" (regexp-quote diary-nonmarking-symbol)
2156 (regexp-opt (mapcar 'regexp-quote
2157 (list hebrew-diary-entry-symbol
2158 islamic-diary-entry-symbol
2159 bahai-diary-entry-symbol))
2161 '(1 font-lock-reference-face))
2162 '(diary-font-lock-sexps . font-lock-keyword-face)
2163 `(,(format "\\(^\\|\\s-\\)%s\\(-%s\\)?" diary-time-regexp
2164 diary-time-regexp)
2165 . 'diary-time))))
2167 (defvar diary-font-lock-keywords (diary-font-lock-keywords)
2168 "Forms to highlight in `diary-mode'.")
2170 ;; Following code from Dave Love <fx@gnu.org>.
2171 ;; Import Outlook-format appointments from mail messages in Gnus or
2172 ;; Rmail using command `diary-from-outlook'. This, or the specialized
2173 ;; functions `diary-from-outlook-gnus' and `diary-from-outlook-rmail',
2174 ;; could be run from hooks to notice appointments automatically (in
2175 ;; which case they will prompt about adding to the diary). The
2176 ;; message formats recognized are customizable through
2177 ;; `diary-outlook-formats'.
2179 ;; Dynamically bound.
2180 (defvar subject)
2182 (defun diary-from-outlook-internal (&optional test-only)
2183 "Snarf a diary entry from a message assumed to be from MS Outlook.
2184 Assumes `body' is bound to a string comprising the body of the message and
2185 `subject' is bound to a string comprising its subject.
2186 Arg TEST-ONLY non-nil means return non-nil if and only if the
2187 message contains an appointment, don't make a diary entry."
2188 (catch 'finished
2189 (let (format-string)
2190 (dotimes (i (length diary-outlook-formats))
2191 (when (eq 0 (string-match (car (nth i diary-outlook-formats))
2192 body))
2193 (unless test-only
2194 (setq format-string (cdr (nth i diary-outlook-formats)))
2195 (save-excursion
2196 (save-window-excursion
2197 ;; Fixme: References to optional fields in the format
2198 ;; are treated literally, not replaced by the empty
2199 ;; string. I think this is an Emacs bug.
2200 (make-diary-entry
2201 (format (replace-match (if (functionp format-string)
2202 (funcall format-string body)
2203 format-string)
2204 t nil (match-string 0 body))
2205 subject))
2206 (save-buffer))))
2207 (throw 'finished t))))
2208 nil))
2210 (defun diary-from-outlook (&optional noconfirm)
2211 "Maybe snarf diary entry from current Outlook-generated message.
2212 Currently knows about Gnus and Rmail modes. Unless the optional
2213 argument NOCONFIRM is non-nil (which is the case when this
2214 function is called interactively), then if an entry is found the
2215 user is asked to confirm its addition."
2216 (interactive "p")
2217 (let ((func (cond
2218 ((eq major-mode 'rmail-mode)
2219 #'diary-from-outlook-rmail)
2220 ((memq major-mode '(gnus-summary-mode gnus-article-mode))
2221 #'diary-from-outlook-gnus)
2222 (t (error "Don't know how to snarf in `%s'" major-mode)))))
2223 (funcall func noconfirm)))
2226 (defvar gnus-article-mime-handles)
2227 (defvar gnus-article-buffer)
2229 (autoload 'gnus-fetch-field "gnus-util")
2230 (autoload 'gnus-narrow-to-body "gnus")
2231 (autoload 'mm-get-part "mm-decode")
2233 (defun diary-from-outlook-gnus (&optional noconfirm)
2234 "Maybe snarf diary entry from Outlook-generated message in Gnus.
2235 Unless the optional argument NOCONFIRM is non-nil (which is the case when
2236 this function is called interactively), then if an entry is found the
2237 user is asked to confirm its addition.
2238 Add this function to `gnus-article-prepare-hook' to notice appointments
2239 automatically."
2240 (interactive "p")
2241 (with-current-buffer gnus-article-buffer
2242 (let ((subject (gnus-fetch-field "subject"))
2243 (body (if gnus-article-mime-handles
2244 ;; We're multipart. Don't get confused by part
2245 ;; buttons &c. Assume info is in first part.
2246 (mm-get-part (nth 1 gnus-article-mime-handles))
2247 (save-restriction
2248 (gnus-narrow-to-body)
2249 (buffer-string)))))
2250 (when (diary-from-outlook-internal t)
2251 (when (or noconfirm (y-or-n-p "Snarf diary entry? "))
2252 (diary-from-outlook-internal)
2253 (message "Diary entry added"))))))
2255 (custom-add-option 'gnus-article-prepare-hook 'diary-from-outlook-gnus)
2258 (defvar rmail-buffer)
2260 (defun diary-from-outlook-rmail (&optional noconfirm)
2261 "Maybe snarf diary entry from Outlook-generated message in Rmail.
2262 Unless the optional argument NOCONFIRM is non-nil (which is the case when
2263 this function is called interactively), then if an entry is found the
2264 user is asked to confirm its addition."
2265 (interactive "p")
2266 (with-current-buffer rmail-buffer
2267 (let ((subject (mail-fetch-field "subject"))
2268 (body (buffer-substring (save-excursion
2269 (rfc822-goto-eoh)
2270 (point))
2271 (point-max))))
2272 (when (diary-from-outlook-internal t)
2273 (when (or noconfirm (y-or-n-p "Snarf diary entry? "))
2274 (diary-from-outlook-internal)
2275 (message "Diary entry added"))))))
2278 (provide 'diary-lib)
2280 ;; arch-tag: 22dd506e-2e33-410d-9ae1-095a0c1b2010
2281 ;;; diary-lib.el ends here