1 ;;; diary-lib.el --- diary functions
3 ;; Copyright (C) 1989-1990, 1992-1995, 2001-2013 Free Software
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 3 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
32 (eval-and-compile (load "diary-loaddefs" nil t
))
39 (defcustom diary-include-string
"#include"
40 "The string indicating inclusion of another file of diary entries.
41 See the documentation for the function `diary-include-other-diary-files'."
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
52 (defcustom diary-face
'diary
53 "Face name to use for diary entries."
55 :group
'calendar-faces
)
56 (make-obsolete-variable 'diary-face
"customize the face `diary' instead."
59 (defface diary-anniversary
'((t :inherit font-lock-keyword-face
))
60 "Face used for anniversaries in the fancy diary display."
62 :group
'calendar-faces
)
64 (defface diary-time
'((t :inherit font-lock-variable-name-face
))
65 "Face used for times of day in the fancy diary display."
67 :group
'calendar-faces
)
69 (defface diary-button
'((((type pc
) (class color
))
70 (:foreground
"lightblue")))
71 "Face used for buttons in the fancy diary display."
73 :group
'calendar-faces
)
75 (define-obsolete-face-alias 'diary-button-face
'diary-button
"22.1")
77 ;; Face markup of calendar and diary displays: Any entry line that
78 ;; ends with [foo:value] where foo is a face attribute (except :box
79 ;; :stipple) or with [face:blah] tags, will have these values applied
80 ;; to the calendar and fancy diary displays. These attributes "stack"
81 ;; on calendar displays. File-wide attributes can be defined as
82 ;; follows: the first line matching "^# [tag:value]" defines the value
83 ;; for that particular tag.
84 (defcustom diary-face-attrs
85 '((" *\\[foreground:\\([-a-z]+\\)\\]$" 1 :foreground string
)
86 (" *\\[background:\\([-a-z]+\\)\\]$" 1 :background string
)
87 (" *\\[width:\\([-a-z]+\\)\\]$" 1 :width symbol
)
88 (" *\\[height:\\([.0-9]+\\)\\]$" 1 :height int
)
89 (" *\\[weight:\\([-a-z]+\\)\\]$" 1 :weight symbol
)
90 (" *\\[slant:\\([-a-z]+\\)\\]$" 1 :slant symbol
)
91 (" *\\[underline:\\([-a-z]+\\)\\]$" 1 :underline stringtnil
)
92 (" *\\[overline:\\([-a-z]+\\)\\]$" 1 :overline stringtnil
)
93 (" *\\[strike-through:\\([-a-z]+\\)\\]$" 1 :strike-through stringtnil
)
94 (" *\\[inverse-video:\\([-a-z]+\\)\\]$" 1 :inverse-video tnil
)
95 (" *\\[face:\\([-0-9a-z]+\\)\\]$" 1 :face string
)
96 (" *\\[font:\\([-a-z0-9]+\\)\\]$" 1 :font string
)
98 ;;; (" *\\[box:\\([-a-z]+\\)\\]$" 1 :box)
99 ;;; (" *\\[stipple:\\([-a-z]+\\)\\]$" 1 :stipple)
101 "Alist of (REGEXP SUBEXP ATTRIBUTE TYPE) elements.
102 This is used by `diary-pull-attrs' to fontify certain diary
103 elements. REGEXP is a regular expression to for, and SUBEXP is
104 the numbered sub-expression to extract. `diary-glob-file-regexp-prefix'
105 is pre-pended to REGEXP for file-wide specifiers. ATTRIBUTE
106 specifies which face attribute (e.g. `:foreground') to modify, or
107 that this is a face (`:face') to apply. TYPE is the type of
108 attribute being applied. Available TYPES (see `diary-attrtype-convert')
109 are: `string', `symbol', `int', `tnil', `stringtnil.'"
110 :type
'(repeat (list (string :tag
"Regular expression")
111 (integer :tag
"Sub-expression")
112 (symbol :tag
"Attribute (e.g. :foreground)")
113 (choice (const string
:tag
"A string")
114 (const symbol
:tag
"A symbol")
115 (const int
:tag
"An integer")
116 (const tnil
:tag
"`t' or `nil'")
118 :tag
"A string, `t', or `nil'"))))
121 (defcustom diary-glob-file-regexp-prefix
"^\\#"
122 "Regular expression pre-pended to `diary-face-attrs' for file-wide specifiers."
126 (defcustom diary-file-name-prefix nil
127 "Non-nil means prefix each diary entry with the name of the file defining it."
131 (defcustom diary-file-name-prefix-function
'identity
132 "The function that will take a diary file name and return the desired prefix."
136 (define-obsolete-variable-alias 'sexp-diary-entry-symbol
137 'diary-sexp-entry-symbol
"23.1")
139 (defcustom diary-sexp-entry-symbol
"%%"
140 "The string used to indicate a sexp diary entry in `diary-file'.
141 See the documentation for the function `diary-list-sexp-entries'."
145 (defcustom diary-comment-start nil
146 "String marking the start of a comment in the diary, or nil.
147 Nil means there are no comments. The diary does not display
148 parts of entries that are inside comments. You can use comments
149 for whatever you like, e.g. for meta-data that packages such as
150 `appt.el' can use. Comments may not span multiple lines, and there
151 can be only one comment on any line.
152 See also `diary-comment-end'."
154 :type
'(choice (const :tag
"No comment" nil
) string
)
157 (defcustom diary-comment-end
""
158 "String marking the end of a comment in the diary.
159 The empty string means comments finish at the end of a line.
160 See also `diary-comment-start'."
165 (defcustom diary-hook nil
166 "List of functions called after the display of the diary.
167 Used for example by the appointment package - see `appt-activate'."
171 (define-obsolete-variable-alias 'diary-display-hook
'diary-display-function
174 (defcustom diary-display-function
'diary-fancy-display
175 "Function used to display the diary.
176 The two standard options are `diary-fancy-display' and `diary-simple-display'.
178 For historical reasons, `nil' is the same as `diary-simple-display'
179 \(so you must use `ignore' for no display). Also for historical
180 reasons, this variable can be a list of functions to run. These
181 uses are not recommended and may be removed at some point.
183 When this function is called, the variable `diary-entries-list'
184 is a list, in order by date, of all relevant diary entries in the
185 form of ((MONTH DAY YEAR) STRING), where string is the diary
186 entry for the given date. This can be used, for example, to
187 produce a different buffer for display (perhaps combined with
188 holidays), or hard copy output."
189 :type
'(choice (const diary-fancy-display
:tag
"Fancy display")
190 (const diary-simple-display
:tag
"Basic display")
191 (const ignore
:tag
"No display")
192 (const nil
:tag
"Obsolete way to choose basic display")
193 (hook :tag
"Obsolete form with list of display functions"))
194 :initialize
'custom-initialize-default
195 :set
'diary-set-maybe-redraw
196 :version
"23.2" ; simple->fancy
199 (define-obsolete-variable-alias 'list-diary-entries-hook
200 'diary-list-entries-hook
"23.1")
202 (defcustom diary-list-entries-hook nil
203 "Hook run after diary file is culled for relevant entries.
205 If you add `diary-include-other-diary-files' to this hook, you
206 will probably also want to add `diary-mark-included-diary-files'
207 to `diary-mark-entries-hook'. For example, to cause the fancy
208 diary buffer to be displayed with diary entries from various
209 included files, each day's entries sorted into lexicographic
210 order, add the following to your init file:
212 (setq diary-display-function 'diary-fancy-display)
213 (add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
214 (add-hook 'diary-list-entries-hook 'diary-sort-entries t)
216 Note how the sort function is placed last, so that it can sort
217 the entries included from other files.
219 This hook runs after `diary-nongregorian-listing-hook'. These two hooks
220 differ only if you are using included diary files. In that case,
221 `diary-nongregorian-listing-hook' runs for each file, whereas
222 `diary-list-entries-hook' only runs once, for the main diary file.
223 So for example, to sort the complete list of diary entries you would
224 use the list-entries hook, whereas to process e.g. Islamic entries in
225 the main file and all included files, you would use the nongregorian hook."
227 :options
'(diary-include-other-diary-files diary-sort-entries
)
230 (define-obsolete-variable-alias 'mark-diary-entries-hook
231 'diary-mark-entries-hook
"23.1")
233 (defcustom diary-mark-entries-hook nil
234 "List of functions called after marking diary entries in the calendar.
235 You might wish to add `diary-mark-included-diary-files', in which case
236 you will probably also want to add `diary-include-other-diary-files' to
237 `diary-list-entries-hook'.
239 This hook runs after `diary-nongregorian-marking-hook'. These two hooks
240 differ only if you are using included diary files. In that case,
241 `diary-nongregorian-marking-hook' runs for each file, whereas
242 `diary-mark-entries-hook' only runs once, for the main diary file."
244 :options
'(diary-mark-included-diary-files)
247 (define-obsolete-variable-alias 'nongregorian-diary-listing-hook
248 'diary-nongregorian-listing-hook
"23.1")
250 (defcustom diary-nongregorian-listing-hook nil
251 "List of functions called for listing diary file and included files.
252 As the files are processed for diary entries, these functions are used
253 to cull relevant entries. You can use any or all of
254 `diary-bahai-list-entries', `diary-hebrew-list-entries', and
255 `diary-islamic-list-entries'. The documentation for these functions
256 describes the style of such diary entries.
258 You can use this hook for other functions as well, if you want them to
259 be run on the main diary file and any included diary files. Otherwise,
260 use `diary-list-entries-hook', which runs only for the main diary file."
262 :options
'(diary-bahai-list-entries
263 diary-hebrew-list-entries
264 diary-islamic-list-entries
)
267 (define-obsolete-variable-alias 'nongregorian-diary-marking-hook
268 'diary-nongregorian-marking-hook
"23.1")
270 (defcustom diary-nongregorian-marking-hook nil
271 "List of functions called for marking diary file and included files.
272 As the files are processed for diary entries, these functions are used
273 to cull relevant entries. You can use any or all of
274 `diary-bahai-mark-entries', `diary-hebrew-mark-entries' and
275 `diary-islamic-mark-entries'. The documentation for these functions
276 describes the style of such diary entries.
278 You can use this hook for other functions as well, if you want them to
279 be run on the main diary file and any included diary files. Otherwise,
280 use `diary-mark-entries-hook', which runs only for the main diary file."
282 :options
'(diary-bahai-mark-entries
283 diary-hebrew-mark-entries
284 diary-islamic-mark-entries
)
287 (define-obsolete-variable-alias 'print-diary-entries-hook
288 'diary-print-entries-hook
"23.1")
290 (defcustom diary-print-entries-hook
'lpr-buffer
291 "Run by `diary-print-entries' after preparing a temporary diary buffer.
292 The buffer shows only the diary entries currently visible in the
293 diary buffer. The default just does the printing. Other uses
294 might include, for example, rearranging the lines into order by
295 day and time, saving the buffer instead of deleting it, or
296 changing the function used to do the printing."
300 (defcustom diary-unknown-time -
9999
301 "Value returned by `diary-entry-time' when no time is found.
302 The default value -9999 causes entries with no recognizable time
303 to be placed before those with times; 9999 would place entries
304 with no recognizable time after those with times."
309 (defcustom diary-mail-addr
310 (or (bound-and-true-p user-mail-address
) "")
311 "Email address that `diary-mail-entries' will send email to."
316 (defcustom diary-mail-days
7
317 "Default number of days for `diary-mail-entries' to check."
322 (defcustom diary-remind-message
324 (if (zerop (% days
7))
325 (format "%d week%s" (/ days
7) (if (= 7 days
) "" "s"))
326 (format "%d day%s" days
(if (= 1 days
) "" "s")))
329 "Pseudo-pattern giving form of reminder messages in the fancy diary display.
331 Used by the function `diary-remind', a pseudo-pattern is a list of
332 expressions that can involve the keywords `days' (a number), `date'
333 \(a list of month, day, year), and `diary-entry' (a string)."
337 (define-obsolete-variable-alias 'abbreviated-calendar-year
338 'diary-abbreviated-year-flag
"23.1")
340 (defcustom diary-abbreviated-year-flag t
341 "Interpret a two-digit year DD in a diary entry as either 19DD or 20DD.
342 This applies to the Gregorian, Hebrew, Islamic, and Bahá'à calendars.
343 When the current century is added to a two-digit year, if the result
344 is more than 50 years in the future, the previous century is assumed.
345 If the result is more than 50 years in the past, the next century is assumed.
346 If this variable is nil, years must be written in full."
350 (defun diary-outlook-format-1 (body)
351 "Return a replace-match template for an element of `diary-outlook-formats'.
352 Returns a string using match elements 1-5, where:
353 1 = month name, 2 = day, 3 = year, 4 = time, 5 = location; also uses
354 %s = message subject. BODY is the string from which the matches derive."
355 (let* ((monthname (match-string 1 body
))
356 (day (match-string 2 body
))
357 (year (match-string 3 body
))
360 (dotimes (i (length calendar-month-name-array
))
361 (if (string-equal (aref calendar-month-name-array i
)
363 (throw 'found
(1+ i
))))
365 ;; If we could convert the monthname to a numeric month, we can
366 ;; use the standard function calendar-date-string.
368 (calendar-date-string (list month
(string-to-number day
)
369 (string-to-number year
)) nil t
)
370 (cond ((eq calendar-date-style
'iso
) "\\3 \\1 \\2") ; YMD
371 ((eq calendar-date-style
'european
) "\\2 \\1 \\3") ; DMY
372 (t "\\1 \\2 \\3"))) ; MDY
374 ;; TODO Sometimes the time is in a different time-zone to the one you
375 ;; are in. Eg in PST, you might still get an email referring to:
376 ;; "7:00 PM-8:00 PM. Greenwich Standard Time".
377 ;; Note that it doesn't use a standard abbreviation for the timezone,
378 ;; or anything helpful like that.
379 ;; Sigh, this could cause the meeting to even be on a different day
380 ;; to that given in the When: string.
381 ;; These things seem to come in a multipart mail with a calendar part,
382 ;; it's probably better to use that rather than this whole thing.
383 ;; So this is unlikely to get improved.
385 ;; TODO Is the format of these messages actually documented anywhere?
386 (defcustom diary-outlook-formats
387 '(;; When: Tuesday, November 9, 2010 7:00 PM-8:00 PM. Greenwich Standard Time
388 ;; Where: Meeting room B
389 ("[ \t\n]*When: [[:alpha:]]+, \\([[:alpha:]]+\\) \\([0-9][0-9]*\\), \
390 \\([0-9]\\{4\\}\\),? \\(.+\\)\n\
391 \\(?:Where: \\(.+\n\\)\\)?" . diary-outlook-format-1
))
392 "Alist of regexps matching message text and replacement text.
394 The regexp must match the start of the message text containing an
395 appointment, but need not include a leading `^'. If it matches the
396 current message, a diary entry is made from the corresponding
397 template. If the template is a string, it should be suitable for
398 passing to `replace-match', and so will have occurrences of `\\D' to
399 substitute the match for the Dth subexpression. It must also contain
400 a single `%s' which will be replaced with the text of the message's
401 Subject field. Any other `%' characters must be doubled, so that the
402 template can be passed to `format'.
404 If the template is actually a function, it is called with the message
405 body text as argument, and may use `match-string' etc. to make a
406 template following the rules above."
407 :type
'(alist :key-type
(regexp :tag
"Regexp matching time/place")
409 (string :tag
"Template for entry")
411 "Unary function providing template")))
415 (defvar diary-header-line-flag
)
416 (defvar diary-header-line-format
)
418 (defun diary-set-header (symbol value
)
419 "Set SYMBOL's value to VALUE, and redraw the diary header if necessary."
420 (let ((oldvalue (symbol-value symbol
))
421 (dbuff (and diary-file
(find-buffer-visiting diary-file
))))
422 (custom-set-default symbol value
)
424 (not (equal value oldvalue
))
425 (with-current-buffer dbuff
426 (if (eq major-mode
'diary-mode
)
427 (setq header-line-format
(and diary-header-line-flag
428 diary-header-line-format
)))))))
430 ;; This can be removed once the kill/yank treatment of invisible text
431 ;; (see etc/TODO) is fixed. -- gm
432 (defcustom diary-header-line-flag t
433 "Non-nil means `diary-simple-display' will show a header line.
434 The format of the header is specified by `diary-header-line-format'."
437 :initialize
'custom-initialize-default
438 :set
'diary-set-header
441 (defvar diary-selective-display nil
442 "Internal diary variable; non-nil if some diary text is hidden.")
444 (defcustom diary-header-line-format
445 '(:eval
(calendar-string-spread
446 (list (if diary-selective-display
447 "Some text is hidden - press \"C-c C-s\" before edit/copy"
450 "Format of the header line displayed by `diary-simple-display'.
451 Only used if `diary-header-line-flag' is non-nil."
454 :initialize
'custom-initialize-default
455 :set
'diary-set-header
456 :version
"23.3") ; frame-width -> window-width
458 ;; The first version of this also checked for diary-selective-display
459 ;; in the non-fancy case. This was an attempt to distinguish between
460 ;; displaying the diary and just visiting the diary file. However,
461 ;; when using fancy diary, calling diary when there are no entries to
462 ;; display does not create the fancy buffer, nor does it set
463 ;; diary-selective-display in the diary buffer. This means some
464 ;; customizations will not take effect, eg:
465 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-03/msg00466.html
466 ;; So the check for diary-selective-display was dropped. This means the
467 ;; diary will be displayed if one customizes a diary variable while
468 ;; just visiting the diary-file. This is i) unlikely, and ii) no great loss.
470 (defun diary-live-p ()
471 "Return non-nil if the diary is being displayed."
472 (or (get-buffer diary-fancy-buffer
)
473 (and diary-file
(find-buffer-visiting diary-file
))))
476 (defun diary-set-maybe-redraw (symbol value
)
477 "Set SYMBOL's value to VALUE, and redraw the diary if necessary.
478 Redraws the diary if it is being displayed (note this is not the same as
479 just visiting the `diary-file'), and SYMBOL's value is to be changed."
480 (let ((oldvalue (symbol-value symbol
)))
481 (custom-set-default symbol value
)
482 (and (not (equal value oldvalue
))
484 ;; Note this assumes diary was called without prefix arg.
487 (define-obsolete-variable-alias 'number-of-diary-entries
488 'diary-number-of-entries
"23.1")
490 (defcustom diary-number-of-entries
1
491 "Specifies how many days of diary entries are to be displayed initially.
492 This variable affects the diary display when the command \\[diary] is
493 used, or if the value of the variable `calendar-view-diary-initially-flag'
494 is non-nil. For example, if the default value 1 is used, then only the
495 current day's diary entries will be displayed. If the value 2 is used,
496 then both the current day's and the next day's entries will be displayed.
498 The value can also be a vector such as [0 2 2 2 2 4 1]; this value says
499 to display no diary entries on Sunday, the entries for the current date
500 and the day after on Monday through Thursday, Friday through Monday's
501 entries on Friday, and only Saturday's entries on Saturday.
503 This variable does not affect the diary display with the `d' command
504 from the calendar; in that case, the prefix argument controls the number
505 of days of diary entries displayed."
506 :type
'(choice (integer :tag
"Entries")
507 (vector :value
[0 0 0 0 0 0 0]
508 (integer :tag
"Sunday")
509 (integer :tag
"Monday")
510 (integer :tag
"Tuesday")
511 (integer :tag
"Wednesday")
512 (integer :tag
"Thursday")
513 (integer :tag
"Friday")
514 (integer :tag
"Saturday")))
515 :initialize
'custom-initialize-default
516 :set
'diary-set-maybe-redraw
519 ;;; More user options in calendar.el, holidays.el.
522 (defun diary-check-diary-file ()
523 "Check that the file specified by `diary-file' exists and is readable.
524 If so, return the expanded file name, otherwise signal an error."
525 (if (and diary-file
(file-exists-p diary-file
))
526 (if (file-readable-p diary-file
)
528 (error "Diary file `%s' is not readable" diary-file
))
529 (error "Diary file `%s' does not exist" diary-file
)))
532 (defun diary (&optional arg
)
533 "Generate the diary window for ARG days starting with the current date.
534 If no argument is provided, the number of days of diary entries is governed
535 by the variable `diary-number-of-entries'. A value of ARG less than 1
536 does nothing. This function is suitable for execution in an init file."
538 (diary-check-diary-file)
539 (diary-list-entries (calendar-current-date)
540 (if arg
(prefix-numeric-value arg
))))
543 (defun diary-view-entries (&optional arg
)
544 "Prepare and display a buffer with diary entries.
545 Searches the file named in `diary-file' for entries that match
546 ARG days starting with the date indicated by the cursor position
547 in the displayed three-month calendar."
549 (diary-check-diary-file)
550 (diary-list-entries (calendar-cursor-to-date t
) arg
))
554 (defun diary-view-other-diary-entries (arg dfile
)
555 "Prepare and display buffer of diary entries from an alternative diary file.
556 Searches for entries that match ARG days, starting with the date indicated
557 by the cursor position in the displayed three-month calendar.
558 DFILE specifies the file to use as the diary file."
560 (list (prefix-numeric-value current-prefix-arg
)
561 (read-file-name "Enter diary file name: " default-directory nil t
)))
562 (let ((diary-file dfile
))
563 (diary-view-entries arg
)))
566 (define-obsolete-function-alias 'view-other-diary-entries
567 'diary-view-other-diary-entries
"23.1")
569 (defvar diary-syntax-table
570 (let ((st (copy-syntax-table (standard-syntax-table))))
571 (modify-syntax-entry ?
* "w" st
)
572 (modify-syntax-entry ?
: "w" st
)
574 "The syntax table used when parsing dates in the diary file.
575 It is the standard syntax table used in Fundamental mode, but with the
576 syntax of `*' and `:' changed to be word constituents.")
578 (defun diary-attrtype-convert (attrvalue type
)
579 "Convert string ATTRVALUE to TYPE appropriate for a face description.
580 Valid TYPEs are: string, symbol, int, stringtnil, tnil."
581 (cond ((eq type
'string
) attrvalue
)
582 ((eq type
'symbol
) (intern-soft attrvalue
))
583 ((eq type
'int
) (string-to-number attrvalue
))
584 ((eq type
'stringtnil
)
585 (cond ((string-equal "t" attrvalue
) t
)
586 ((string-equal "nil" attrvalue
) nil
)
588 ((eq type
'tnil
) (string-equal "t" attrvalue
))))
590 (defun diary-pull-attrs (entry fileglobattrs
)
591 "Search for matches for regexps from `diary-face-attrs'.
592 If ENTRY is nil, searches from the start of the current buffer, and
593 prepends all regexps with `diary-glob-file-regexp-prefix'.
594 If ENTRY is a string, search for matches in that string, and remove them.
595 Returns a list of ENTRY followed by (ATTRIBUTE VALUE) pairs.
596 When ENTRY is non-nil, FILEGLOBATTRS forms the start of the (ATTRIBUTE VALUE)
598 (let (regexp regnum attrname attrname attrvalue type ret-attr
)
601 (dolist (attr diary-face-attrs
)
602 ;; FIXME inefficient searching.
603 (goto-char (point-min))
604 (setq regexp
(concat diary-glob-file-regexp-prefix
(car attr
))
606 attrname
(nth 2 attr
)
608 attrvalue
(if (re-search-forward regexp nil t
)
609 (match-string-no-properties regnum
)))
611 (setq attrvalue
(diary-attrtype-convert attrvalue type
))
612 (setq ret-attr
(append ret-attr
613 (list attrname attrvalue
))))))
614 (setq ret-attr fileglobattrs
)
615 (dolist (attr diary-face-attrs
)
616 (setq regexp
(car attr
)
618 attrname
(nth 2 attr
)
621 ;; If multiple matches, replace all, use the last (which may
622 ;; be the first instance in the line, if the regexp is
624 (while (string-match regexp entry
)
625 (setq attrvalue
(match-string-no-properties regnum entry
)
626 entry
(replace-match "" t t entry
)))
628 (setq attrvalue
(diary-attrtype-convert attrvalue type
))
629 (setq ret-attr
(append ret-attr
(list attrname attrvalue
))))))
630 (list entry ret-attr
)))
634 (defvar diary-modify-entry-list-string-function nil
635 "Function applied to entry string before putting it into the entries list.
636 Can be used by programs integrating a diary list into other buffers (e.g.
637 org.el and planner.el) to modify the string or add properties to it.
638 The function takes a string argument and must return a string.")
640 (defvar diary-entries-list
) ; bound in diary-list-entries
642 (defun diary-add-to-list (date string specifier
&optional marker
644 "Add an entry to `diary-entries-list'.
645 Do nothing if DATE or STRING are nil. DATE is the (MONTH DAY
646 YEAR) for which the entry applies; STRING is the text of the
647 entry as it will appear in the diary (i.e. with any format
648 strings such as \"%d\" expanded); SPECIFIER is the date part of
649 the entry as it appears in the diary-file; LITERAL is the entry
650 as it appears in the diary-file (i.e. before expansion).
651 If LITERAL is nil, it is taken to be the same as STRING.
653 The entry is added to the list as (DATE STRING SPECIFIER LOCATOR
654 GLOBCOLOR), where LOCATOR has the form (MARKER FILENAME LITERAL),
655 FILENAME being the file containing the diary entry.
657 Modifies STRING using `diary-modify-entry-list-string-function', if non-nil.
658 Also removes the region between `diary-comment-start' and
659 `diary-comment-end', if the former is non-nil."
660 (when (and date string
)
661 ;; b-f-n is nil if we are visiting an include file in a temp-buffer.
662 (let ((dfile (or (buffer-file-name) diary-file
))
664 (if diary-file-name-prefix
665 (let ((prefix (funcall diary-file-name-prefix-function dfile
)))
666 (or (string-equal prefix
"")
667 (setq string
(format "[%s] %s" prefix string
)))))
668 (and diary-modify-entry-list-string-function
669 (setq string
(funcall diary-modify-entry-list-string-function
671 (when (and diary-comment-start
672 (string-match (setq cstart
(regexp-quote diary-comment-start
))
674 ;; Preserve the value with the comments.
675 (or literal
(setq literal string
))
676 ;; Handles multiple comments per entry, so long as each is on
677 ;; a single line, and each line has no more than one comment.
678 (setq string
(replace-regexp-in-string
679 (format "%s.*%s" cstart
(regexp-quote diary-comment-end
))
681 (setq diary-entries-list
682 (append diary-entries-list
683 (list (list date string specifier
684 (list marker dfile literal
)
687 (define-obsolete-function-alias 'add-to-diary-list
'diary-add-to-list
"23.1")
689 (defun diary-list-entries-2 (date mark globattr list-only
690 &optional months symbol gdate
)
691 "Internal subroutine of `diary-list-entries'.
692 Find diary entries applying to DATE, by searching from point-min for
693 each element of `diary-date-forms'. MARK indicates an entry is non-marking.
694 GLOBATTR is the list of global file attributes. If LIST-ONLY is
695 non-nil, don't change the buffer, only return a list of entries.
696 Optional array MONTHS replaces `calendar-month-name-array', and
697 means months cannot be abbreviated. Optional string SYMBOL marks diary
698 entries of the desired type. If DATE is not Gregorian, then the
699 Gregorian equivalent should be provided via GDATE. Returns non-nil if
700 any entries were found."
701 (let* ((month (calendar-extract-month date
))
702 (day (calendar-extract-day date
))
703 (year (calendar-extract-year date
))
704 (dayname (format "%s\\|%s\\.?" (calendar-day-name date
)
705 (calendar-day-name date
'abbrev
)))
706 (calendar-month-name-array (or months calendar-month-name-array
))
707 (monthname (format "\\*\\|%s%s" (calendar-month-name month
)
710 (calendar-month-name month
'abbrev
)))))
711 (month (format "\\*\\|0*%d" month
))
712 (day (format "\\*\\|0*%d" day
))
713 (year (format "\\*\\|0*%d%s" year
714 (if diary-abbreviated-year-flag
715 (format "\\|%02d" (% year
100))
719 (dolist (date-form diary-date-forms
)
720 (let ((backup (when (eq (car date-form
) 'backup
)
721 (setq date-form
(cdr date-form
))
723 ;; date-form uses day etc as set above.
724 (regexp (format "^%s?%s\\(%s\\)" (regexp-quote mark
)
725 (if symbol
(regexp-quote symbol
) "")
726 (mapconcat 'eval date-form
"\\)\\(?:")))
727 entry-start date-start temp
)
728 (goto-char (point-min))
729 (while (re-search-forward regexp nil t
)
730 (if backup
(re-search-backward "\\<" nil t
))
731 ;; regexp moves us past the end of date, onto the next line.
732 ;; Trailing whitespace after date not allowed (see diary-file).
733 (if (and (bolp) (not (looking-at "[ \t]")))
734 ;; Diary entry that consists only of date.
736 ;; Found a nonempty diary entry--make it
737 ;; visible and add it to the list.
738 (setq date-start
(line-end-position 0))
739 ;; Actual entry starts on the next-line?
740 (if (looking-at "[ \t]*\n[ \t]") (forward-line 1))
744 (while (looking-at "[ \t]") ; continued entry
746 (unless (and (eobp) (not (bolp)))
749 (remove-overlays date-start
(point) 'invisible
'diary
))
750 (setq temp
(diary-pull-attrs
751 (buffer-substring-no-properties
752 entry-start
(point)) globattr
))
754 (or gdate date
) (car temp
)
755 (buffer-substring-no-properties (1+ date-start
) (1- entry-start
))
756 (copy-marker entry-start
) (cadr temp
))))))
759 (defvar original-date
) ; from diary-list-entries
760 (defvar file-glob-attrs
)
764 (defun diary-list-entries-1 (months symbol absfunc
)
765 "List diary entries of a certain type.
766 MONTHS is an array of month names. SYMBOL marks diary entries of the type
767 in question. ABSFUNC is a function that converts absolute dates to dates
768 of the appropriate type."
769 (let ((gdate original-date
))
770 (dotimes (_idummy number
)
771 (diary-list-entries-2
772 (funcall absfunc
(calendar-absolute-from-gregorian gdate
))
773 diary-nonmarking-symbol file-glob-attrs list-only months symbol gdate
)
775 (calendar-gregorian-from-absolute
776 (1+ (calendar-absolute-from-gregorian gdate
))))))
777 (goto-char (point-min)))
779 (defvar diary-included-files nil
780 "List of any diary files included in the last call to `diary-list-entries'.
781 Or to `diary-mark-entries'.")
783 (defun diary-list-entries (date number
&optional list-only
)
784 "Create and display a buffer containing the relevant lines in `diary-file'.
785 Selects entries for NUMBER days starting with date DATE. Hides any
786 other entries using overlays. If NUMBER is less than 1, this function
789 Returns a list of all relevant diary entries found.
790 The list entries have the form ((MONTH DAY YEAR) STRING SPECIFIER) where
791 \(MONTH DAY YEAR) is the date of the entry, STRING is the entry text, and
792 SPECIFIER is the applicability. If the variable `diary-list-include-blanks'
793 is non-nil, this list includes a dummy diary entry consisting of the empty
794 string for a date with no diary entries.
796 If producing entries for multiple dates (i.e., NUMBER > 1), then
797 this function normally returns the entries from any given diary
798 file in date order. The entries for any given day are in the
799 order in which they were found in the file, not necessarily in
800 time-of-day order. Note that any functions present on the
801 hooks (see below) may add entries, or change the order. For
802 example, `diary-include-other-diary-files' adds entries from any
803 include files that it finds to the end of the original list. The
804 entries from each file will be in date order, but the overall
805 list will not be. If you want the entire list to be in time
806 order, add `diary-sort-entries' to the end of `diary-list-entries-hook'.
808 After preparing the initial list, hooks run in this order:
810 `diary-nongregorian-listing-hook' runs for the main diary file,
811 and each included file. For example, this is the appropriate hook
812 to process Islamic entries in all diary files.
814 `diary-list-entries-hook' runs once only, for the main diary file.
815 For example, this is appropriate for sorting all the entries.
816 If not using include files, there is no difference from the previous
819 `diary-hook' runs last, after the diary is displayed.
820 This is used e.g. by `appt-check'.
822 Functions called by these hooks may use the variables ORIGINAL-DATE
823 and NUMBER, which are the arguments with which this function was called.
824 Note that hook functions should _not_ use DATE, but ORIGINAL-DATE.
825 \(Sexp diary entries may use DATE - see `diary-list-sexp-entries'.)
827 This function displays the list using `diary-display-function', unless
828 LIST-ONLY is non-nil, in which case it just returns the list."
830 (setq number
(if (vectorp diary-number-of-entries
)
831 (aref diary-number-of-entries
(calendar-day-of-week date
))
832 diary-number-of-entries
)))
834 (let* ((original-date date
) ; save for possible use in the hooks
835 (date-string (calendar-date-string date
))
836 (diary-buffer (find-buffer-visiting diary-file
))
837 ;; Dynamically bound in diary-include-files.
838 (d-incp (and (boundp 'diary-including
) diary-including
))
839 diary-entries-list file-glob-attrs temp-buff
)
841 (setq diary-included-files nil
)
842 (message "Preparing diary..."))
844 (with-current-buffer (or diary-buffer
846 (setq temp-buff
(generate-new-buffer
848 (find-file-noselect diary-file t
)))
850 (or (verify-visited-file-modtime diary-buffer
)
851 (revert-buffer t t
)))
853 ;; If including, caller has already verified it is readable.
854 (insert-file-contents diary-file
)
855 ;; Setup things like the header-line-format and invisibility-spec.
856 (if (eq major-mode
(default-value 'major-mode
))
858 ;; This kludge is to make customizations to
859 ;; diary-header-line-flag after diary has been displayed
860 ;; take effect. Unconditionally calling (diary-mode)
861 ;; clobbers file local variables.
862 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-03/msg00363.html
863 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-04/msg00404.html
864 (if (eq major-mode
'diary-mode
)
865 (setq header-line-format
(and diary-header-line-flag
866 diary-header-line-format
)))))
867 ;; d-s-p is passed to the diary display function.
868 (let ((diary-saved-point (point)))
872 (setq file-glob-attrs
(cadr (diary-pull-attrs nil
"")))
873 (with-syntax-table diary-syntax-table
874 (goto-char (point-min))
876 (let ((ol (make-overlay (point-min) (point-max) nil t nil
)))
877 (set (make-local-variable 'diary-selective-display
) t
)
878 (overlay-put ol
'invisible
'diary
)
879 (overlay-put ol
'evaporate t
)))
880 (dotimes (_idummy number
)
881 (let ((sexp-found (diary-list-sexp-entries date
))
882 (entry-found (diary-list-entries-2
883 date diary-nonmarking-symbol
884 file-glob-attrs list-only
)))
885 (if diary-list-include-blanks
886 (or sexp-found entry-found
887 (diary-add-to-list date
"" "" "" "")))
889 (calendar-gregorian-from-absolute
890 (1+ (calendar-absolute-from-gregorian date
)))))))
891 (goto-char (point-min))
892 ;; Although it looks like list-entries-hook runs
893 ;; every time, diary-include-other-diary-files
894 ;; binds it to nil (essentially) when it runs
895 ;; in included files.
896 (run-hooks 'diary-nongregorian-listing-hook
897 'diary-list-entries-hook
)
898 ;; We could make this explicit:
899 ;;; (run-hooks 'diary-nongregorian-listing-hook)
901 ;;; (diary-include-other-diary-files) ; recurse
902 ;;; (run-hooks 'diary-list-entries-hook))
904 (if (and diary-display-function
905 (listp diary-display-function
))
906 ;; Backwards compatibility.
907 (run-hooks 'diary-display-function
)
908 (funcall (or diary-display-function
909 'diary-simple-display
))))
910 (run-hooks 'diary-hook
)))))
911 (and temp-buff
(buffer-name temp-buff
) (kill-buffer temp-buff
)))
912 (or d-incp
(message "Preparing diary...done"))
913 diary-entries-list
)))
915 (defun diary-unhide-everything ()
916 "Show all invisible text in the diary."
917 (kill-local-variable 'diary-selective-display
)
918 (save-restriction ; bug#5477
920 (remove-overlays (point-min) (point-max) 'invisible
'diary
))
921 (kill-local-variable 'mode-line-format
))
923 (defvar original-date
) ; bound in diary-list-entries
924 ;(defvar number) ; already declared above
926 (defun diary-include-files (&optional mark
)
927 "Process diary entries from included diary files.
928 By default, lists included entries, but if optional argument MARK is non-nil
929 marks entries instead.
930 For example, this enables you to share common diary files.
931 Specify include files using lines matching `diary-include-string', e.g.
932 #include \"filename\"
933 This is recursive; that is, included files may include other files."
934 (goto-char (point-min))
935 (while (re-search-forward
936 (format "^%s \"\\([^\"]*\\)\"" (regexp-quote diary-include-string
))
938 (let ((diary-file (match-string-no-properties 1))
939 (diary-mark-entries-hook 'diary-mark-included-diary-files
)
940 (diary-list-entries-hook 'diary-include-other-diary-files
)
942 diary-hook diary-list-include-blanks efile
)
943 (if (file-exists-p diary-file
)
944 (if (file-readable-p diary-file
)
945 (if (member (setq efile
(expand-file-name diary-file
))
946 diary-included-files
)
947 (error "Recursive diary include for %s" diary-file
)
948 (setq diary-included-files
949 (append diary-included-files
(list efile
)))
952 (setq diary-entries-list
953 (append diary-entries-list
954 (diary-list-entries original-date number t
)))))
957 (format "Can't read included diary file %s\n" diary-file
)))
960 (format "Can't find included diary file %s\n" diary-file
)))))
961 (goto-char (point-min)))
963 (defun diary-include-other-diary-files ()
964 "Add diary entries from included diary files to `diary-entries-list'.
965 To use, add this function to `diary-list-entries-hook'.
966 For details, see `diary-include-files'.
967 See also `diary-mark-included-diary-files'."
968 (diary-include-files))
970 (define-obsolete-function-alias 'include-other-diary-files
971 'diary-include-other-diary-files
"23.1")
973 (defvar date-string
) ; bound in diary-list-entries
975 (defun diary-display-no-entries ()
976 "Common subroutine of `diary-simple-display' and `diary-fancy-display'.
977 Handles the case where there are no diary entries.
978 Returns a cons (NOENTRIES . HOLIDAY-STRING)."
979 (let* ((holiday-list (if diary-show-holidays-flag
980 (calendar-check-holidays original-date
)))
981 (hol-string (format "%s%s%s"
983 (if holiday-list
": " "")
984 (mapconcat 'identity holiday-list
"; ")))
985 (msg (format "No diary entries for %s" hol-string
))
986 ;; Empty list, or single item with no text.
987 ;; FIXME multiple items with no text?
988 (noentries (or (not diary-entries-list
)
989 (and (not (cdr diary-entries-list
))
990 (string-equal "" (cadr
991 (car diary-entries-list
)))))))
992 ;; Inconsistency: whether or not the holidays are displayed in a
993 ;; separate buffer depends on if there are diary entries.
995 (if (or (< (length msg
) (frame-width))
998 ;; holiday-list which is too wide for a message gets a buffer.
999 (calendar-in-read-only-buffer holiday-buffer
1000 (calendar-set-mode-line (format "Holidays for %s" date-string
))
1001 (insert (mapconcat 'identity holiday-list
"\n")))
1002 (message "No diary entries for %s" date-string
)))
1003 (cons noentries hol-string
)))
1006 (defvar diary-saved-point
) ; bound in diary-list-entries
1008 (defun diary-simple-display ()
1009 "Display the diary buffer if there are any relevant entries or holidays.
1010 Entries that do not apply are made invisible. Holidays are shown
1011 in the mode line. This is an option for `diary-display-function'."
1012 ;; If selected window is dedicated (to the calendar), need a new one
1013 ;; to display the diary.
1014 (let* ((pop-up-frames (or pop-up-frames
(window-dedicated-p)))
1015 (dbuff (find-buffer-visiting diary-file
))
1016 (empty (diary-display-no-entries)))
1017 ;; This may be too wide, but when simple diary is used there is
1018 ;; nowhere else for the holidays to go. Also, it is documented in
1019 ;; diary-show-holidays-flag that the holidays go in the mode-line.
1020 ;; FIXME however if there are no diary entries a separate buffer
1021 ;; is displayed - this is inconsistent.
1022 (with-current-buffer dbuff
1023 (calendar-set-mode-line (format "Diary for %s" (cdr empty
))))
1024 (unless (car empty
) ; no entries
1025 (with-current-buffer dbuff
1026 (let ((window (display-buffer (current-buffer))))
1027 ;; d-s-p is passed from diary-list-entries.
1028 (set-window-point window diary-saved-point
)
1029 (set-window-start window
(point-min)))))))
1031 (define-obsolete-function-alias 'simple-diary-display
1032 'diary-simple-display
"23.1")
1034 (defvar diary-goto-entry-function
'diary-goto-entry
1035 "Function called to jump to a diary entry.
1036 Modes that require special handling of the included file
1037 containing the diary entry can assign a suitable function to this
1040 (define-button-type 'diary-entry
1041 'action
(lambda (button) (funcall diary-goto-entry-function button
))
1042 'face
'diary-button
'help-echo
"Find this diary entry"
1045 (defun diary-goto-entry (button)
1046 "Jump to the diary entry for the BUTTON at point."
1047 (let* ((locator (button-get button
'locator
))
1048 (marker (car locator
))
1050 ;; If marker pointing to diary location is valid, use that.
1051 (if (and marker
(setq markbuf
(marker-buffer marker
)))
1053 (pop-to-buffer markbuf
)
1054 (goto-char (marker-position marker
)))
1055 ;; Marker is invalid (eg buffer has been killed).
1056 (or (and (setq file
(cadr locator
))
1057 (file-exists-p file
)
1058 (find-file-other-window file
)
1060 (when (eq major-mode
(default-value 'major-mode
)) (diary-mode))
1061 (goto-char (point-min))
1062 (if (re-search-forward (format "%s.*\\(%s\\)"
1063 (regexp-quote (nth 2 locator
))
1064 (regexp-quote (nth 3 locator
)))
1066 (goto-char (match-beginning 1)))))
1067 (message "Unable to locate this diary entry")))))
1069 (defun diary-fancy-display ()
1070 "Prepare a diary buffer with relevant entries in a fancy, noneditable form.
1071 Holidays are shown unless `diary-show-holidays-flag' is nil.
1072 Days with no diary entries are not shown (even if that day is a
1073 holiday), unless `diary-list-include-blanks' is non-nil.
1075 This is an option for `diary-display-function'."
1076 ;; Turn off selective-display in the diary file's buffer.
1077 (with-current-buffer (find-buffer-visiting diary-file
)
1078 (diary-unhide-everything))
1079 (unless (car (diary-display-no-entries)) ; no entries
1080 ;; Prepare the fancy diary buffer.
1081 (calendar-in-read-only-buffer diary-fancy-buffer
1082 (calendar-set-mode-line "Diary Entries")
1083 (let ((holiday-list-last-month 1)
1084 (holiday-list-last-year 1)
1087 (dolist (entry diary-entries-list
)
1088 (unless (calendar-date-equal date
(car entry
))
1089 (setq date
(car entry
))
1090 (and diary-show-holidays-flag
1091 (calendar-date-compare
1092 (list (list holiday-list-last-month
1093 (calendar-last-day-of-month
1094 holiday-list-last-month
1095 holiday-list-last-year
)
1096 holiday-list-last-year
))
1098 ;; We need to get the holidays for the next 3 months.
1099 (setq holiday-list-last-month
1100 (calendar-extract-month date
)
1101 holiday-list-last-year
1102 (calendar-extract-year date
))
1104 (calendar-increment-month
1105 holiday-list-last-month holiday-list-last-year
1)
1108 (let ((displayed-month holiday-list-last-month
)
1109 (displayed-year holiday-list-last-year
))
1110 (calendar-holiday-list)))
1111 (calendar-increment-month
1112 holiday-list-last-month holiday-list-last-year
1))
1114 date-holiday-list cc
)
1115 ;; Make a list of all holidays for date.
1116 (dolist (h holiday-list
)
1117 (if (calendar-date-equal date
(car h
))
1118 (setq date-holiday-list
(append date-holiday-list
1120 (insert (if (bobp) "" ?
\n) (calendar-date-string date
))
1121 (if date-holiday-list
(insert ": "))
1122 (setq cc
(current-column))
1123 (insert (mapconcat (lambda (x)
1124 (setq longest
(max longest
(length x
)))
1127 (concat "\n" (make-string cc ?\s
))))
1128 (insert ?
\n (make-string (+ cc longest
) ?
=) ?
\n)))
1129 (let ((this-entry (cadr entry
))
1130 this-loc marks temp-face
)
1131 (unless (zerop (length this-entry
))
1132 (if (setq this-loc
(nth 3 entry
))
1133 (insert-button this-entry
1134 ;; (MARKER FILENAME SPECIFIER LITERAL)
1135 'locator
(list (car this-loc
)
1138 (or (nth 2 this-loc
)
1141 (insert this-entry
))
1143 ;; Doesn't make sense to check font-lock-mode - see
1144 ;; comments above diary-entry-marker in calendar.el.
1145 (and ; font-lock-mode
1146 (setq marks
(nth 4 entry
))
1148 (setq temp-face
(calendar-make-temp-face marks
))
1149 (search-backward this-entry
)
1151 (make-overlay (match-beginning 0) (match-end 0))
1152 'face temp-face
)))))))
1153 ;; FIXME can't remember what this check was for.
1154 ;; To prevent something looping, or a minor optimization?
1155 (if (eq major-mode
'diary-fancy-display-mode
)
1156 (run-hooks 'diary-fancy-display-mode-hook
)
1157 (diary-fancy-display-mode))
1158 (calendar-set-mode-line date-string
))))
1160 (define-obsolete-function-alias 'fancy-diary-display
1161 'diary-fancy-display
"23.1")
1164 (defun diary-print-entries ()
1165 "Print a hard copy of the diary display.
1167 If the simple diary display is being used, prepare a temp buffer with the
1168 visible lines of the diary buffer, add a heading line composed from the mode
1169 line, print the temp buffer, and destroy it.
1171 If the fancy diary display is being used, just print the buffer.
1173 The hooks given by the variable `diary-print-entries-hook' are called to do
1174 the actual printing."
1176 (let ((diary-buffer (get-buffer diary-fancy-buffer
))
1177 temp-buffer heading start end
)
1179 (with-current-buffer diary-buffer
1180 (run-hooks 'diary-print-entries-hook
))
1181 (or (setq diary-buffer
(find-buffer-visiting diary-file
))
1182 (error "You don't have a diary buffer!"))
1183 ;; Name affects printing?
1184 (setq temp-buffer
(get-buffer-create " *Printable Diary Entries*"))
1185 (with-current-buffer diary-buffer
1187 (if (not (stringp mode-line-format
))
1189 (string-match "^-*\\([^-].*[^-]\\)-*$" mode-line-format
)
1190 (match-string 1 mode-line-format
))
1194 (setq end
(next-single-char-property-change start
'invisible
))
1195 (unless (get-char-property start
'invisible
)
1196 (with-current-buffer temp-buffer
1197 (insert-buffer-substring diary-buffer start end
)))
1199 (and end
(< end
(point-max))))))
1200 (set-buffer temp-buffer
)
1201 (goto-char (point-min))
1202 (insert heading
"\n"
1203 (make-string (length heading
) ?
=) "\n")
1204 (run-hooks 'diary-print-entries-hook
)
1205 (kill-buffer temp-buffer
))))
1207 (define-obsolete-function-alias 'print-diary-entries
1208 'diary-print-entries
"23.1")
1211 (defun diary-show-all-entries ()
1212 "Show all of the diary entries in the diary file.
1213 This function gets rid of the selective display of the diary file so that
1214 all entries, not just some, are visible. If there is no diary buffer, one
1217 (let* ((d-file (diary-check-diary-file))
1218 (pop-up-frames (or pop-up-frames
(window-dedicated-p)))
1219 (win (selected-window))
1220 (height (window-height)))
1221 (with-current-buffer (or (find-buffer-visiting d-file
)
1222 (find-file-noselect d-file t
))
1223 (when (eq major-mode
(default-value 'major-mode
)) (diary-mode))
1224 (diary-unhide-everything)
1225 (display-buffer (current-buffer))
1226 (when (and (/= height
(window-height win
))
1227 (with-current-buffer (window-buffer win
)
1228 (derived-mode-p 'calendar-mode
)))
1229 (fit-window-to-buffer win
)))))
1232 (defun diary-mail-entries (&optional ndays
)
1233 "Send a mail message showing diary entries for next NDAYS days.
1234 If no prefix argument is given, NDAYS is set to `diary-mail-days'.
1235 Mail is sent to the address specified by `diary-mail-addr'.
1237 Here is an example of a script to call `diary-mail-entries',
1238 suitable for regular scheduling using cron (or at). Note that
1239 since `emacs -script' does not load your init file, you should
1240 ensure that all relevant variables are set.
1242 #!/usr/bin/emacs -script
1243 ;; diary-rem.el - run the Emacs diary-reminder
1245 \(setq diary-mail-days 3
1246 diary-file \"/path/to/diary.file\"
1247 calendar-date-style 'european
1248 diary-mail-addr \"user@host.name\")
1250 \(diary-mail-entries)
1252 # diary-rem.el ends here
1255 (if (string-equal diary-mail-addr
"")
1256 (error "You must set `diary-mail-addr' to use this command")
1257 (let ((diary-display-function 'diary-fancy-display
))
1258 (diary-list-entries (calendar-current-date) (or ndays diary-mail-days
)))
1259 (compose-mail diary-mail-addr
1260 (concat "Diary entries generated "
1261 (calendar-date-string (calendar-current-date))))
1263 (if (get-buffer diary-fancy-buffer
)
1264 (with-current-buffer diary-fancy-buffer
(buffer-string))
1265 "No entries found"))
1266 (call-interactively (get mail-user-agent
'sendfunc
))))
1268 (defun diary-name-pattern (string-array &optional abbrev-array paren
)
1269 "Return a regexp matching the strings in the array STRING-ARRAY.
1270 If the optional argument ABBREV-ARRAY is present, the regexp
1271 also matches the supplied abbreviations, with or without final `.'
1272 characters. If the optional argument PAREN is non-nil, surrounds
1273 the regexp with parentheses."
1274 (regexp-opt (append string-array
1277 (mapcar (lambda (e) (format "%s." e
))
1282 (defvar diary-marking-entries-flag nil
1283 "True during the marking of diary entries, nil otherwise.")
1285 (defvar diary-marking-entry-flag nil
1286 "True during the marking of diary entries, if current entry is marking.")
1288 ;; file-glob-attrs bound in diary-mark-entries.
1289 (defun diary-mark-entries-1 (markfunc &optional months symbol absfunc
)
1290 "Mark diary entries of a certain type.
1291 MARKFUNC is a function that marks entries of the appropriate type
1292 matching a given date pattern. MONTHS is an array of month names.
1293 SYMBOL marks diary entries of the type in question. ABSFUNC is a
1294 function that converts absolute dates to dates of the appropriate type. "
1295 (let ((dayname (diary-name-pattern calendar-day-name-array
1296 calendar-day-abbrev-array
))
1297 (monthname (format "%s\\|\\*"
1299 (diary-name-pattern months
)
1300 (diary-name-pattern calendar-month-name-array
1301 calendar-month-abbrev-array
))))
1302 (month "[0-9]+\\|\\*")
1303 (day "[0-9]+\\|\\*")
1304 (year "[0-9]+\\|\\*")
1305 (case-fold-search t
)
1307 (dolist (date-form diary-date-forms
)
1308 (if (eq (car date-form
) 'backup
) ; ignore 'backup directive
1309 (setq date-form
(cdr date-form
)))
1310 (let* ((l (length date-form
))
1311 (d-name-pos (- l
(length (memq 'dayname date-form
))))
1312 (d-name-pos (if (/= l d-name-pos
) (1+ d-name-pos
)))
1313 (m-name-pos (- l
(length (memq 'monthname date-form
))))
1314 (m-name-pos (if (/= l m-name-pos
) (1+ m-name-pos
)))
1315 (d-pos (- l
(length (memq 'day date-form
))))
1316 (d-pos (if (/= l d-pos
) (1+ d-pos
)))
1317 (m-pos (- l
(length (memq 'month date-form
))))
1318 (m-pos (if (/= l m-pos
) (1+ m-pos
)))
1319 (y-pos (- l
(length (memq 'year date-form
))))
1320 (y-pos (if (/= l y-pos
) (1+ y-pos
)))
1321 (regexp (format "^%s\\(%s\\)"
1322 (if symbol
(regexp-quote symbol
) "")
1323 (mapconcat 'eval date-form
"\\)\\("))))
1324 (goto-char (point-min))
1325 (while (re-search-forward regexp nil t
)
1328 (match-string-no-properties d-name-pos
)))
1331 (match-string-no-properties m-name-pos
)))
1332 (mm (string-to-number
1334 (match-string-no-properties m-pos
)
1336 (dd (string-to-number
1338 (match-string-no-properties d-pos
)
1341 (match-string-no-properties y-pos
)))
1344 (if (and (= (length y-str
) 2)
1345 diary-abbreviated-year-flag
)
1347 (calendar-extract-year
1351 (calendar-absolute-from-gregorian
1352 (calendar-current-date)))
1353 (calendar-current-date))))
1354 (y (+ (string-to-number y-str
)
1355 ;; Current century, eg 2000.
1356 (* 100 (/ current-y
100))))
1357 (offset (- y current-y
)))
1358 ;; Add 2-digit year to current century.
1359 ;; If more than 50 years in the future,
1360 ;; assume last century. If more than 50
1361 ;; years in the past, assume next century.
1367 (string-to-number y-str
)))))
1368 (setq marks
(cadr (diary-pull-attrs
1369 (buffer-substring-no-properties
1370 (point) (line-end-position))
1372 ;; Only mark all days of a given name if the pattern
1373 ;; contains no more specific elements.
1374 (if (and dd-name
(not (or d-pos m-pos y-pos
)))
1375 (calendar-mark-days-named
1376 (cdr (assoc-string dd-name
1377 (calendar-make-alist
1378 calendar-day-name-array
1379 0 nil calendar-day-abbrev-array
1382 calendar-day-abbrev-array
))
1386 (if (string-equal mm-name
"*") 0
1389 (if months
(calendar-make-alist months
)
1390 (calendar-make-alist
1391 calendar-month-name-array
1392 1 nil calendar-month-abbrev-array
1395 calendar-month-abbrev-array
)))
1397 (funcall markfunc mm dd yy marks
))))))))
1400 (defun diary-mark-entries (&optional redraw
)
1401 "Mark days in the calendar window that have diary entries.
1402 Marks each entry in the diary that is visible in the calendar window.
1404 After marking the entries, runs `diary-nongregorian-marking-hook'
1405 for the main diary file, and each included file. For example,
1406 this is the appropriate hook to process Islamic entries in all
1407 diary files. Next `diary-mark-entries-hook' runs, for the main diary
1408 file only. If not using include files, there is no difference between
1411 If the optional argument REDRAW is non-nil (which is the case
1412 interactively, for example) then this first removes any existing diary
1413 marks. This is intended to deal with deleted diary entries."
1415 ;; To remove any deleted diary entries. Do not redraw when:
1416 ;; i) processing #include diary files (else only get the marks from
1417 ;; the last #include file processed).
1418 ;; ii) called via calendar-redraw (since calendar has already been
1420 ;; Use of REDRAW handles both of these cases.
1421 (when (and redraw calendar-mark-diary-entries-flag
)
1422 (setq calendar-mark-diary-entries-flag nil
)
1424 (let ((diary-marking-entries-flag t
)
1425 (diary-buffer (find-buffer-visiting diary-file
))
1426 ;; Dynamically bound in diary-include-files.
1427 (d-incp (and (boundp 'diary-including
) diary-including
))
1428 file-glob-attrs temp-buff
)
1430 (setq diary-included-files nil
)
1431 (message "Marking diary entries..."))
1433 (with-current-buffer (or diary-buffer
1435 (setq temp-buff
(generate-new-buffer
1438 (diary-check-diary-file) t
)))
1440 ;; If including, caller has already verified it is readable.
1441 (insert-file-contents diary-file
)
1442 (if (eq major-mode
(default-value 'major-mode
)) (diary-mode)))
1443 (setq calendar-mark-diary-entries-flag t
)
1444 (setq file-glob-attrs
(nth 1 (diary-pull-attrs nil
'())))
1445 (with-syntax-table diary-syntax-table
1447 (diary-mark-entries-1 'calendar-mark-date-pattern
)
1448 (diary-mark-sexp-entries)
1449 ;; Although it looks like mark-entries-hook runs every time,
1450 ;; diary-mark-included-diary-files binds it to nil
1451 ;; (essentially) when it runs in included files.
1452 (run-hooks 'diary-nongregorian-marking-hook
1453 'diary-mark-entries-hook
))))
1454 (and temp-buff
(buffer-name temp-buff
) (kill-buffer temp-buff
)))
1455 (or d-incp
(message "Marking diary entries...done"))))
1458 (define-obsolete-function-alias 'mark-diary-entries
'diary-mark-entries
"23.1")
1460 (defun diary-sexp-entry (sexp entry date
)
1461 "Process a SEXP diary ENTRY for DATE."
1462 (let ((result (if calendar-debug-sexp
1463 (let ((debug-on-error t
))
1464 (eval (car (read-from-string sexp
))))
1467 (eval (car (read-from-string sexp
)))
1471 (format "Bad diary sexp at line %d in %s:\n%s\n\
1473 (count-lines (point-min) (point))
1474 diary-file sexp err
))
1476 (cond ((stringp result
) result
)
1477 ((and (consp result
)
1478 (stringp (cdr result
))) result
)
1482 (defvar displayed-year
) ; bound in calendar-generate
1483 (defvar displayed-month
)
1485 (defun diary-mark-sexp-entries ()
1486 "Mark days in the calendar window that have sexp diary entries.
1487 Each entry in the diary file (or included files) visible in the calendar window
1488 is marked. See the documentation for the function `diary-list-sexp-entries'."
1489 (let* ((sexp-mark (regexp-quote diary-sexp-entry-symbol
))
1490 (s-entry (format "^\\(%s(\\)\\|\\(%s%s(diary-remind\\)" sexp-mark
1491 (regexp-quote diary-nonmarking-symbol
)
1493 (file-glob-attrs (nth 1 (diary-pull-attrs nil
'())))
1494 m y first-date last-date date mark file-glob-attrs
1495 sexp-start sexp entry entry-start
)
1496 (with-current-buffer calendar-buffer
1497 (setq m displayed-month
1499 (calendar-increment-month m y -
1)
1500 (setq first-date
(calendar-absolute-from-gregorian (list m
1 y
)))
1501 (calendar-increment-month m y
2)
1503 (calendar-absolute-from-gregorian
1504 (list m
(calendar-last-day-of-month m y
) y
)))
1505 (goto-char (point-min))
1506 (while (re-search-forward s-entry nil t
)
1507 (setq diary-marking-entry-flag
(char-equal (preceding-char) ?\
())
1508 (re-search-backward "(")
1509 (setq sexp-start
(point))
1511 (setq sexp
(buffer-substring-no-properties sexp-start
(point)))
1513 (if (and (bolp) (not (looking-at "[ \t]")))
1514 ;; Diary entry consists only of the sexp.
1518 (setq entry-start
(point))
1519 ;; Find end of entry.
1521 (while (looking-at "[ \t]")
1523 (if (bolp) (backward-char 1))
1524 (setq entry
(buffer-substring-no-properties entry-start
(point))))
1525 (setq date
(1- first-date
))
1526 ;; FIXME this loops over all visible dates.
1527 ;; Could be optimized in many cases. Depends on whether t or * present.
1528 (while (<= (setq date
(1+ date
)) last-date
)
1529 (when (setq mark
(diary-sexp-entry
1531 (calendar-gregorian-from-absolute date
)))
1532 (calendar-mark-visible-date
1533 (calendar-gregorian-from-absolute date
)
1534 (or (cadr (diary-pull-attrs entry file-glob-attrs
))
1535 (if (consp mark
) (car mark
)))))))))
1537 (define-obsolete-function-alias 'mark-sexp-diary-entries
1538 'diary-mark-sexp-entries
"23.1")
1540 (defun diary-mark-included-diary-files ()
1541 "Mark diary entries from included diary files.
1542 To use, add this function to `diary-mark-entries-hook'.
1543 For details, see `diary-include-files'.
1544 See also `diary-include-other-diary-files'."
1545 (diary-include-files t
))
1547 (define-obsolete-function-alias 'mark-included-diary-files
1548 'diary-mark-included-diary-files
"23.1")
1550 (defun calendar-mark-days-named (dayname &optional color
)
1551 "Mark all dates in the calendar window that are day DAYNAME of the week.
1552 0 means all Sundays, 1 means all Mondays, and so on.
1553 Optional argument COLOR is passed to `calendar-mark-visible-date' as MARK."
1554 (with-current-buffer calendar-buffer
1555 (let ((prev-month displayed-month
)
1556 (prev-year displayed-year
)
1557 (succ-month displayed-month
)
1558 (succ-year displayed-year
)
1561 (calendar-increment-month succ-month succ-year
1)
1562 (calendar-increment-month prev-month prev-year -
1)
1563 (setq day
(calendar-absolute-from-gregorian
1564 (calendar-nth-named-day 1 dayname prev-month prev-year
))
1565 last-day
(calendar-absolute-from-gregorian
1566 (calendar-nth-named-day -
1 dayname succ-month succ-year
)))
1567 (while (<= day last-day
)
1568 (calendar-mark-visible-date (calendar-gregorian-from-absolute day
)
1570 (setq day
(+ day
7))))))
1572 (define-obsolete-function-alias 'mark-calendar-days-named
1573 'calendar-mark-days-named
"23.1")
1575 (defun calendar-mark-month (month year p-month p-day p-year
&optional color
)
1576 "Mark dates in the MONTH/YEAR that conform to pattern P-MONTH/P-DAY/P-YEAR.
1577 A value of 0 in any position of the pattern is a wildcard.
1578 Optional argument COLOR is passed to `calendar-mark-visible-date' as MARK."
1579 (if (or (and (= month p-month
)
1580 (or (zerop p-year
) (= year p-year
)))
1581 (and (zerop p-month
)
1582 (or (zerop p-year
) (= year p-year
))))
1584 (dotimes (i (calendar-last-day-of-month month year
))
1585 (calendar-mark-visible-date (list month
(1+ i
) year
) color
))
1586 (calendar-mark-visible-date (list month p-day year
) color
))))
1588 (define-obsolete-function-alias 'mark-calendar-month
1589 'calendar-mark-month
"23.1")
1591 (defun calendar-mark-date-pattern (month day year
&optional color
)
1592 "Mark all dates in the calendar window that conform to MONTH/DAY/YEAR.
1593 A value of 0 in any position is a wildcard. Optional argument COLOR is
1594 passed to `calendar-mark-visible-date' as MARK."
1595 (with-current-buffer calendar-buffer
1596 (let ((m displayed-month
)
1598 (calendar-increment-month m y -
1)
1599 (dotimes (_idummy 3)
1600 (calendar-mark-month m y month day year color
)
1601 (calendar-increment-month m y
1)))))
1603 (define-obsolete-function-alias 'mark-calendar-date-pattern
1604 'calendar-mark-date-pattern
"23.1")
1606 ;; Bahai, Hebrew, Islamic.
1607 (defun calendar-mark-complex (month day year fromabs
&optional color
)
1608 "Mark dates in the calendar conforming to MONTH DAY YEAR of some system.
1609 The function FROMABS converts absolute dates to the appropriate date system.
1610 Optional argument COLOR is passed to `calendar-mark-visible-date' as MARK."
1611 ;; Not one of the simple cases--check all visible dates for match.
1612 ;; Actually, the following code takes care of ALL of the cases, but
1613 ;; it's much too slow to be used for the simple (common) cases.
1614 (let* ((m displayed-month
)
1617 (calendar-increment-month m y -
1)
1618 (calendar-absolute-from-gregorian (list m
1 y
))))
1620 (calendar-increment-month m y
2)
1621 (calendar-absolute-from-gregorian
1622 (list m
(calendar-last-day-of-month m y
) y
))))
1623 (date (1- first-date
))
1625 (while (<= (setq date
(1+ date
)) last-date
)
1626 (setq local-date
(funcall fromabs date
))
1627 (and (or (zerop month
)
1628 (= month
(calendar-extract-month local-date
)))
1630 (= day
(calendar-extract-day local-date
)))
1632 (= year
(calendar-extract-year local-date
)))
1633 (calendar-mark-visible-date
1634 (calendar-gregorian-from-absolute date
) color
)))))
1637 (defun calendar-mark-1 (month day year fromabs toabs
&optional color
)
1638 "Mark dates in the calendar conforming to MONTH DAY YEAR of some system.
1639 The function FROMABS converts absolute dates to the appropriate date system.
1640 The function TOABS carries out the inverse operation. Optional argument
1641 COLOR is passed to `calendar-mark-visible-date' as MARK."
1642 (with-current-buffer calendar-buffer
1643 (if (and (not (zerop month
)) (not (zerop day
)))
1644 (if (not (zerop year
))
1645 ;; Fully specified date.
1646 (let ((date (calendar-gregorian-from-absolute
1647 (funcall toabs
(list month day year
)))))
1648 (if (calendar-date-is-visible-p date
)
1649 (calendar-mark-visible-date date color
)))
1650 ;; Month and day in any year--this taken from the holiday stuff.
1651 (let* ((i-date (funcall fromabs
1652 (calendar-absolute-from-gregorian
1653 (list displayed-month
15 displayed-year
))))
1654 (m (calendar-extract-month i-date
))
1655 (y (calendar-extract-year i-date
))
1657 (unless (< m
1) ; calendar doesn't apply
1658 (calendar-increment-month m y
(- 10 month
))
1659 (and (> m
7) ; date might be visible
1660 (calendar-date-is-visible-p
1661 (setq date
(calendar-gregorian-from-absolute
1662 (funcall toabs
(list month day y
)))))
1663 (calendar-mark-visible-date date color
)))))
1664 (calendar-mark-complex month day year
1665 'calendar-bahai-from-absolute color
))))
1668 (defun diary-entry-time (s)
1669 "Return time at the beginning of the string S as a military-style integer.
1670 For example, returns 1325 for 1:25pm.
1672 Returns `diary-unknown-time' (default value -9999) if no time is recognized.
1673 The recognized forms are XXXX, X:XX, or XX:XX (military time), and XXam,
1674 XXAM, XXpm, XXPM, XX:XXam, XX:XXAM, XX:XXpm, or XX:XXPM. A period (.) can
1675 be used instead of a colon (:) to separate the hour and minute parts."
1676 (let (case-fold-search)
1677 (cond ((string-match ; military time
1678 "\\`[ \t\n]*\\([0-9]?[0-9]\\)[:.]?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)"
1680 (+ (* 100 (string-to-number (match-string 1 s
)))
1681 (string-to-number (match-string 2 s
))))
1682 ((string-match ; hour only (XXam or XXpm)
1683 "\\`[ \t\n]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s
)
1684 (+ (* 100 (%
(string-to-number (match-string 1 s
)) 12))
1685 (if (equal ?a
(downcase (aref s
(match-beginning 2))))
1687 ((string-match ; hour and minute (XX:XXam or XX:XXpm)
1688 "\\`[ \t\n]*\\([0-9]?[0-9]\\)[:.]\\([0-9][0-9]\\)\\([ap]\\)m\\>" s
)
1689 (+ (* 100 (%
(string-to-number (match-string 1 s
)) 12))
1690 (string-to-number (match-string 2 s
))
1691 (if (equal ?a
(downcase (aref s
(match-beginning 3))))
1693 (t diary-unknown-time
)))) ; unrecognizable
1695 (defun diary-entry-compare (e1 e2
)
1696 "Return t if E1 is earlier than E2."
1697 (or (calendar-date-compare e1 e2
)
1698 (and (calendar-date-equal (car e1
) (car e2
))
1699 (let* ((ts1 (cadr e1
)) (t1 (diary-entry-time ts1
))
1700 (ts2 (cadr e2
)) (t2 (diary-entry-time ts2
)))
1703 (string-lessp ts1 ts2
)))))))
1705 (defun diary-sort-entries ()
1706 "Sort the list of diary entries by time of day.
1707 If you add this function to `diary-list-entries-hook', it should
1708 be the last item in the hook, in case earlier items add diary
1709 entries, or change the order."
1710 (setq diary-entries-list
(sort diary-entries-list
'diary-entry-compare
)))
1712 (define-obsolete-function-alias 'sort-diary-entries
'diary-sort-entries
"23.1")
1715 (defun diary-list-sexp-entries (date)
1716 "Add sexp entries for DATE from the diary file to `diary-entries-list'.
1717 Also, make them visible in the diary. Returns t if any entries are found.
1719 Sexp diary entries must be prefaced by a `diary-sexp-entry-symbol'
1720 \(normally `%%'). The form of a sexp diary entry is
1724 Both ENTRY and DATE are available when the SEXP is evaluated. If
1725 the SEXP returns nil, the diary entry does not apply. If it
1726 returns a non-nil value, ENTRY will be taken to apply to DATE; if
1727 the value is a string, that string will be the diary entry in the
1728 fancy diary display.
1730 For example, the following diary entry will apply to the 21st of
1731 the month if it is a weekday and the Friday before if the 21st is
1734 &%%(let ((dayname (calendar-day-of-week date))
1735 (day (calendar-extract-day date)))
1737 (and (= day 21) (memq dayname '(1 2 3 4 5)))
1738 (and (memq day '(19 20)) (= dayname 5)))
1739 ) UIUC pay checks deposited
1741 A number of built-in functions are available for this type of
1742 diary entry. In the following, the optional parameter MARK
1743 specifies a face or single-character string to use when
1744 highlighting the day in the calendar. For those functions that
1745 take MONTH, DAY, and YEAR as arguments, the order of the input
1746 parameters changes according to `calendar-date-style' (e.g. to
1747 DAY MONTH YEAR in the European style).
1749 %%(diary-date MONTH DAY YEAR &optional MARK) text
1750 Entry applies if date is MONTH, DAY, YEAR. DAY, MONTH, and YEAR can
1751 be a list of integers, `t' (meaning all values), or an integer.
1753 %%(diary-float MONTH DAYNAME N &optional DAY MARK) text
1754 Entry will appear on the Nth DAYNAME after/before MONTH DAY.
1755 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
1756 If N>0, use the Nth DAYNAME after MONTH DAY.
1757 If N<0, use the Nth DAYNAME before MONTH DAY.
1758 DAY defaults to 1 if N>0, and MONTH's last day otherwise.
1759 MONTH can be a list of months, a single month, or `t' to
1762 %%(diary-block M1 D1 Y1 M2 D2 Y2 &optional MARK) text
1763 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2,
1766 %%(diary-anniversary MONTH DAY YEAR &optional MARK) text
1767 Entry will appear on anniversary dates of MONTH DAY, YEAR.
1768 Text can contain `%d' or `%d%s'; `%d' will be replaced by the
1769 number of years since the MONTH DAY, YEAR, and `%s' by the
1770 ordinal ending of that number (i.e. `st', `nd', `rd' or `th',
1771 as appropriate). The anniversary of February 29 is
1772 considered to be March 1 in a non-leap year.
1774 %%(diary-cyclic N MONTH DAY YEAR &optional MARK) text
1775 Entry will appear every N days, starting MONTH DAY, YEAR.
1776 Text can contain `%d' or `%d%s'; `%d' will be replaced by the
1777 number of repetitions since the MONTH DAY, YEAR and `%s' by
1778 the ordinal ending of that number (i.e. `st', `nd', `rd' or
1779 `th', as appropriate).
1781 %%(diary-remind SEXP DAYS &optional MARKING) text
1782 Entry is a reminder for diary sexp SEXP. DAYS is either a
1783 single number or a list of numbers indicating the number(s)
1784 of days before the event that the warning(s) should occur.
1785 A negative number -DAYS has the same meaning as a list (1 2 ... DAYS).
1786 If the current date is (one of) DAYS before the event indicated
1787 by EXPR, then a suitable message (as specified by
1788 `diary-remind-message') appears. In addition to the
1789 reminders beforehand, the diary entry also appears on the
1790 date itself. If optional MARKING is non-nil then the
1791 *reminders* are marked on the calendar. Marking of reminders
1792 is independent of whether the entry *itself* is a marking or
1795 %%(diary-hebrew-yahrzeit MONTH DAY YEAR) text
1796 Text is assumed to be the name of the person; the date is the
1797 date of death on the *civil* calendar. The diary entry will
1798 appear on the proper Hebrew-date anniversary and on the day
1801 All the remaining functions do not accept any text, and so only
1802 make sense with `diary-fancy-display'. Most produce output every day.
1804 `diary-day-of-year' - day of year and number of days remaining
1805 `diary-iso-date' - ISO commercial date
1806 `diary-astro-day-number' - astronomical (Julian) day number
1807 `diary-sunrise-sunset' - local times of sunrise and sunset
1809 These functions give the date in alternative calendrical systems:
1811 `diary-bahai-date', `diary-chinese-date', `diary-coptic-date',
1812 `diary-ethiopic-date', `diary-french-date', `diary-hebrew-date',
1813 `diary-islamic-date', `diary-julian-date', `diary-mayan-date',
1814 `diary-persian-date'
1816 Theses functions only produce output on certain dates:
1818 `diary-lunar-phases' - phases of moon (on the appropriate days)
1819 `diary-hebrew-omer' - Omer count, within 50 days after Passover
1820 `diary-hebrew-parasha' - weekly parasha, every Saturday
1821 `diary-hebrew-rosh-hodesh' - Rosh Hodesh, or the day or Saturday before
1822 `diary-hebrew-sabbath-candles' - local time of candle lighting, on Fridays
1825 Marking these entries is *extremely* time consuming, so it is
1826 best if they are non-marking."
1827 (let ((s-entry (format "^%s?%s(" (regexp-quote diary-nonmarking-symbol
)
1828 (regexp-quote diary-sexp-entry-symbol
)))
1829 entry-found file-glob-attrs marks
1830 sexp-start sexp entry specifier entry-start line-start
1831 diary-entry temp literal
)
1832 (goto-char (point-min))
1833 (setq file-glob-attrs
(nth 1 (diary-pull-attrs nil
'())))
1834 (while (re-search-forward s-entry nil t
)
1836 (setq sexp-start
(point))
1838 (setq sexp
(buffer-substring-no-properties sexp-start
(point))
1839 line-start
(line-end-position 0)
1841 (buffer-substring-no-properties (1+ line-start
) (point))
1842 entry-start
(1+ line-start
))
1844 (if (and (bolp) (not (looking-at "[ \t]")))
1845 ;; Diary entry consists only of the sexp.
1849 (setq entry-start
(point))
1851 (while (looking-at "[ \t]")
1853 (if (bolp) (backward-char 1))
1854 (setq entry
(buffer-substring-no-properties entry-start
(point))))
1855 (setq diary-entry
(diary-sexp-entry sexp entry date
)
1856 literal entry
; before evaluation
1857 entry
(if (consp diary-entry
)
1861 (remove-overlays line-start
(point) 'invisible
'diary
)
1862 (if (< 0 (length entry
))
1863 (setq temp
(diary-pull-attrs entry file-glob-attrs
)
1865 marks
(nth 1 temp
))))
1866 (diary-add-to-list date entry specifier
1867 (if entry-start
(copy-marker entry-start
))
1869 (setq entry-found
(or entry-found diary-entry
)))
1872 (define-obsolete-function-alias 'list-sexp-diary-entries
1873 'diary-list-sexp-entries
"23.1")
1875 (defun diary-make-date (a b c
)
1876 "Convert A B C into the internal calendar date form.
1877 The expected order of the inputs depends on `calendar-date-style',
1878 e.g. in the European case, A = day, B = month, C = year. Returns
1879 a list (MONTH DAY YEAR), i.e. the American style, which is the
1880 form used internally by the calendar and diary."
1881 (cond ((eq calendar-date-style
'iso
) ; YMD
1883 ((eq calendar-date-style
'european
) ; DMY
1888 ;;; Sexp diary functions.
1893 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
1894 (defun diary-date (month day year
&optional mark
)
1895 "Specific date(s) diary entry.
1896 Entry applies if date is MONTH, DAY, YEAR. Each parameter can be a
1897 list of integers, `t' (meaning all values), or an integer. The order
1898 of the input parameters changes according to `calendar-date-style'
1899 \(e.g. to DAY MONTH YEAR in the European style).
1901 An optional parameter MARK specifies a face or single-character string
1902 to use when highlighting the day in the calendar."
1903 (let* ((ddate (diary-make-date month day year
))
1904 (dd (calendar-extract-day ddate
))
1905 (mm (calendar-extract-month ddate
))
1906 (yy (calendar-extract-year ddate
))
1907 (m (calendar-extract-month date
))
1908 (y (calendar-extract-year date
))
1909 (d (calendar-extract-day date
)))
1911 (or (and (listp dd
) (memq d dd
))
1914 (or (and (listp mm
) (memq m mm
))
1917 (or (and (listp yy
) (memq y yy
))
1920 (cons mark entry
))))
1922 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
1923 (defun diary-block (m1 d1 y1 m2 d2 y2
&optional mark
)
1925 Entry applies if date is between, or on one of, two dates. The order
1926 of the input parameters changes according to `calendar-date-style'
1927 \(e.g. to D1, M1, Y1, D2, M2, Y2 in the European style).
1929 An optional parameter MARK specifies a face or single-character string
1930 to use when highlighting the day in the calendar."
1931 (let ((date1 (calendar-absolute-from-gregorian
1932 (diary-make-date m1 d1 y1
)))
1933 (date2 (calendar-absolute-from-gregorian
1934 (diary-make-date m2 d2 y2
)))
1935 (d (calendar-absolute-from-gregorian date
)))
1936 (and (<= date1 d
) (<= d date2
)
1937 (cons mark entry
))))
1939 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
1940 (defun diary-float (month dayname n
&optional day mark
)
1941 "Diary entry for the Nth DAYNAME after/before MONTH DAY.
1942 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
1943 If N>0, use the Nth DAYNAME after MONTH DAY.
1944 If N<0, use the Nth DAYNAME before MONTH DAY.
1945 DAY defaults to 1 if N>0, and MONTH's last day otherwise.
1946 MONTH can be a list of months, an integer, or `t' (meaning all months).
1947 Optional MARK specifies a face or single-character string to use when
1948 highlighting the day in the calendar."
1949 ;; This is messy because the diary entry may apply, but the date on which it
1950 ;; is based can be in a different month/year. For example, asking for the
1951 ;; first Monday after December 30. For large values of |n| the problem is
1953 (and (= dayname
(calendar-day-of-week date
))
1954 (let* ((m (calendar-extract-month date
))
1955 (d (calendar-extract-day date
))
1956 (y (calendar-extract-year date
))
1957 ;; Last (n>0) or first (n<0) possible base date for entry.
1959 (calendar-nth-named-absday (- n
) dayname m y d
))
1960 (last-abs (if (> n
0) limit
(+ limit
6)))
1961 (first-abs (if (> n
0) (- limit
6) limit
))
1962 (last (calendar-gregorian-from-absolute last-abs
))
1963 (first (calendar-gregorian-from-absolute first-abs
))
1964 ;; m1, d1 is first possible base date.
1965 (m1 (calendar-extract-month first
))
1966 (d1 (calendar-extract-day first
))
1967 (y1 (calendar-extract-year first
))
1968 ;; m2, d2 is last possible base date.
1969 (m2 (calendar-extract-month last
))
1970 (d2 (calendar-extract-day last
))
1971 (y2 (calendar-extract-year last
)))
1972 (if (or (and (= m1 m2
) ; only possible base dates in one month
1977 (let ((d (or day
(if (> n
0)
1979 (calendar-last-day-of-month m1 y1
)))))
1980 (and (<= d1 d
) (<= d d2
))))
1981 ;; Only possible base dates straddle two months.
1983 (and (= y1 y2
) (< m1 m2
)))
1985 ;; m1, d1 works as a base date.
1991 (<= d1
(or day
(if (> n
0)
1993 (calendar-last-day-of-month m1 y1
)))))
1994 ;; m2, d2 works as a base date.
1995 (and (or (eq month t
)
1999 (<= (or day
(if (> n
0)
2001 (calendar-last-day-of-month m2 y2
)))
2003 (cons mark entry
)))))
2005 (defun diary-ordinal-suffix (n)
2006 "Ordinal suffix for N. (That is, `st', `nd', `rd', or `th', as appropriate.)"
2007 (if (or (memq (% n
100) '(11 12 13))
2010 (aref ["th" "st" "nd" "rd"] (% n
10))))
2012 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
2013 (defun diary-anniversary (month day
&optional year mark
)
2014 "Anniversary diary entry.
2015 Entry applies if date is the anniversary of MONTH, DAY, YEAR.
2016 The order of the input parameters changes according to
2017 `calendar-date-style' (e.g. to DAY MONTH YEAR in the European style).
2019 The diary entry can contain `%d' or `%d%s'; the %d will be replaced
2020 by the number of years since the MONTH, DAY, YEAR, and the %s will
2021 be replaced by the ordinal ending of that number (that is, `st',
2022 `nd', `rd' or `th', as appropriate). The anniversary of February 29
2023 is considered to be March 1 in non-leap years.
2025 An optional parameter MARK specifies a face or single-character
2026 string to use when highlighting the day in the calendar."
2027 (let* ((ddate (diary-make-date month day year
))
2028 (dd (calendar-extract-day ddate
))
2029 (mm (calendar-extract-month ddate
))
2030 (yy (calendar-extract-year ddate
))
2031 (y (calendar-extract-year date
))
2032 (diff (if yy
(- y yy
) 100)))
2033 (and (= mm
2) (= dd
29) (not (calendar-leap-year-p y
))
2036 (and (> diff
0) (calendar-date-equal (list mm dd y
) date
)
2037 (cons mark
(format entry diff
(diary-ordinal-suffix diff
))))))
2039 ;; To be called from diary-sexp-entry, where DATE, ENTRY are bound.
2040 (defun diary-cyclic (n month day year
&optional mark
)
2041 "Cycle diary entry--entry applies every N days starting at MONTH, DAY, YEAR.
2042 The order of the input parameters changes according to
2043 `calendar-date-style' (e.g. to N DAY MONTH YEAR in the European
2044 style). The entry can contain `%d' or `%d%s'; the %d will be
2045 replaced by the number of repetitions since the MONTH DAY YEAR,
2046 and %s by the ordinal ending of that number (that is, `st', `nd',
2047 `rd' or `th', as appropriate).
2049 An optional parameter MARK specifies a face or single-character
2050 string to use when highlighting the day in the calendar."
2052 (error "Day count must be positive"))
2053 (let* ((diff (- (calendar-absolute-from-gregorian date
)
2054 (calendar-absolute-from-gregorian
2055 (diary-make-date month day year
))))
2057 (and (>= diff
0) (zerop (% diff n
))
2058 (cons mark
(format entry cycle
(diary-ordinal-suffix cycle
))))))
2060 (defun diary-day-of-year ()
2061 "Day of year and number of days remaining in the year of date diary entry."
2062 (calendar-day-of-year-string date
))
2064 (defun diary-remind (sexp days
&optional marking
)
2065 "Provide a reminder of a diary entry.
2066 SEXP is a diary-sexp. DAYS is either a single number or a list
2067 of numbers indicating the number(s) of days before the event that
2068 the warning(s) should occur on. A negative number -DAYS has the
2069 same meaning as a list (1 2 ... DAYS). If the current date
2070 is (one of) DAYS before the event indicated by SEXP, then this function
2071 returns a suitable message (as specified by `diary-remind-message').
2073 In addition to the reminders beforehand, the diary entry also
2074 appears on the date itself.
2076 A `diary-nonmarking-symbol' at the beginning of the line of the
2077 `diary-remind' entry specifies that the diary entry (not the
2078 reminder) is non-marking. Marking of reminders is independent of
2079 whether the entry itself is a marking or nonmarking; if optional
2080 parameter MARKING is non-nil then the reminders are marked on the
2082 ;; `date' has a value at this point, from diary-sexp-entry.
2083 ;; Convert a negative number to a list of days.
2084 (and (integerp days
)
2086 (setq days
(number-sequence 1 (- days
))))
2087 (let ((diary-entry (eval sexp
)))
2089 ;; Diary entry applies on date.
2091 (or (not diary-marking-entries-flag
) diary-marking-entry-flag
))
2093 ;; Diary entry may apply to `days' before date.
2094 ((and (integerp days
)
2095 (not diary-entry
) ; diary entry does not apply to date
2096 (or (not diary-marking-entries-flag
) marking
))
2097 ;; Adjust date, and re-evaluate.
2098 (let ((date (calendar-gregorian-from-absolute
2099 (+ (calendar-absolute-from-gregorian date
) days
))))
2100 (when (setq diary-entry
(eval sexp
))
2101 ;; Discard any mark portion from diary-anniversary, etc.
2102 (if (consp diary-entry
) (setq diary-entry
(cdr diary-entry
)))
2103 (mapconcat 'eval diary-remind-message
""))))
2104 ;; Diary entry may apply to one of a list of days before date.
2105 ((and (listp days
) days
)
2106 (or (diary-remind sexp
(car days
) marking
)
2107 (diary-remind sexp
(cdr days
) marking
))))))
2110 ;;; Diary insertion functions.
2113 (defun diary-make-entry (string &optional nonmarking file
)
2114 "Insert a diary entry STRING which may be NONMARKING in FILE.
2115 If omitted, NONMARKING defaults to nil and FILE defaults to
2117 (let ((pop-up-frames (or pop-up-frames
(window-dedicated-p))))
2118 (find-file-other-window (or file diary-file
)))
2119 (when (eq major-mode
(default-value 'major-mode
)) (diary-mode))
2121 (diary-unhide-everything)
2122 (goto-char (point-max))
2123 (when (let ((case-fold-search t
))
2124 (search-backward "Local Variables:"
2125 (max (- (point-max) 3000) (point-min))
2132 (if nonmarking diary-nonmarking-symbol
"")
2136 (define-obsolete-function-alias 'make-diary-entry
'diary-make-entry
"23.1")
2139 (defun diary-insert-entry (arg &optional event
)
2140 "Insert a diary entry for the date indicated by point.
2141 Prefix argument ARG makes the entry nonmarking."
2143 (list current-prefix-arg last-nonmenu-event
))
2144 (diary-make-entry (calendar-date-string (calendar-cursor-to-date t event
) t t
)
2148 (define-obsolete-function-alias 'insert-diary-entry
'diary-insert-entry
"23.1")
2151 (defun diary-insert-weekly-entry (arg)
2152 "Insert a weekly diary entry for the day of the week indicated by point.
2153 Prefix argument ARG makes the entry nonmarking."
2155 (diary-make-entry (calendar-day-name (calendar-cursor-to-date t
))
2159 (define-obsolete-function-alias 'insert-weekly-diary-entry
2160 'diary-insert-weekly-entry
"23.1")
2162 (defun diary-date-display-form (&optional type
)
2163 "Return value for `calendar-date-display-form' using `calendar-date-style'.
2164 Optional symbol TYPE is either `monthly' or `yearly'."
2165 (cond ((eq type
'monthly
) (cond ((eq calendar-date-style
'iso
)
2166 '((format "*-*-%.2d"
2167 (string-to-number day
))))
2168 ((eq calendar-date-style
'european
)
2171 ((eq type
'yearly
) (cond ((eq calendar-date-style
'iso
)
2172 '((format "*-%.2d-%.2d"
2173 (string-to-number month
)
2174 (string-to-number day
))))
2175 ((eq calendar-date-style
'european
)
2176 '(day " " monthname
))
2177 (t '(monthname " " day
))))
2178 ;; Iso cannot contain "-", because this form used eg by
2179 ;; diary-insert-anniversary-entry.
2180 (t (cond ((eq calendar-date-style
'iso
)
2181 '((format "%s %.2d %.2d" year
2182 (string-to-number month
) (string-to-number day
))))
2183 ((eq calendar-date-style
'european
)
2184 '(day " " month
" " year
))
2185 (t '(month " " day
" " year
))))))
2187 (defun diary-insert-entry-1 (&optional type nomark months symbol absfunc
)
2188 "Subroutine to insert a diary entry related to the date at point.
2189 TYPE is the type of entry (`monthly' or `yearly'). NOMARK non-nil
2190 means make the entry non-marking. Array MONTHS is used in place
2191 of `calendar-month-name-array'. String SYMBOL marks the type of
2192 diary entry. Function ABSFUNC converts absolute dates to dates of
2193 the appropriate type."
2194 (let ((calendar-date-display-form (if type
2195 (diary-date-display-form type
)
2196 calendar-date-display-form
))
2197 (calendar-month-name-array (or months calendar-month-name-array
))
2198 (date (calendar-cursor-to-date t
)))
2200 (format "%s%s" (or symbol
"")
2201 (calendar-date-string
2203 (funcall absfunc
(calendar-absolute-from-gregorian date
))
2210 (defun diary-insert-monthly-entry (arg)
2211 "Insert a monthly diary entry for the day of the month indicated by point.
2212 Prefix argument ARG makes the entry nonmarking."
2214 (diary-insert-entry-1 'monthly arg
))
2217 (define-obsolete-function-alias 'insert-monthly-diary-entry
2218 'diary-insert-monthly-entry
"23.1")
2221 (defun diary-insert-yearly-entry (arg)
2222 "Insert an annual diary entry for the day of the year indicated by point.
2223 Prefix argument ARG makes the entry nonmarking."
2225 (diary-insert-entry-1 'yearly arg
))
2228 (define-obsolete-function-alias 'insert-yearly-diary-entry
2229 'diary-insert-yearly-entry
"23.1")
2232 (defun diary-insert-anniversary-entry (arg)
2233 "Insert an anniversary diary entry for the date given by point.
2234 Prefix argument ARG makes the entry nonmarking."
2236 (let ((calendar-date-display-form (diary-date-display-form)))
2238 (format "%s(diary-anniversary %s)"
2239 diary-sexp-entry-symbol
2240 (calendar-date-string (calendar-cursor-to-date t
) nil t
))
2244 (define-obsolete-function-alias 'insert-anniversary-diary-entry
2245 'diary-insert-anniversary-entry
"23.1")
2248 (defun diary-insert-block-entry (arg)
2249 "Insert a block diary entry for the days between the point and marked date.
2250 Prefix argument ARG makes the entry nonmarking."
2252 (let ((calendar-date-display-form (diary-date-display-form))
2253 (cursor (calendar-cursor-to-date t
))
2254 (mark (or (car calendar-mark-ring
)
2255 (error "No mark set in this buffer")))
2257 (if (< (calendar-absolute-from-gregorian mark
)
2258 (calendar-absolute-from-gregorian cursor
))
2264 (format "%s(diary-block %s %s)"
2265 diary-sexp-entry-symbol
2266 (calendar-date-string start nil t
)
2267 (calendar-date-string end nil t
))
2271 (define-obsolete-function-alias 'insert-block-diary-entry
2272 'diary-insert-block-entry
"23.1")
2275 (defun diary-insert-cyclic-entry (arg)
2276 "Insert a cyclic diary entry starting at the date given by point.
2277 Prefix argument ARG makes the entry nonmarking."
2279 (let ((calendar-date-display-form (diary-date-display-form)))
2281 (format "%s(diary-cyclic %d %s)"
2282 diary-sexp-entry-symbol
2283 (calendar-read "Repeat every how many days: "
2284 (lambda (x) (> x
0)))
2285 (calendar-date-string (calendar-cursor-to-date t
) nil t
))
2289 (define-obsolete-function-alias 'insert-cyclic-diary-entry
2290 'diary-insert-cyclic-entry
"23.1")
2294 (defun diary-redraw-calendar ()
2295 "If `calendar-buffer' is live and diary entries are marked, redraw it."
2296 (and calendar-mark-diary-entries-flag
2299 ;; Return value suitable for `write-contents-functions'.
2302 (defvar diary-mode-map
2303 (let ((map (make-sparse-keymap)))
2304 (define-key map
"\C-c\C-s" 'diary-show-all-entries
)
2305 (define-key map
"\C-c\C-q" 'quit-window
)
2307 "Keymap for `diary-mode'.")
2309 (defun diary-font-lock-sexps (limit)
2310 "Recognize sexp diary entry up to LIMIT for font-locking."
2311 (if (re-search-forward
2312 (format "^%s?\\(%s\\)" (regexp-quote diary-nonmarking-symbol
)
2313 (regexp-quote diary-sexp-entry-symbol
))
2317 (narrow-to-region (point-min) limit
)
2318 (let ((start (point)))
2320 (store-match-data (list start
(point)))
2324 (defun diary-font-lock-date-forms (month-array &optional symbol abbrev-array
)
2325 "Create font-lock patterns for `diary-date-forms' using MONTH-ARRAY.
2326 If given, optional SYMBOL must be a prefix to entries. If
2327 optional ABBREV-ARRAY is present, also matches the abbreviations
2328 from this array (with or without a final `.'), in addition to the
2330 (let ((dayname (diary-name-pattern calendar-day-name-array
2331 calendar-day-abbrev-array t
))
2332 (monthname (format "\\(%s\\|\\*\\)"
2333 (diary-name-pattern month-array abbrev-array
)))
2334 (month "\\([0-9]+\\|\\*\\)")
2335 (day "\\([0-9]+\\|\\*\\)")
2336 (year "-?\\([0-9]+\\|\\*\\)"))
2339 (concat "^" (regexp-quote diary-nonmarking-symbol
) "?"
2340 (if symbol
(regexp-quote symbol
) "") "\\("
2342 ;; If backup, omit first item (backup)
2343 ;; and last item (not part of date).
2344 (if (equal (car x
) 'backup
)
2345 (nreverse (cdr (reverse (cdr x
))))
2348 ;; With backup, last item is not part of date.
2349 (if (equal (car x
) 'backup
)
2350 (concat "\\)" (eval (car (reverse x
))))
2355 (defmacro diary-font-lock-keywords-1
(markfunc listfunc feature months symbol
)
2356 "Subroutine of the function `diary-font-lock-keywords'.
2357 If MARKFUNC is a member of `diary-nongregorian-marking-hook', or
2358 LISTFUNC of `diary-nongregorian-listing-hook', then require FEATURE and
2359 return a font-lock pattern matching array of MONTHS and marking SYMBOL."
2360 `(when (or (memq ',markfunc diary-nongregorian-marking-hook
)
2361 (memq ',listfunc diary-nongregorian-listing-hook
))
2363 (diary-font-lock-date-forms ,months
,symbol
)))
2365 (defconst diary-time-regexp
2366 ;; Accepted formats: 10:00 10.00 10h00 10h 10am 10:00am 10.00am
2367 ;; Use of "." as a separator annoyingly matches numbers, eg "123.45".
2368 ;; Hence often prefix this with "\\(^\\|\\s-\\)."
2369 (concat "[0-9]?[0-9]\\([AaPp][mM]\\|\\("
2370 "[Hh]\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]"
2371 "\\)\\([AaPp][Mm]\\)?\\)")
2372 "Regular expression matching a time of day.")
2374 (defvar calendar-hebrew-month-name-array-leap-year
)
2375 (defvar calendar-islamic-month-name-array
)
2376 (defvar calendar-bahai-month-name-array
)
2379 (defun diary-font-lock-keywords ()
2380 "Return a value for the variable `diary-font-lock-keywords'."
2382 (diary-font-lock-date-forms calendar-month-name-array
2383 nil calendar-month-abbrev-array
)
2384 (diary-font-lock-keywords-1 diary-hebrew-mark-entries
2385 diary-hebrew-list-entries
2387 calendar-hebrew-month-name-array-leap-year
2388 diary-hebrew-entry-symbol
)
2389 (diary-font-lock-keywords-1 diary-islamic-mark-entries
2390 diary-islamic-list-entries
2392 calendar-islamic-month-name-array
2393 diary-islamic-entry-symbol
)
2394 (diary-font-lock-keywords-1 diary-bahai-mark-entries
2395 diary-bahai-list-entries
2397 calendar-bahai-month-name-array
2398 diary-bahai-entry-symbol
)
2401 (format "^%s.*$" (regexp-quote diary-include-string
))
2402 'font-lock-keyword-face
)
2404 (format "^%s?\\(%s\\)" (regexp-quote diary-nonmarking-symbol
)
2405 (regexp-quote diary-sexp-entry-symbol
))
2406 '(1 font-lock-constant-face
))
2408 (format "^%s" (regexp-quote diary-nonmarking-symbol
))
2409 'font-lock-constant-face
)
2411 (format "^%s?%s" (regexp-quote diary-nonmarking-symbol
)
2412 (regexp-opt (mapcar 'regexp-quote
2413 (list diary-hebrew-entry-symbol
2414 diary-islamic-entry-symbol
2415 diary-bahai-entry-symbol
))
2417 '(1 font-lock-constant-face
))
2418 '(diary-font-lock-sexps . font-lock-keyword-face
)
2419 ;; Don't need to worry about space around "-" because the first
2420 ;; match takes care of that. It does mean the "-" itself may or
2421 ;; may not be fontified though.
2422 ;; diary-date-forms often include a final character that is not
2423 ;; part of the date (eg a non-digit to mark the end of the year).
2424 ;; This can use up the only space char between a date and time (b#7891).
2425 ;; Hence we use OVERRIDE, which can only override whitespace.
2426 ;; FIXME it's probably better to tighten up the diary-time-regexp
2427 ;; and drop the whitespace requirement below.
2428 `(,(format "\\(^\\|\\s-\\)%s\\(-%s\\)?" diary-time-regexp
2430 .
(0 'diary-time t
)))))
2433 (defvar diary-font-lock-keywords
(diary-font-lock-keywords)
2434 "Forms to highlight in `diary-mode'.")
2437 (define-derived-mode diary-mode fundamental-mode
"Diary"
2438 "Major mode for editing the diary file."
2439 (set (make-local-variable 'font-lock-defaults
)
2440 '(diary-font-lock-keywords t
))
2441 (set (make-local-variable 'comment-start
) diary-comment-start
)
2442 (set (make-local-variable 'comment-end
) diary-comment-end
)
2443 (add-to-invisibility-spec '(diary . nil
))
2444 (add-hook 'after-save-hook
'diary-redraw-calendar nil t
)
2445 ;; In case the file was modified externally, refresh the calendar
2446 ;; after refreshing the diary buffer.
2447 (add-hook 'after-revert-hook
'diary-redraw-calendar nil t
)
2448 (if diary-header-line-flag
2449 (setq header-line-format diary-header-line-format
)))
2452 ;;; Fancy Diary Mode.
2454 (defun diary-fancy-date-pattern ()
2455 "Return a regexp matching the first line of a fancy diary date header.
2456 This depends on the calendar date style."
2458 (let ((dayname (diary-name-pattern calendar-day-name-array nil t
))
2459 (monthname (diary-name-pattern calendar-month-name-array nil t
))
2462 ;; FIXME? This used to be "-?[0-9]+" - what was the "-?" for?
2464 ;; This is ugly. c-d-d-form expects `day' etc to be "numbers in
2465 ;; string form"; eg the iso version calls string-to-number on some.
2466 ;; Therefore we cannot eg just let day = "[0-9]+". (Bug#8583).
2467 ;; Assumes no integers in c-day/month-name-array.
2468 (replace-regexp-in-string "[0-9]+" "[0-9]+"
2469 (mapconcat 'eval calendar-date-display-form
"")
2471 ;; Optional ": holiday name" after the date.
2474 (defun diary-fancy-date-matcher (limit)
2475 "Search for a fancy diary data header, up to LIMIT."
2476 ;; Any number of " other holiday name" lines, followed by "==" line.
2477 (when (re-search-forward
2478 (format "%s\\(\n +.*\\)*\n=+$" (diary-fancy-date-pattern)) limit t
)
2479 (put-text-property (match-beginning 0) (match-end 0) 'font-lock-multiline t
)
2482 (define-obsolete-variable-alias 'fancy-diary-font-lock-keywords
2483 'diary-fancy-font-lock-keywords
"23.1")
2485 (defvar diary-fancy-font-lock-keywords
2486 `((diary-fancy-date-matcher . diary-face
)
2487 ("^.*\\([aA]nniversary\\|[bB]irthday\\).*$" .
'diary-anniversary
)
2488 ("^.*Yahrzeit.*$" . font-lock-constant-face
)
2489 ("^\\(Erev \\)?Rosh Hodesh.*" . font-lock-function-name-face
)
2490 ("^Day.*omer.*$" . font-lock-builtin-face
)
2491 ("^Parashat.*$" . font-lock-comment-face
)
2492 (,(format "\\(^\\|\\s-\\)%s\\(-%s\\)?" diary-time-regexp
2493 diary-time-regexp
) .
'diary-time
))
2494 "Keywords to highlight in fancy diary display.")
2496 ;; If region looks like it might start or end in the middle of a
2497 ;; multiline pattern, extend the region to encompass the whole pattern.
2498 (defun diary-fancy-font-lock-fontify-region-function (beg end
&optional verbose
)
2499 "Function to use for `font-lock-fontify-region-function' in Fancy Diary.
2500 Needed to handle multiline keyword in `diary-fancy-font-lock-keywords'.
2501 Fontify the region between BEG and END, quietly unless VERBOSE is non-nil."
2504 (if (looking-at "=+$") (forward-line -
1))
2505 (while (and (looking-at " +[^ ]")
2506 (zerop (forward-line -
1))))
2507 ;; This check not essential.
2508 (if (looking-at (diary-fancy-date-pattern))
2509 (setq beg
(line-beginning-position)))
2512 (while (and (looking-at " +[^ ]")
2513 (zerop (forward-line 1))))
2514 (if (looking-at "=+$")
2515 (setq end
(line-beginning-position 2)))
2516 (font-lock-default-fontify-region beg end verbose
))
2518 (defvar diary-fancy-overriding-map
(make-sparse-keymap)
2519 "Keymap overriding minor-mode maps in `diary-fancy-display-mode'.")
2521 (define-derived-mode diary-fancy-display-mode special-mode
2523 "Major mode used while displaying diary entries using Fancy Display."
2524 (set (make-local-variable 'font-lock-defaults
)
2525 '(diary-fancy-font-lock-keywords
2527 (font-lock-fontify-region-function
2528 . diary-fancy-font-lock-fontify-region-function
)))
2529 (set (make-local-variable 'minor-mode-overriding-map-alist
)
2530 (list (cons t diary-fancy-overriding-map
)))
2533 (define-obsolete-function-alias 'fancy-diary-display-mode
2534 'diary-fancy-display-mode
"23.1")
2536 ;; Following code from Dave Love <fx@gnu.org>.
2537 ;; Import Outlook-format appointments from mail messages in Gnus or
2538 ;; Rmail using command `diary-from-outlook'. This, or the specialized
2539 ;; functions `diary-from-outlook-gnus' and `diary-from-outlook-rmail',
2540 ;; could be run from hooks to notice appointments automatically (in
2541 ;; which case they will prompt about adding to the diary). The
2542 ;; message formats recognized are customizable through `diary-outlook-formats'.
2544 (defun diary-from-outlook-internal (subject body
&optional test-only
)
2545 "Snarf a diary entry from a message assumed to be from MS Outlook.
2546 SUBJECT and BODY are strings giving the message subject and body.
2547 Arg TEST-ONLY non-nil means return non-nil if and only if the
2548 message contains an appointment, don't make a diary entry."
2550 (let (format-string)
2551 (dolist (fmt diary-outlook-formats
)
2552 (when (eq 0 (string-match (car fmt
) body
))
2554 (setq format-string
(cdr fmt
))
2556 (save-window-excursion
2558 (format (replace-match (if (functionp format-string
)
2559 (funcall format-string body
)
2561 t nil
(match-string 0 body
))
2563 (throw 'finished t
))))
2566 (defvar gnus-article-mime-handles
)
2567 (defvar gnus-article-buffer
)
2569 (autoload 'gnus-fetch-field
"gnus-util")
2570 (autoload 'gnus-narrow-to-body
"gnus")
2571 (autoload 'mm-get-part
"mm-decode")
2573 (defun diary-from-outlook-gnus (&optional noconfirm
)
2574 "Maybe snarf diary entry from Outlook-generated message in Gnus.
2575 Unless the optional argument NOCONFIRM is non-nil (which is the case when
2576 this function is called interactively), then if an entry is found the
2577 user is asked to confirm its addition.
2578 Add this function to `gnus-article-prepare-hook' to notice appointments
2581 (with-current-buffer gnus-article-buffer
2582 (let ((subject (gnus-fetch-field "subject"))
2583 (body (if gnus-article-mime-handles
2584 ;; We're multipart. Don't get confused by part
2585 ;; buttons &c. Assume info is in first part.
2586 (mm-get-part (nth 1 gnus-article-mime-handles
))
2588 (gnus-narrow-to-body)
2590 (when (diary-from-outlook-internal subject body t
)
2591 (when (or noconfirm
(y-or-n-p "Snarf diary entry? "))
2592 (diary-from-outlook-internal subject body
)
2593 (message "Diary entry added"))))))
2595 (custom-add-option 'gnus-article-prepare-hook
'diary-from-outlook-gnus
)
2597 (defvar rmail-buffer
)
2599 (defun diary-from-outlook-rmail (&optional noconfirm
)
2600 "Maybe snarf diary entry from Outlook-generated message in Rmail.
2601 Unless the optional argument NOCONFIRM is non-nil (which is the case when
2602 this function is called interactively), then if an entry is found the
2603 user is asked to confirm its addition."
2605 ;; FIXME maybe the body needs rmail-mm decoding, in which case
2606 ;; there is no single buffer with both body and subject, sigh.
2607 (with-current-buffer rmail-buffer
2608 (let ((subject (mail-fetch-field "subject"))
2609 (body (buffer-substring (save-excursion
2613 (when (diary-from-outlook-internal subject body t
)
2614 (when (or noconfirm
(y-or-n-p "Snarf diary entry? "))
2615 (diary-from-outlook-internal subject body
)
2616 (message "Diary entry added"))))))
2618 (defvar diary-from-outlook-function nil
2619 "If non-nil, a function of one argument for `diary-from-outlook' to call.
2620 If the current buffer contains an Outlook-style appointment message,
2621 this function should extract it into a diary entry. If the argument is
2622 nil, it should ask for confirmation before adding this entry to the diary.
2623 For examples, see `diary-from-outlook-rmail' and `diary-from-outlook-gnus'.")
2625 (defun diary-from-outlook (&optional noconfirm
)
2626 "Maybe snarf diary entry from current Outlook-generated message.
2627 Uses `diary-from-outlook-function' if that is non-nil, else
2628 `diary-from-outlook-rmail' for Rmail or `diary-from-outlook-gnus' for Gnus.
2629 Unless the optional argument NOCONFIRM is non-nil (which is the
2630 case when this function is called interactively), then if an
2631 entry is found the user is asked to confirm its addition."
2634 (diary-from-outlook-function)
2635 ((eq major-mode
'rmail-mode
)
2636 #'diary-from-outlook-rmail
)
2637 ((memq major-mode
'(gnus-summary-mode gnus-article-mode
))
2638 #'diary-from-outlook-gnus
)
2639 (t (error "Don't know how to snarf in `%s'" major-mode
)))))
2640 (funcall func noconfirm
)))
2642 (provide 'diary-lib
)
2648 ;;; diary-lib.el ends here