Mercurial > emacs
annotate lisp/calendar/diary-lib.el @ 48241:0250bd3da532
(install-arch-indep): Prepend $(srcdir)/ to lisp.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Mon, 11 Nov 2002 09:03:08 +0000 |
parents | afefa409b756 |
children | 67f6a633fe52 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37001
diff
changeset
|
1 ;;; diary-lib.el --- diary functions |
13053 | 2 |
14169 | 3 ;; Copyright (C) 1989, 1990, 1992, 1993, 1994, 1995 Free Software |
4 ;; Foundation, Inc. | |
13053 | 5 |
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
7 ;; Keywords: calendar | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
13053 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This collection of functions implements the diary features as described | |
29 ;; in calendar.el. | |
30 | |
31 ;; Comments, corrections, and improvements should be sent to | |
32 ;; Edward M. Reingold Department of Computer Science | |
33 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
34 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
35 ;; Urbana, Illinois 61801 | |
36 | |
37 ;;; Code: | |
38 | |
39 (require 'calendar) | |
40 | |
41 ;;;###autoload | |
42 (defun diary (&optional arg) | |
43 "Generate the diary window for ARG days starting with the current date. | |
44 If no argument is provided, the number of days of diary entries is governed | |
45 by the variable `number-of-diary-entries'. This function is suitable for | |
46 execution in a `.emacs' file." | |
47 (interactive "P") | |
48 (let ((d-file (substitute-in-file-name diary-file)) | |
49 (date (calendar-current-date))) | |
50 (if (and d-file (file-exists-p d-file)) | |
51 (if (file-readable-p d-file) | |
52 (list-diary-entries | |
53 date | |
54 (cond | |
55 (arg (prefix-numeric-value arg)) | |
56 ((vectorp number-of-diary-entries) | |
57 (aref number-of-diary-entries (calendar-day-of-week date))) | |
58 (t number-of-diary-entries))) | |
59 (error "Your diary file is not readable!")) | |
60 (error "You don't have a diary file!")))) | |
61 | |
62 (defun view-diary-entries (arg) | |
63 "Prepare and display a buffer with diary entries. | |
64 Searches the file named in `diary-file' for entries that | |
65 match ARG days starting with the date indicated by the cursor position | |
66 in the displayed three-month calendar." | |
67 (interactive "p") | |
68 (let ((d-file (substitute-in-file-name diary-file))) | |
69 (if (and d-file (file-exists-p d-file)) | |
70 (if (file-readable-p d-file) | |
71 (list-diary-entries (calendar-cursor-to-date t) arg) | |
72 (error "Diary file is not readable!")) | |
73 (error "You don't have a diary file!")))) | |
74 | |
22412
6fdc14d2b071
Don't overide default value of diary-file.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
21957
diff
changeset
|
75 (defun view-other-diary-entries (arg d-file) |
13053 | 76 "Prepare and display buffer of diary entries from an alternative diary file. |
77 Prompts for a file name and searches that file for entries that match ARG | |
78 days starting with the date indicated by the cursor position in the displayed | |
79 three-month calendar." | |
80 (interactive | |
81 (list (cond ((null current-prefix-arg) 1) | |
82 ((listp current-prefix-arg) (car current-prefix-arg)) | |
83 (t current-prefix-arg)) | |
22412
6fdc14d2b071
Don't overide default value of diary-file.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
21957
diff
changeset
|
84 (read-file-name "Enter diary file name: " default-directory nil t))) |
6fdc14d2b071
Don't overide default value of diary-file.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
21957
diff
changeset
|
85 (let ((diary-file d-file)) |
6fdc14d2b071
Don't overide default value of diary-file.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
21957
diff
changeset
|
86 (view-diary-entries arg))) |
13053 | 87 |
88 (autoload 'check-calendar-holidays "holidays" | |
89 "Check the list of holidays for any that occur on DATE. | |
90 The value returned is a list of strings of relevant holiday descriptions. | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
91 The holidays are those in the list `calendar-holidays'.") |
13053 | 92 |
93 (autoload 'calendar-holiday-list "holidays" | |
94 "Form the list of holidays that occur on dates in the calendar window. | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
95 The holidays are those in the list `calendar-holidays'.") |
13053 | 96 |
97 (autoload 'diary-french-date "cal-french" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
98 "French calendar equivalent of date diary entry.") |
13053 | 99 |
100 (autoload 'diary-mayan-date "cal-mayan" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
101 "Mayan calendar equivalent of date diary entry.") |
13053 | 102 |
13688
88f14fa8e205
Autoload diary-iso-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13687
diff
changeset
|
103 (autoload 'diary-iso-date "cal-iso" |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
104 "ISO calendar equivalent of date diary entry.") |
13688
88f14fa8e205
Autoload diary-iso-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13687
diff
changeset
|
105 |
13053 | 106 (autoload 'diary-julian-date "cal-julian" |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
107 "Julian calendar equivalent of date diary entry.") |
13053 | 108 |
109 (autoload 'diary-astro-day-number "cal-julian" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
110 "Astronomical (Julian) day number diary entry.") |
13053 | 111 |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
112 (autoload 'diary-chinese-date "cal-china" |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
113 "Chinese calendar equivalent of date diary entry.") |
13053 | 114 |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
115 (autoload 'diary-islamic-date "cal-islam" |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
116 "Islamic calendar equivalent of date diary entry.") |
13053 | 117 |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
118 (autoload 'list-islamic-diary-entries "cal-islam" |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
119 "Add any Islamic date entries from the diary file to `diary-entries-list'.") |
13053 | 120 |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
121 (autoload 'mark-islamic-diary-entries "cal-islam" |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
122 "Mark days in the calendar window that have Islamic date diary entries.") |
13053 | 123 |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14308
diff
changeset
|
124 (autoload 'mark-islamic-calendar-date-pattern "cal-islam" |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
125 "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR.") |
13053 | 126 |
127 (autoload 'diary-hebrew-date "cal-hebrew" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
128 "Hebrew calendar equivalent of date diary entry.") |
13053 | 129 |
130 (autoload 'diary-omer "cal-hebrew" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
131 "Omer count diary entry.") |
13053 | 132 |
133 (autoload 'diary-yahrzeit "cal-hebrew" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
134 "Yahrzeit diary entry--entry applies if date is yahrzeit or the day before.") |
13053 | 135 |
136 (autoload 'diary-parasha "cal-hebrew" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
137 "Parasha diary entry--entry applies if date is a Saturday.") |
13053 | 138 |
139 (autoload 'diary-rosh-hodesh "cal-hebrew" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
140 "Rosh Hodesh diary entry.") |
13053 | 141 |
142 (autoload 'list-hebrew-diary-entries "cal-hebrew" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
143 "Add any Hebrew date entries from the diary file to `diary-entries-list'.") |
13053 | 144 |
145 (autoload 'mark-hebrew-diary-entries "cal-hebrew" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
146 "Mark days in the calendar window that have Hebrew date diary entries.") |
13053 | 147 |
148 (autoload 'mark-hebrew-calendar-date-pattern "cal-hebrew" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
149 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR.") |
13053 | 150 |
151 (autoload 'diary-coptic-date "cal-coptic" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
152 "Coptic calendar equivalent of date diary entry.") |
13053 | 153 |
154 (autoload 'diary-ethiopic-date "cal-coptic" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
155 "Ethiopic calendar equivalent of date diary entry.") |
13053 | 156 |
15258
ab5975df6164
Change autoload references from cal-persian to cal-persia.
Karl Heuer <kwzh@gnu.org>
parents:
14954
diff
changeset
|
157 (autoload 'diary-persian-date "cal-persia" |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
158 "Persian calendar equivalent of date diary entry.") |
14954
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
159 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
160 (autoload 'diary-phases-of-moon "lunar" "Moon phases diary entry.") |
13053 | 161 |
162 (autoload 'diary-sunrise-sunset "solar" | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
163 "Local time of sunrise and sunset as a diary entry.") |
13053 | 164 |
165 (autoload 'diary-sabbath-candles "solar" | |
166 "Local time of candle lighting diary entry--applies if date is a Friday. | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
167 No diary entry if there is no sunset on that date.") |
13053 | 168 |
169 (defvar diary-syntax-table (copy-syntax-table (standard-syntax-table)) | |
170 "The syntax table used when parsing dates in the diary file. | |
171 It is the standard syntax table used in Fundamental mode, but with the | |
172 syntax of `*' changed to be a word constituent.") | |
173 | |
174 (modify-syntax-entry ?* "w" diary-syntax-table) | |
25155
acad42cf5361
Change syntax table entry for colon in the diary as part of the
Richard M. Stallman <rms@gnu.org>
parents:
24760
diff
changeset
|
175 (modify-syntax-entry ?: "w" diary-syntax-table) |
13053 | 176 |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
177 (defvar diary-modified) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
178 (defvar diary-entries-list) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
179 (defvar displayed-year) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
180 (defvar displayed-month) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
181 (defvar entry) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
182 (defvar date) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
183 (defvar number) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
184 (defvar date-string) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
185 (defvar d-file) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
186 (defvar original-date) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
187 |
13053 | 188 (defun list-diary-entries (date number) |
189 "Create and display a buffer containing the relevant lines in diary-file. | |
190 The arguments are DATE and NUMBER; the entries selected are those | |
191 for NUMBER days starting with date DATE. The other entries are hidden | |
192 using selective display. | |
193 | |
194 Returns a list of all relevant diary entries found, if any, in order by date. | |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
195 The list entries have the form ((month day year) string specifier) where |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
196 \(month day year) is the date of the entry, string is the entry text, and |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
197 specifier is the applicability. If the variable `diary-list-include-blanks' |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
198 is t, this list includes a dummy diary entry consisting of the empty string) |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
199 for a date with no diary entries. |
13053 | 200 |
201 After the list is prepared, the hooks `nongregorian-diary-listing-hook', | |
202 `list-diary-entries-hook', `diary-display-hook', and `diary-hook' are run. | |
203 These hooks have the following distinct roles: | |
204 | |
205 `nongregorian-diary-listing-hook' can cull dates from the diary | |
206 and each included file. Usually used for Hebrew or Islamic | |
207 diary entries in files. Applied to *each* file. | |
208 | |
209 `list-diary-entries-hook' adds or manipulates diary entries from | |
210 external sources. Used, for example, to include diary entries | |
211 from other files or to sort the diary entries. Invoked *once* only, | |
212 before the display hook is run. | |
213 | |
214 `diary-display-hook' does the actual display of information. If this is | |
215 nil, simple-diary-display will be used. Use add-hook to set this to | |
216 fancy-diary-display, if desired. If you want no diary display, use | |
217 add-hook to set this to ignore. | |
218 | |
219 `diary-hook' is run last. This can be used for an appointment | |
220 notification function." | |
221 | |
222 (if (< 0 number) | |
223 (let* ((original-date date);; save for possible use in the hooks | |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
224 old-diary-syntax-table |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
225 diary-entries-list |
13053 | 226 (date-string (calendar-date-string date)) |
227 (d-file (substitute-in-file-name diary-file))) | |
228 (message "Preparing diary...") | |
229 (save-excursion | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
230 (let ((diary-buffer (find-buffer-visiting d-file))) |
16545
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
231 (if (not diary-buffer) |
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
232 (set-buffer (find-file-noselect d-file t)) |
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
233 (set-buffer diary-buffer) |
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
234 (or (verify-visited-file-modtime diary-buffer) |
ff25eb6a7d11
(list-diary-entries): Reread the diary file if it has changed.
Richard M. Stallman <rms@gnu.org>
parents:
15258
diff
changeset
|
235 (revert-buffer t t)))) |
13053 | 236 (setq selective-display t) |
237 (setq selective-display-ellipses nil) | |
238 (setq old-diary-syntax-table (syntax-table)) | |
239 (set-syntax-table diary-syntax-table) | |
240 (unwind-protect | |
241 (let ((buffer-read-only nil) | |
242 (diary-modified (buffer-modified-p)) | |
243 (mark (regexp-quote diary-nonmarking-symbol))) | |
27918
a71031623500
(list-diary-entries): Don't try to go forward at
Gerd Moellmann <gerd@gnu.org>
parents:
27842
diff
changeset
|
244 ;; First and last characters must be ^M or \n for |
a71031623500
(list-diary-entries): Don't try to go forward at
Gerd Moellmann <gerd@gnu.org>
parents:
27842
diff
changeset
|
245 ;; selective display to work properly |
13053 | 246 (goto-char (1- (point-max))) |
247 (if (not (looking-at "\^M\\|\n")) | |
248 (progn | |
27918
a71031623500
(list-diary-entries): Don't try to go forward at
Gerd Moellmann <gerd@gnu.org>
parents:
27842
diff
changeset
|
249 (goto-char (point-max)) |
41566
82d4ad3abe8c
(list-diary-entries): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents:
39615
diff
changeset
|
250 (insert "\^M"))) |
13053 | 251 (goto-char (point-min)) |
252 (if (not (looking-at "\^M\\|\n")) | |
41566
82d4ad3abe8c
(list-diary-entries): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents:
39615
diff
changeset
|
253 (insert "\^M")) |
13053 | 254 (subst-char-in-region (point-min) (point-max) ?\n ?\^M t) |
255 (calendar-for-loop i from 1 to number do | |
256 (let ((d diary-date-forms) | |
257 (month (extract-calendar-month date)) | |
258 (day (extract-calendar-day date)) | |
259 (year (extract-calendar-year date)) | |
260 (entry-found (list-sexp-diary-entries date))) | |
261 (while d | |
262 (let* | |
263 ((date-form (if (equal (car (car d)) 'backup) | |
264 (cdr (car d)) | |
265 (car d))) | |
266 (backup (equal (car (car d)) 'backup)) | |
267 (dayname | |
268 (concat | |
269 (calendar-day-name date) "\\|" | |
270 (substring (calendar-day-name date) 0 3) ".?")) | |
271 (monthname | |
272 (concat | |
273 "\\*\\|" | |
274 (calendar-month-name month) "\\|" | |
275 (substring (calendar-month-name month) 0 3) ".?")) | |
276 (month (concat "\\*\\|0*" (int-to-string month))) | |
277 (day (concat "\\*\\|0*" (int-to-string day))) | |
278 (year | |
279 (concat | |
280 "\\*\\|0*" (int-to-string year) | |
281 (if abbreviated-calendar-year | |
25594
2d1ef4eb8297
1999-09-07 Edward M. Reingold <reingold@emr.cs.uiuc.edu>
Dave Love <fx@gnu.org>
parents:
25155
diff
changeset
|
282 (concat "\\|" (format "%02d" (% year 100))) |
13053 | 283 ""))) |
284 (regexp | |
285 (concat | |
286 "\\(\\`\\|\^M\\|\n\\)" mark "?\\(" | |
287 (mapconcat 'eval date-form "\\)\\(") | |
288 "\\)")) | |
289 (case-fold-search t)) | |
290 (goto-char (point-min)) | |
291 (while (re-search-forward regexp nil t) | |
292 (if backup (re-search-backward "\\<" nil t)) | |
293 (if (and (or (char-equal (preceding-char) ?\^M) | |
294 (char-equal (preceding-char) ?\n)) | |
295 (not (looking-at " \\|\^I"))) | |
296 ;; Diary entry that consists only of date. | |
297 (backward-char 1) | |
298 ;; Found a nonempty diary entry--make it visible and | |
299 ;; add it to the list. | |
300 (setq entry-found t) | |
301 (let ((entry-start (point)) | |
302 (date-start)) | |
303 (re-search-backward "\^M\\|\n\\|\\`") | |
304 (setq date-start (point)) | |
305 (re-search-forward "\^M\\|\n" nil t 2) | |
306 (while (looking-at " \\|\^I") | |
307 (re-search-forward "\^M\\|\n" nil t)) | |
308 (backward-char 1) | |
309 (subst-char-in-region date-start | |
310 (point) ?\^M ?\n t) | |
311 (add-to-diary-list | |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
312 date |
43646
bcdc815ba23f
(list-diary-entries): Use `buffer-substring' instead of
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
42513
diff
changeset
|
313 (buffer-substring |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
314 entry-start (point)) |
43646
bcdc815ba23f
(list-diary-entries): Use `buffer-substring' instead of
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
42513
diff
changeset
|
315 (buffer-substring |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
316 (1+ date-start) (1- entry-start))))))) |
13053 | 317 (setq d (cdr d))) |
318 (or entry-found | |
319 (not diary-list-include-blanks) | |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
320 (setq diary-entries-list |
13053 | 321 (append diary-entries-list |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
322 (list (list date "" ""))))) |
13053 | 323 (setq date |
324 (calendar-gregorian-from-absolute | |
325 (1+ (calendar-absolute-from-gregorian date)))) | |
326 (setq entry-found nil))) | |
327 (set-buffer-modified-p diary-modified)) | |
328 (set-syntax-table old-diary-syntax-table)) | |
329 (goto-char (point-min)) | |
330 (run-hooks 'nongregorian-diary-listing-hook | |
331 'list-diary-entries-hook) | |
332 (if diary-display-hook | |
333 (run-hooks 'diary-display-hook) | |
334 (simple-diary-display)) | |
335 (run-hooks 'diary-hook) | |
336 diary-entries-list)))) | |
337 | |
338 (defun include-other-diary-files () | |
339 "Include the diary entries from other diary files with those of diary-file. | |
340 This function is suitable for use in `list-diary-entries-hook'; | |
341 it enables you to use shared diary files together with your own. | |
342 The files included are specified in the diaryfile by lines of this form: | |
343 #include \"filename\" | |
344 This is recursive; that is, #include directives in diary files thus included | |
345 are obeyed. You can change the `#include' to some other string by | |
346 changing the variable `diary-include-string'." | |
347 (goto-char (point-min)) | |
348 (while (re-search-forward | |
349 (concat | |
350 "\\(\\`\\|\^M\\|\n\\)" | |
351 (regexp-quote diary-include-string) | |
352 " \"\\([^\"]*\\)\"") | |
353 nil t) | |
27842
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
354 (let* ((diary-file (substitute-in-file-name |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
355 (buffer-substring-no-properties |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
356 (match-beginning 2) (match-end 2)))) |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
357 (diary-list-include-blanks nil) |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
358 (list-diary-entries-hook 'include-other-diary-files) |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
359 (diary-display-hook 'ignore) |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
360 (diary-hook nil) |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
361 (d-buffer (find-buffer-visiting diary-file)) |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
362 (diary-modified (if d-buffer |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
363 (save-excursion |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
364 (set-buffer d-buffer) |
cfa579c1229f
(include-other-diary-files): Undo the selective
Gerd Moellmann <gerd@gnu.org>
parents:
26330
diff
changeset
|
365 (buffer-modified-p))))) |
13053 | 366 (if (file-exists-p diary-file) |
367 (if (file-readable-p diary-file) | |
368 (unwind-protect | |
369 (setq diary-entries-list | |
370 (append diary-entries-list | |
371 (list-diary-entries original-date number))) | |
28575
dc6ae1a1331c
(include-other-diary-files): Fix the fix of
Gerd Moellmann <gerd@gnu.org>
parents:
27918
diff
changeset
|
372 (save-excursion |
dc6ae1a1331c
(include-other-diary-files): Fix the fix of
Gerd Moellmann <gerd@gnu.org>
parents:
27918
diff
changeset
|
373 (set-buffer (find-buffer-visiting diary-file)) |
44732
a3338547dad4
(include-other-diary-files): Allow modifying
Richard M. Stallman <rms@gnu.org>
parents:
43646
diff
changeset
|
374 (let ((inhibit-read-only t)) |
a3338547dad4
(include-other-diary-files): Allow modifying
Richard M. Stallman <rms@gnu.org>
parents:
43646
diff
changeset
|
375 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)) |
28575
dc6ae1a1331c
(include-other-diary-files): Fix the fix of
Gerd Moellmann <gerd@gnu.org>
parents:
27918
diff
changeset
|
376 (setq selective-display nil) |
dc6ae1a1331c
(include-other-diary-files): Fix the fix of
Gerd Moellmann <gerd@gnu.org>
parents:
27918
diff
changeset
|
377 (set-buffer-modified-p diary-modified))) |
13053 | 378 (beep) |
379 (message "Can't read included diary file %s" diary-file) | |
380 (sleep-for 2)) | |
381 (beep) | |
382 (message "Can't find included diary file %s" diary-file) | |
383 (sleep-for 2)))) | |
384 (goto-char (point-min))) | |
385 | |
386 (defun simple-diary-display () | |
387 "Display the diary buffer if there are any relevant entries or holidays." | |
388 (let* ((holiday-list (if holidays-in-diary-buffer | |
389 (check-calendar-holidays original-date))) | |
390 (msg (format "No diary entries for %s %s" | |
391 (concat date-string (if holiday-list ":" "")) | |
392 (mapconcat 'identity holiday-list "; ")))) | |
26330
d0f895577892
(simple-diary-display): Reset modeline even if
Gerd Moellmann <gerd@gnu.org>
parents:
25594
diff
changeset
|
393 (calendar-set-mode-line |
d0f895577892
(simple-diary-display): Reset modeline even if
Gerd Moellmann <gerd@gnu.org>
parents:
25594
diff
changeset
|
394 (concat "Diary for " date-string |
d0f895577892
(simple-diary-display): Reset modeline even if
Gerd Moellmann <gerd@gnu.org>
parents:
25594
diff
changeset
|
395 (if holiday-list ": " "") |
d0f895577892
(simple-diary-display): Reset modeline even if
Gerd Moellmann <gerd@gnu.org>
parents:
25594
diff
changeset
|
396 (mapconcat 'identity holiday-list "; "))) |
13053 | 397 (if (or (not diary-entries-list) |
398 (and (not (cdr diary-entries-list)) | |
399 (string-equal (car (cdr (car diary-entries-list))) ""))) | |
400 (if (<= (length msg) (frame-width)) | |
14308
0ce52b2f2bb5
(simple-diary-display, fancy-diary-display): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
401 (message "%s" msg) |
13053 | 402 (set-buffer (get-buffer-create holiday-buffer)) |
403 (setq buffer-read-only nil) | |
404 (calendar-set-mode-line date-string) | |
405 (erase-buffer) | |
406 (insert (mapconcat 'identity holiday-list "\n")) | |
407 (goto-char (point-min)) | |
408 (set-buffer-modified-p nil) | |
409 (setq buffer-read-only t) | |
410 (display-buffer holiday-buffer) | |
411 (message "No diary entries for %s" date-string)) | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
412 (display-buffer (find-buffer-visiting d-file)) |
13053 | 413 (message "Preparing diary...done")))) |
414 | |
415 (defun fancy-diary-display () | |
416 "Prepare a diary buffer with relevant entries in a fancy, noneditable form. | |
417 This function is provided for optional use as the `diary-display-hook'." | |
418 (save-excursion;; Turn off selective-display in the diary file's buffer. | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
419 (set-buffer (find-buffer-visiting (substitute-in-file-name diary-file))) |
13053 | 420 (let ((diary-modified (buffer-modified-p))) |
421 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t) | |
422 (setq selective-display nil) | |
423 (kill-local-variable 'mode-line-format) | |
424 (set-buffer-modified-p diary-modified))) | |
425 (if (or (not diary-entries-list) | |
426 (and (not (cdr diary-entries-list)) | |
427 (string-equal (car (cdr (car diary-entries-list))) ""))) | |
428 (let* ((holiday-list (if holidays-in-diary-buffer | |
429 (check-calendar-holidays original-date))) | |
430 (msg (format "No diary entries for %s %s" | |
431 (concat date-string (if holiday-list ":" "")) | |
432 (mapconcat 'identity holiday-list "; ")))) | |
433 (if (<= (length msg) (frame-width)) | |
14308
0ce52b2f2bb5
(simple-diary-display, fancy-diary-display): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
434 (message "%s" msg) |
13053 | 435 (set-buffer (get-buffer-create holiday-buffer)) |
436 (setq buffer-read-only nil) | |
437 (calendar-set-mode-line date-string) | |
438 (erase-buffer) | |
439 (insert (mapconcat 'identity holiday-list "\n")) | |
440 (goto-char (point-min)) | |
441 (set-buffer-modified-p nil) | |
442 (setq buffer-read-only t) | |
443 (display-buffer holiday-buffer) | |
444 (message "No diary entries for %s" date-string))) | |
445 (save-excursion;; Prepare the fancy diary buffer. | |
446 (set-buffer (make-fancy-diary-buffer)) | |
447 (setq buffer-read-only nil) | |
448 (let ((entry-list diary-entries-list) | |
449 (holiday-list) | |
450 (holiday-list-last-month 1) | |
451 (holiday-list-last-year 1) | |
452 (date (list 0 0 0))) | |
453 (while entry-list | |
454 (if (not (calendar-date-equal date (car (car entry-list)))) | |
455 (progn | |
456 (setq date (car (car entry-list))) | |
457 (and holidays-in-diary-buffer | |
458 (calendar-date-compare | |
459 (list (list holiday-list-last-month | |
460 (calendar-last-day-of-month | |
461 holiday-list-last-month | |
462 holiday-list-last-year) | |
463 holiday-list-last-year)) | |
464 (list date)) | |
465 ;; We need to get the holidays for the next 3 months. | |
466 (setq holiday-list-last-month | |
467 (extract-calendar-month date)) | |
468 (setq holiday-list-last-year | |
469 (extract-calendar-year date)) | |
470 (increment-calendar-month | |
471 holiday-list-last-month holiday-list-last-year 1) | |
472 (setq holiday-list | |
473 (let ((displayed-month holiday-list-last-month) | |
474 (displayed-year holiday-list-last-year)) | |
475 (calendar-holiday-list))) | |
476 (increment-calendar-month | |
477 holiday-list-last-month holiday-list-last-year 1)) | |
478 (let* ((date-string (calendar-date-string date)) | |
479 (date-holiday-list | |
480 (let ((h holiday-list) | |
481 (d)) | |
482 ;; Make a list of all holidays for date. | |
483 (while h | |
484 (if (calendar-date-equal date (car (car h))) | |
485 (setq d (append d (cdr (car h))))) | |
486 (setq h (cdr h))) | |
487 d))) | |
488 (insert (if (= (point) (point-min)) "" ?\n) date-string) | |
489 (if date-holiday-list (insert ": ")) | |
14954
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
490 (let* ((l (current-column)) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
491 (longest 0)) |
28615
4c6883cb70ab
(fancy-diary-display, mark-diary-entries)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28575
diff
changeset
|
492 (insert (mapconcat (lambda (x) |
4c6883cb70ab
(fancy-diary-display, mark-diary-entries)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28575
diff
changeset
|
493 (if (< longest (length x)) |
4c6883cb70ab
(fancy-diary-display, mark-diary-entries)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28575
diff
changeset
|
494 (setq longest (length x))) |
4c6883cb70ab
(fancy-diary-display, mark-diary-entries)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28575
diff
changeset
|
495 x) |
14954
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
496 date-holiday-list |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
497 (concat "\n" (make-string l ? )))) |
a9102c34a5b6
Fix length of separator string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14687
diff
changeset
|
498 (insert ?\n (make-string (+ l longest) ?=) ?\n))))) |
13053 | 499 (if (< 0 (length (car (cdr (car entry-list))))) |
500 (insert (car (cdr (car entry-list))) ?\n)) | |
501 (setq entry-list (cdr entry-list)))) | |
502 (set-buffer-modified-p nil) | |
503 (goto-char (point-min)) | |
504 (setq buffer-read-only t) | |
505 (display-buffer fancy-diary-buffer) | |
506 (message "Preparing diary...done")))) | |
507 | |
508 (defun make-fancy-diary-buffer () | |
509 "Create and return the initial fancy diary buffer." | |
510 (save-excursion | |
511 (set-buffer (get-buffer-create fancy-diary-buffer)) | |
512 (setq buffer-read-only nil) | |
513 (make-local-variable 'mode-line-format) | |
514 (calendar-set-mode-line "Diary Entries") | |
515 (erase-buffer) | |
516 (set-buffer-modified-p nil) | |
517 (setq buffer-read-only t) | |
518 (get-buffer fancy-diary-buffer))) | |
519 | |
520 (defun print-diary-entries () | |
521 "Print a hard copy of the diary display. | |
522 | |
523 If the simple diary display is being used, prepare a temp buffer with the | |
524 visible lines of the diary buffer, add a heading line composed from the mode | |
525 line, print the temp buffer, and destroy it. | |
526 | |
527 If the fancy diary display is being used, just print the buffer. | |
528 | |
529 The hooks given by the variable `print-diary-entries-hook' are called to do | |
530 the actual printing." | |
531 (interactive) | |
532 (if (bufferp (get-buffer fancy-diary-buffer)) | |
533 (save-excursion | |
534 (set-buffer (get-buffer fancy-diary-buffer)) | |
535 (run-hooks 'print-diary-entries-hook)) | |
536 (let ((diary-buffer | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
537 (find-buffer-visiting (substitute-in-file-name diary-file)))) |
13053 | 538 (if diary-buffer |
539 (let ((temp-buffer (get-buffer-create "*Printable Diary Entries*")) | |
540 (heading)) | |
541 (save-excursion | |
542 (set-buffer diary-buffer) | |
543 (setq heading | |
544 (if (not (stringp mode-line-format)) | |
545 "All Diary Entries" | |
546 (string-match "^-*\\([^-].*[^-]\\)-*$" mode-line-format) | |
547 (substring mode-line-format | |
548 (match-beginning 1) (match-end 1)))) | |
549 (copy-to-buffer temp-buffer (point-min) (point-max)) | |
550 (set-buffer temp-buffer) | |
551 (while (re-search-forward "\^M.*$" nil t) | |
552 (replace-match "")) | |
553 (goto-char (point-min)) | |
554 (insert heading "\n" | |
555 (make-string (length heading) ?=) "\n") | |
556 (run-hooks 'print-diary-entries-hook) | |
557 (kill-buffer temp-buffer))) | |
558 (error "You don't have a diary buffer!"))))) | |
559 | |
560 (defun show-all-diary-entries () | |
561 "Show all of the diary entries in the diary file. | |
562 This function gets rid of the selective display of the diary file so that | |
563 all entries, not just some, are visible. If there is no diary buffer, one | |
564 is created." | |
565 (interactive) | |
566 (let ((d-file (substitute-in-file-name diary-file))) | |
567 (if (and d-file (file-exists-p d-file)) | |
568 (if (file-readable-p d-file) | |
569 (save-excursion | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
570 (let ((diary-buffer (find-buffer-visiting d-file))) |
13053 | 571 (set-buffer (if diary-buffer |
572 diary-buffer | |
573 (find-file-noselect d-file t))) | |
574 (let ((buffer-read-only nil) | |
575 (diary-modified (buffer-modified-p))) | |
576 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t) | |
577 (setq selective-display nil) | |
578 (make-local-variable 'mode-line-format) | |
579 (setq mode-line-format default-mode-line-format) | |
580 (display-buffer (current-buffer)) | |
581 (set-buffer-modified-p diary-modified)))) | |
582 (error "Your diary file is not readable!")) | |
583 (error "You don't have a diary file!")))) | |
584 | |
20345
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
585 |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
586 |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
587 (defcustom diary-mail-addr |
20345
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
588 (if (boundp 'user-mail-address) user-mail-address nil) |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
589 "*Email address that `diary-mail-entries' will send email to." |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
590 :group 'diary |
22683
0941a5743283
(diary-mail-addr): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
22638
diff
changeset
|
591 :type '(choice string (const nil)) |
21668
621dd51298ec
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20354
diff
changeset
|
592 :version "20.3") |
20345
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
593 |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
594 (defcustom diary-mail-days 7 |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
595 "*Number of days for `diary-mail-entries' to check." |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
596 :group 'diary |
21668
621dd51298ec
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20354
diff
changeset
|
597 :type 'integer |
621dd51298ec
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20354
diff
changeset
|
598 :version "20.3") |
20345
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
599 |
21957
a74e1cee89bf
(diary-mail-entries): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
21893
diff
changeset
|
600 ;;;###autoload |
20345
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
601 (defun diary-mail-entries (&optional ndays) |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
602 "Send a mail message showing diary entries for next NDAYS days. |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
603 If no prefix argument is given, NDAYS is set to `diary-mail-days'. |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
604 |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
605 You can call `diary-mail-entries' every night using an at/cron job. |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
606 For example, this script will run the program at 2am daily. Since |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
607 `emacs -batch' does not load your `.emacs' file, you must ensure that |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
608 all relevant variables are set, as done here. |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
609 |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
610 #!/bin/sh |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
611 # diary-rem.sh -- repeatedly run the Emacs diary-reminder |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
612 emacs -batch \\ |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
613 -eval \"(setq diary-mail-days 3 \\ |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
614 european-calendar-style t \\ |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
615 diary-mail-addr \\\"user@host.name\\\" )\" \\ |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
616 -l diary-lib -f diary-mail-entries |
20345
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
617 at -f diary-rem.sh 0200 tomorrow |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
618 |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
619 You may have to tweak the syntax of the `at' command to suit your |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
620 system. Alternatively, you can specify a cron entry: |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
621 0 1 * * * diary-rem.sh |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
622 to run it every morning at 1am." |
35500
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
623 (interactive "P") |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
624 (let* ((diary-display-hook 'fancy-diary-display) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
625 (text (progn (list-diary-entries (calendar-current-date) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
626 (if ndays ndays diary-mail-days)) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
627 (set-buffer fancy-diary-buffer) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
628 (buffer-substring (point-min) (point-max))))) |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
629 (compose-mail diary-mail-addr |
47163
88f34e3227e6
(diary-mail-entries): Don't overwrite user's value
Richard M. Stallman <rms@gnu.org>
parents:
46826
diff
changeset
|
630 (if (string-equal text "") |
88f34e3227e6
(diary-mail-entries): Don't overwrite user's value
Richard M. Stallman <rms@gnu.org>
parents:
46826
diff
changeset
|
631 "No entries found" |
88f34e3227e6
(diary-mail-entries): Don't overwrite user's value
Richard M. Stallman <rms@gnu.org>
parents:
46826
diff
changeset
|
632 (concat "Diary entries generated " |
88f34e3227e6
(diary-mail-entries): Don't overwrite user's value
Richard M. Stallman <rms@gnu.org>
parents:
46826
diff
changeset
|
633 (calendar-date-string (calendar-current-date))))) |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
634 (insert text) |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
635 (funcall (get mail-user-agent 'sendfunc)))) |
20345
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
636 |
69818ee01344
(diary-mail-addr, diary-mail-days): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
20269
diff
changeset
|
637 |
13053 | 638 (defun diary-name-pattern (string-array &optional fullname) |
47922
afefa409b756
(diary-name-pattern): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
47163
diff
changeset
|
639 "Convert a STRING-ARRAY, an array of strings to a pattern. |
13053 | 640 The pattern will match any of the strings, either entirely or abbreviated |
641 to three characters. An abbreviated form will match with or without a period; | |
642 If the optional FULLNAME is t, abbreviations will not match, just the full | |
643 name." | |
644 (let ((pattern "")) | |
645 (calendar-for-loop i from 0 to (1- (length string-array)) do | |
646 (setq pattern | |
647 (concat | |
648 pattern | |
649 (if (string-equal pattern "") "" "\\|") | |
650 (aref string-array i) | |
651 (if fullname | |
652 "" | |
653 (concat | |
654 "\\|" | |
655 (substring (aref string-array i) 0 3) ".?"))))) | |
656 pattern)) | |
657 | |
658 (defvar marking-diary-entries nil | |
659 "True during the marking of diary entries, nil otherwise.") | |
660 | |
661 (defvar marking-diary-entry nil | |
662 "True during the marking of diary entries, if current entry is marking.") | |
663 | |
664 (defun mark-diary-entries () | |
665 "Mark days in the calendar window that have diary entries. | |
666 Each entry in the diary file visible in the calendar window is marked. | |
667 After the entries are marked, the hooks `nongregorian-diary-marking-hook' and | |
668 `mark-diary-entries-hook' are run." | |
669 (interactive) | |
670 (setq mark-diary-entries-in-calendar t) | |
671 (let ((d-file (substitute-in-file-name diary-file)) | |
672 (marking-diary-entries t)) | |
673 (if (and d-file (file-exists-p d-file)) | |
674 (if (file-readable-p d-file) | |
675 (save-excursion | |
676 (message "Marking diary entries...") | |
677 (set-buffer (find-file-noselect d-file t)) | |
678 (let ((d diary-date-forms) | |
679 (old-diary-syntax-table)) | |
680 (setq old-diary-syntax-table (syntax-table)) | |
681 (set-syntax-table diary-syntax-table) | |
682 (while d | |
683 (let* | |
684 ((date-form (if (equal (car (car d)) 'backup) | |
685 (cdr (car d)) | |
686 (car d)));; ignore 'backup directive | |
687 (dayname (diary-name-pattern calendar-day-name-array)) | |
688 (monthname | |
689 (concat | |
690 (diary-name-pattern calendar-month-name-array) | |
691 "\\|\\*")) | |
692 (month "[0-9]+\\|\\*") | |
693 (day "[0-9]+\\|\\*") | |
694 (year "[0-9]+\\|\\*") | |
695 (l (length date-form)) | |
696 (d-name-pos (- l (length (memq 'dayname date-form)))) | |
697 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos))) | |
698 (m-name-pos (- l (length (memq 'monthname date-form)))) | |
699 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos))) | |
700 (d-pos (- l (length (memq 'day date-form)))) | |
701 (d-pos (if (/= l d-pos) (+ 2 d-pos))) | |
702 (m-pos (- l (length (memq 'month date-form)))) | |
703 (m-pos (if (/= l m-pos) (+ 2 m-pos))) | |
704 (y-pos (- l (length (memq 'year date-form)))) | |
705 (y-pos (if (/= l y-pos) (+ 2 y-pos))) | |
706 (regexp | |
707 (concat | |
708 "\\(\\`\\|\^M\\|\n\\)\\(" | |
709 (mapconcat 'eval date-form "\\)\\(") | |
710 "\\)")) | |
711 (case-fold-search t)) | |
712 (goto-char (point-min)) | |
713 (while (re-search-forward regexp nil t) | |
714 (let* ((dd-name | |
715 (if d-name-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
716 (buffer-substring-no-properties |
13053 | 717 (match-beginning d-name-pos) |
718 (match-end d-name-pos)))) | |
719 (mm-name | |
720 (if m-name-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
721 (buffer-substring-no-properties |
13053 | 722 (match-beginning m-name-pos) |
723 (match-end m-name-pos)))) | |
724 (mm (string-to-int | |
725 (if m-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
726 (buffer-substring-no-properties |
13053 | 727 (match-beginning m-pos) |
728 (match-end m-pos)) | |
729 ""))) | |
730 (dd (string-to-int | |
731 (if d-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
732 (buffer-substring-no-properties |
13053 | 733 (match-beginning d-pos) |
734 (match-end d-pos)) | |
735 ""))) | |
736 (y-str (if y-pos | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
737 (buffer-substring-no-properties |
13053 | 738 (match-beginning y-pos) |
739 (match-end y-pos)))) | |
740 (yy (if (not y-str) | |
741 0 | |
742 (if (and (= (length y-str) 2) | |
743 abbreviated-calendar-year) | |
744 (let* ((current-y | |
745 (extract-calendar-year | |
746 (calendar-current-date))) | |
747 (y (+ (string-to-int y-str) | |
748 (* 100 | |
749 (/ current-y 100))))) | |
750 (if (> (- y current-y) 50) | |
751 (- y 100) | |
752 (if (> (- current-y y) 50) | |
753 (+ y 100) | |
754 y))) | |
755 (string-to-int y-str))))) | |
756 (if dd-name | |
757 (mark-calendar-days-named | |
24192
1baa5a4968b2
(mark-diary-entries): Use assoc-ignore-case and do not capitalize when
Richard M. Stallman <rms@gnu.org>
parents:
23998
diff
changeset
|
758 (cdr (assoc-ignore-case |
1baa5a4968b2
(mark-diary-entries): Use assoc-ignore-case and do not capitalize when
Richard M. Stallman <rms@gnu.org>
parents:
23998
diff
changeset
|
759 (substring dd-name 0 3) |
1baa5a4968b2
(mark-diary-entries): Use assoc-ignore-case and do not capitalize when
Richard M. Stallman <rms@gnu.org>
parents:
23998
diff
changeset
|
760 (calendar-make-alist |
1baa5a4968b2
(mark-diary-entries): Use assoc-ignore-case and do not capitalize when
Richard M. Stallman <rms@gnu.org>
parents:
23998
diff
changeset
|
761 calendar-day-name-array |
1baa5a4968b2
(mark-diary-entries): Use assoc-ignore-case and do not capitalize when
Richard M. Stallman <rms@gnu.org>
parents:
23998
diff
changeset
|
762 0 |
28615
4c6883cb70ab
(fancy-diary-display, mark-diary-entries)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28575
diff
changeset
|
763 (lambda (x) (substring x 0 3)))))) |
13053 | 764 (if mm-name |
765 (if (string-equal mm-name "*") | |
766 (setq mm 0) | |
767 (setq mm | |
24192
1baa5a4968b2
(mark-diary-entries): Use assoc-ignore-case and do not capitalize when
Richard M. Stallman <rms@gnu.org>
parents:
23998
diff
changeset
|
768 (cdr (assoc-ignore-case |
1baa5a4968b2
(mark-diary-entries): Use assoc-ignore-case and do not capitalize when
Richard M. Stallman <rms@gnu.org>
parents:
23998
diff
changeset
|
769 (substring mm-name 0 3) |
13053 | 770 (calendar-make-alist |
771 calendar-month-name-array | |
772 1 | |
28615
4c6883cb70ab
(fancy-diary-display, mark-diary-entries)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28575
diff
changeset
|
773 (lambda (x) (substring x 0 3))) |
13053 | 774 ))))) |
775 (mark-calendar-date-pattern mm dd yy)))) | |
776 (setq d (cdr d)))) | |
777 (mark-sexp-diary-entries) | |
778 (run-hooks 'nongregorian-diary-marking-hook | |
779 'mark-diary-entries-hook) | |
780 (set-syntax-table old-diary-syntax-table) | |
781 (message "Marking diary entries...done"))) | |
782 (error "Your diary file is not readable!")) | |
783 (error "You don't have a diary file!")))) | |
784 | |
785 (defun mark-sexp-diary-entries () | |
786 "Mark days in the calendar window that have sexp diary entries. | |
787 Each entry in the diary file (or included files) visible in the calendar window | |
788 is marked. See the documentation for the function `list-sexp-diary-entries'." | |
789 (let* ((sexp-mark (regexp-quote sexp-diary-entry-symbol)) | |
790 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)\\(" | |
791 (regexp-quote sexp-mark) "(\\)\\|\\(" | |
792 (regexp-quote diary-nonmarking-symbol) | |
793 (regexp-quote sexp-mark) "(diary-remind\\)")) | |
794 (m) | |
795 (y) | |
796 (first-date) | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
797 (last-date) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
798 (mark)) |
13053 | 799 (save-excursion |
800 (set-buffer calendar-buffer) | |
801 (setq m displayed-month) | |
802 (setq y displayed-year)) | |
803 (increment-calendar-month m y -1) | |
804 (setq first-date | |
805 (calendar-absolute-from-gregorian (list m 1 y))) | |
806 (increment-calendar-month m y 2) | |
807 (setq last-date | |
808 (calendar-absolute-from-gregorian | |
809 (list m (calendar-last-day-of-month m y) y))) | |
810 (goto-char (point-min)) | |
811 (while (re-search-forward s-entry nil t) | |
13075
8a67628f4574
(mark-sexp-diary-entries): Add \ for C-M-f's sake.
Richard M. Stallman <rms@gnu.org>
parents:
13053
diff
changeset
|
812 (if (char-equal (preceding-char) ?\() |
13053 | 813 (setq marking-diary-entry t) |
814 (setq marking-diary-entry nil)) | |
815 (re-search-backward "(") | |
816 (let ((sexp-start (point)) | |
817 (sexp) | |
818 (entry) | |
819 (entry-start) | |
820 (line-start)) | |
821 (forward-sexp) | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
822 (setq sexp (buffer-substring-no-properties sexp-start (point))) |
13053 | 823 (save-excursion |
824 (re-search-backward "\^M\\|\n\\|\\`") | |
825 (setq line-start (point))) | |
826 (forward-char 1) | |
827 (if (and (or (char-equal (preceding-char) ?\^M) | |
828 (char-equal (preceding-char) ?\n)) | |
829 (not (looking-at " \\|\^I"))) | |
830 (progn;; Diary entry consists only of the sexp | |
831 (backward-char 1) | |
832 (setq entry "")) | |
833 (setq entry-start (point)) | |
23247
1f91824c4087
(mark-sexp-diary-entries): Fix previous chg.
Karl Heuer <kwzh@gnu.org>
parents:
23232
diff
changeset
|
834 ;; Find end of entry |
13053 | 835 (re-search-forward "\^M\\|\n" nil t) |
836 (while (looking-at " \\|\^I") | |
23232
97332957a969
(mark-sexp-diary-entries): Avoid infinite loop when
Karl Heuer <kwzh@gnu.org>
parents:
23122
diff
changeset
|
837 (or (re-search-forward "\^M\\|\n" nil t) |
97332957a969
(mark-sexp-diary-entries): Avoid infinite loop when
Karl Heuer <kwzh@gnu.org>
parents:
23122
diff
changeset
|
838 (re-search-forward "$" nil t))) |
23247
1f91824c4087
(mark-sexp-diary-entries): Fix previous chg.
Karl Heuer <kwzh@gnu.org>
parents:
23232
diff
changeset
|
839 (if (or (char-equal (preceding-char) ?\^M) |
1f91824c4087
(mark-sexp-diary-entries): Fix previous chg.
Karl Heuer <kwzh@gnu.org>
parents:
23232
diff
changeset
|
840 (char-equal (preceding-char) ?\n)) |
1f91824c4087
(mark-sexp-diary-entries): Fix previous chg.
Karl Heuer <kwzh@gnu.org>
parents:
23232
diff
changeset
|
841 (backward-char 1)) |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
842 (setq entry (buffer-substring-no-properties entry-start (point))) |
13053 | 843 (while (string-match "[\^M]" entry) |
844 (aset entry (match-beginning 0) ?\n ))) | |
845 (calendar-for-loop date from first-date to last-date do | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
846 (if (setq mark (diary-sexp-entry sexp entry |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
847 (calendar-gregorian-from-absolute date))) |
13053 | 848 (mark-visible-calendar-date |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
849 (calendar-gregorian-from-absolute date) |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
850 (if (consp mark) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
851 (car mark))))))))) |
13053 | 852 |
853 (defun mark-included-diary-files () | |
854 "Mark the diary entries from other diary files with those of the diary file. | |
855 This function is suitable for use as the `mark-diary-entries-hook'; it enables | |
856 you to use shared diary files together with your own. The files included are | |
857 specified in the diary-file by lines of this form: | |
858 #include \"filename\" | |
859 This is recursive; that is, #include directives in diary files thus included | |
860 are obeyed. You can change the `#include' to some other string by | |
861 changing the variable `diary-include-string'." | |
862 (goto-char (point-min)) | |
863 (while (re-search-forward | |
864 (concat | |
865 "\\(\\`\\|\^M\\|\n\\)" | |
866 (regexp-quote diary-include-string) | |
867 " \"\\([^\"]*\\)\"") | |
868 nil t) | |
869 (let ((diary-file (substitute-in-file-name | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
870 (buffer-substring-no-properties |
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
871 (match-beginning 2) (match-end 2)))) |
13053 | 872 (mark-diary-entries-hook 'mark-included-diary-files)) |
873 (if (file-exists-p diary-file) | |
874 (if (file-readable-p diary-file) | |
875 (progn | |
876 (mark-diary-entries) | |
13877
44149f0bf44a
Replaced all uses of get-file-buffer with find-buffer-visiting.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13688
diff
changeset
|
877 (kill-buffer (find-buffer-visiting diary-file))) |
13053 | 878 (beep) |
879 (message "Can't read included diary file %s" diary-file) | |
880 (sleep-for 2)) | |
881 (beep) | |
882 (message "Can't find included diary file %s" diary-file) | |
883 (sleep-for 2)))) | |
884 (goto-char (point-min))) | |
885 | |
886 (defun mark-calendar-days-named (dayname) | |
887 "Mark all dates in the calendar window that are day DAYNAME of the week. | |
888 0 means all Sundays, 1 means all Mondays, and so on." | |
889 (save-excursion | |
890 (set-buffer calendar-buffer) | |
891 (let ((prev-month displayed-month) | |
892 (prev-year displayed-year) | |
893 (succ-month displayed-month) | |
894 (succ-year displayed-year) | |
895 (last-day) | |
896 (day)) | |
897 (increment-calendar-month succ-month succ-year 1) | |
898 (increment-calendar-month prev-month prev-year -1) | |
899 (setq day (calendar-absolute-from-gregorian | |
900 (calendar-nth-named-day 1 dayname prev-month prev-year))) | |
901 (setq last-day (calendar-absolute-from-gregorian | |
902 (calendar-nth-named-day -1 dayname succ-month succ-year))) | |
903 (while (<= day last-day) | |
904 (mark-visible-calendar-date (calendar-gregorian-from-absolute day)) | |
905 (setq day (+ day 7)))))) | |
906 | |
907 (defun mark-calendar-date-pattern (month day year) | |
908 "Mark all dates in the calendar window that conform to MONTH/DAY/YEAR. | |
909 A value of 0 in any position is a wildcard." | |
910 (save-excursion | |
911 (set-buffer calendar-buffer) | |
912 (let ((m displayed-month) | |
913 (y displayed-year)) | |
914 (increment-calendar-month m y -1) | |
915 (calendar-for-loop i from 0 to 2 do | |
916 (mark-calendar-month m y month day year) | |
917 (increment-calendar-month m y 1))))) | |
918 | |
919 (defun mark-calendar-month (month year p-month p-day p-year) | |
920 "Mark dates in the MONTH/YEAR that conform to pattern P-MONTH/P_DAY/P-YEAR. | |
921 A value of 0 in any position of the pattern is a wildcard." | |
922 (if (or (and (= month p-month) | |
923 (or (= p-year 0) (= year p-year))) | |
924 (and (= p-month 0) | |
925 (or (= p-year 0) (= year p-year)))) | |
926 (if (= p-day 0) | |
927 (calendar-for-loop | |
928 i from 1 to (calendar-last-day-of-month month year) do | |
929 (mark-visible-calendar-date (list month i year))) | |
930 (mark-visible-calendar-date (list month p-day year))))) | |
931 | |
932 (defun sort-diary-entries () | |
933 "Sort the list of diary entries by time of day." | |
934 (setq diary-entries-list (sort diary-entries-list 'diary-entry-compare))) | |
935 | |
936 (defun diary-entry-compare (e1 e2) | |
937 "Returns t if E1 is earlier than E2." | |
938 (or (calendar-date-compare e1 e2) | |
939 (and (calendar-date-equal (car e1) (car e2)) | |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
940 (let* ((ts1 (cadr e1)) (t1 (diary-entry-time ts1)) |
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
941 (ts2 (cadr e2)) (t2 (diary-entry-time ts2))) |
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
942 (or (< t1 t2) |
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
943 (and (= t1 t2) |
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
944 (string-lessp ts1 ts2))))))) |
13053 | 945 |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
946 (defcustom diary-unknown-time |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
947 -9999 |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
948 "*Value returned by diary-entry-time when no time is found. |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
949 The default value -9999 causes entries with no recognizable time to be placed |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
950 before those with times; 9999 would place entries with no recognizable time |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
951 after those with times." |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
952 :type 'integer |
21669
9861518505cb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21668
diff
changeset
|
953 :group 'diary |
9861518505cb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21668
diff
changeset
|
954 :version "20.3") |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
955 |
13053 | 956 (defun diary-entry-time (s) |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
957 "Return time at the beginning of the string S as a military-style integer. |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
958 For example, returns 1325 for 1:25pm. |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
959 Returns `diary-unknown-time' (default value -9999) if no time is recognized. The recognized forms are XXXX, X:XX, or |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
960 XX:XX (military time), and XXam, XXAM, XXpm, XXPM, XX:XXam, XX:XXAM XX:XXpm, |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
961 or XX:XXPM." |
19324
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
962 (let ((case-fold-search nil)) |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
963 (cond ((string-match ; Military time |
34036
c2a8edb5b5ec
(diary-entry-time): Anchor pattern correctly
Gerd Moellmann <gerd@gnu.org>
parents:
32415
diff
changeset
|
964 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\):?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)" s) |
19324
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
965 (+ (* 100 (string-to-int |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
966 (substring s (match-beginning 1) (match-end 1)))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
967 (string-to-int (substring s (match-beginning 2) (match-end 2))))) |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
968 ((string-match ; Hour only XXam or XXpm |
34036
c2a8edb5b5ec
(diary-entry-time): Anchor pattern correctly
Gerd Moellmann <gerd@gnu.org>
parents:
32415
diff
changeset
|
969 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s) |
19324
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
970 (+ (* 100 (% (string-to-int |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
971 (substring s (match-beginning 1) (match-end 1))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
972 12)) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
973 (if (equal ?a (downcase (aref s (match-beginning 2)))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
974 0 1200))) |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
975 ((string-match ; Hour and minute XX:XXam or XX:XXpm |
34036
c2a8edb5b5ec
(diary-entry-time): Anchor pattern correctly
Gerd Moellmann <gerd@gnu.org>
parents:
32415
diff
changeset
|
976 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\):\\([0-9][0-9]\\)\\([ap]\\)m\\>" s) |
19324
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
977 (+ (* 100 (% (string-to-int |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
978 (substring s (match-beginning 1) (match-end 1))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
979 12)) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
980 (string-to-int (substring s (match-beginning 2) (match-end 2))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
981 (if (equal ?a (downcase (aref s (match-beginning 3)))) |
02a8fe146fa6
(diary-entry-time): Bind case-fold-search to nil.
Richard M. Stallman <rms@gnu.org>
parents:
18922
diff
changeset
|
982 0 1200))) |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
983 (t diary-unknown-time)))) ; Unrecognizable |
34036
c2a8edb5b5ec
(diary-entry-time): Anchor pattern correctly
Gerd Moellmann <gerd@gnu.org>
parents:
32415
diff
changeset
|
984 |
13053 | 985 (defun list-sexp-diary-entries (date) |
986 "Add sexp entries for DATE from the diary file to `diary-entries-list'. | |
987 Also, Make them visible in the diary file. Returns t if any entries were | |
988 found. | |
989 | |
990 Sexp diary entries must be prefaced by a `sexp-diary-entry-symbol' (normally | |
991 `%%'). The form of a sexp diary entry is | |
992 | |
993 %%(SEXP) ENTRY | |
994 | |
995 Both ENTRY and DATE are globally available when the SEXP is evaluated. If the | |
996 SEXP yields the value nil, the diary entry does not apply. If it yields a | |
997 non-nil value, ENTRY will be taken to apply to DATE; if the non-nil value is a | |
998 string, that string will be the diary entry in the fancy diary display. | |
999 | |
1000 For example, the following diary entry will apply to the 21st of the month | |
1001 if it is a weekday and the Friday before if the 21st is on a weekend: | |
1002 | |
1003 &%%(let ((dayname (calendar-day-of-week date)) | |
1004 (day (extract-calendar-day date))) | |
1005 (or | |
1006 (and (= day 21) (memq dayname '(1 2 3 4 5))) | |
1007 (and (memq day '(19 20)) (= dayname 5))) | |
1008 ) UIUC pay checks deposited | |
1009 | |
1010 A number of built-in functions are available for this type of diary entry: | |
1011 | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1012 %%(diary-date MONTH DAY YEAR &optional MARK) text |
13053 | 1013 Entry applies if date is MONTH, DAY, YEAR if |
1014 `european-calendar-style' is nil, and DAY, MONTH, YEAR if | |
1015 `european-calendar-style' is t. DAY, MONTH, and YEAR | |
1016 can be lists of integers, the constant t, or an integer. | |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1017 The constant t means all values. An optional parameter |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1018 MARK specifies a face or single-character string to use |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1019 when highlighting the day in the calendar. |
13053 | 1020 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1021 %%(diary-float MONTH DAYNAME N &optional DAY MARK) text |
13053 | 1022 Entry will appear on the Nth DAYNAME of MONTH. |
1023 (DAYNAME=0 means Sunday, 1 means Monday, and so on; | |
1024 if N is negative it counts backward from the end of | |
1025 the month. MONTH can be a list of months, a single | |
17892
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1026 month, or t to specify all months. Optional DAY means |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1027 Nth DAYNAME of MONTH on or after/before DAY. DAY defaults |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1028 to 1 if N>0 and the last day of the month if N<0. An |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1029 optional parameter MARK specifies a face or single-character |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1030 string to use when highlighting the day in the calendar. |
13053 | 1031 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1032 %%(diary-block M1 D1 Y1 M2 D2 Y2 &optional MARK) text |
13053 | 1033 Entry will appear on dates between M1/D1/Y1 and M2/D2/Y2, |
1034 inclusive. (If `european-calendar-style' is t, the | |
1035 order of the parameters should be changed to D1, M1, Y1, | |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1036 D2, M2, Y2.) An optional parameter MARK specifies a face |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1037 or single-character string to use when highlighting the |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1038 day in the calendar. |
13053 | 1039 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1040 %%(diary-anniversary MONTH DAY YEAR &optional MARK) text |
13053 | 1041 Entry will appear on anniversary dates of MONTH DAY, YEAR. |
1042 (If `european-calendar-style' is t, the order of the | |
1043 parameters should be changed to DAY, MONTH, YEAR.) Text | |
1044 can contain %d or %d%s; %d will be replaced by the number | |
1045 of years since the MONTH DAY, YEAR and %s will be replaced | |
1046 by the ordinal ending of that number (that is, `st', `nd', | |
1047 `rd' or `th', as appropriate. The anniversary of February | |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1048 29 is considered to be March 1 in a non-leap year. An |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1049 optional parameter MARK specifies a face or single-character |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1050 string to use when highlighting the day in the calendar. |
13053 | 1051 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1052 %%(diary-cyclic N MONTH DAY YEAR &optional MARK) text |
13053 | 1053 Entry will appear every N days, starting MONTH DAY, YEAR. |
1054 (If `european-calendar-style' is t, the order of the | |
1055 parameters should be changed to N, DAY, MONTH, YEAR.) Text | |
1056 can contain %d or %d%s; %d will be replaced by the number | |
1057 of repetitions since the MONTH DAY, YEAR and %s will | |
1058 be replaced by the ordinal ending of that number (that is, | |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1059 `st', `nd', `rd' or `th', as appropriate. An optional |
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1060 parameter MARK specifies a face or single-character string |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1061 to use when highlighting the day in the calendar. |
13053 | 1062 |
1063 %%(diary-remind SEXP DAYS &optional MARKING) text | |
1064 Entry is a reminder for diary sexp SEXP. DAYS is either a | |
1065 single number or a list of numbers indicating the number(s) | |
1066 of days before the event that the warning(s) should occur. | |
1067 If the current date is (one of) DAYS before the event | |
1068 indicated by EXPR, then a suitable message (as specified | |
1069 by `diary-remind-message') appears. In addition to the | |
1070 reminders beforehand, the diary entry also appears on | |
1071 the date itself. If optional MARKING is non-nil then the | |
1072 *reminders* are marked on the calendar. Marking of | |
1073 reminders is independent of whether the entry *itself* is | |
1074 a marking or nonmarking one. | |
1075 | |
1076 %%(diary-day-of-year) | |
1077 Diary entries giving the day of the year and the number of | |
1078 days remaining in the year will be made every day. Note | |
1079 that since there is no text, it makes sense only if the | |
1080 fancy diary display is used. | |
1081 | |
1082 %%(diary-iso-date) | |
1083 Diary entries giving the corresponding ISO commercial date | |
1084 will be made every day. Note that since there is no text, | |
1085 it makes sense only if the fancy diary display is used. | |
1086 | |
1087 %%(diary-french-date) | |
1088 Diary entries giving the corresponding French Revolutionary | |
1089 date will be made every day. Note that since there is no | |
1090 text, it makes sense only if the fancy diary display is used. | |
1091 | |
1092 %%(diary-islamic-date) | |
1093 Diary entries giving the corresponding Islamic date will be | |
1094 made every day. Note that since there is no text, it | |
1095 makes sense only if the fancy diary display is used. | |
1096 | |
1097 %%(diary-hebrew-date) | |
1098 Diary entries giving the corresponding Hebrew date will be | |
1099 made every day. Note that since there is no text, it | |
1100 makes sense only if the fancy diary display is used. | |
1101 | |
1102 %%(diary-astro-day-number) Diary entries giving the corresponding | |
1103 astronomical (Julian) day number will be made every day. | |
1104 Note that since there is no text, it makes sense only if the | |
1105 fancy diary display is used. | |
1106 | |
1107 %%(diary-julian-date) Diary entries giving the corresponding | |
1108 Julian date will be made every day. Note that since | |
1109 there is no text, it makes sense only if the fancy diary | |
1110 display is used. | |
1111 | |
1112 %%(diary-sunrise-sunset) | |
1113 Diary entries giving the local times of sunrise and sunset | |
1114 will be made every day. Note that since there is no text, | |
1115 it makes sense only if the fancy diary display is used. | |
1116 Floating point required. | |
1117 | |
1118 %%(diary-phases-of-moon) | |
1119 Diary entries giving the times of the phases of the moon | |
1120 will be when appropriate. Note that since there is no text, | |
1121 it makes sense only if the fancy diary display is used. | |
1122 Floating point required. | |
1123 | |
1124 %%(diary-yahrzeit MONTH DAY YEAR) text | |
1125 Text is assumed to be the name of the person; the date is | |
1126 the date of death on the *civil* calendar. The diary entry | |
1127 will appear on the proper Hebrew-date anniversary and on the | |
1128 day before. (If `european-calendar-style' is t, the order | |
1129 of the parameters should be changed to DAY, MONTH, YEAR.) | |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
1130 |
13053 | 1131 %%(diary-rosh-hodesh) |
1132 Diary entries will be made on the dates of Rosh Hodesh on | |
1133 the Hebrew calendar. Note that since there is no text, it | |
1134 makes sense only if the fancy diary display is used. | |
1135 | |
1136 %%(diary-parasha) | |
1137 Diary entries giving the weekly parasha will be made on | |
1138 every Saturday. Note that since there is no text, it | |
1139 makes sense only if the fancy diary display is used. | |
1140 | |
1141 %%(diary-omer) | |
1142 Diary entries giving the omer count will be made every day | |
13670
15c441f6d41a
(list-sexp-diary-entries): Doc fix.
Paul Eggert <eggert@twinsun.com>
parents:
13650
diff
changeset
|
1143 from Passover to Shavuot. Note that since there is no text, |
13053 | 1144 it makes sense only if the fancy diary display is used. |
1145 | |
1146 Marking these entries is *extremely* time consuming, so these entries are | |
1147 best if they are nonmarking." | |
1148 (let* ((mark (regexp-quote diary-nonmarking-symbol)) | |
1149 (sexp-mark (regexp-quote sexp-diary-entry-symbol)) | |
1150 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)" mark "?" sexp-mark "(")) | |
1151 (entry-found)) | |
1152 (goto-char (point-min)) | |
1153 (while (re-search-forward s-entry nil t) | |
1154 (backward-char 1) | |
1155 (let ((sexp-start (point)) | |
1156 (sexp) | |
1157 (entry) | |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
1158 (specifier) |
13053 | 1159 (entry-start) |
1160 (line-start)) | |
1161 (forward-sexp) | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
1162 (setq sexp (buffer-substring-no-properties sexp-start (point))) |
13053 | 1163 (save-excursion |
1164 (re-search-backward "\^M\\|\n\\|\\`") | |
1165 (setq line-start (point))) | |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
1166 (setq specifier |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
1167 (buffer-substring-no-properties (1+ line-start) (point))) |
13053 | 1168 (forward-char 1) |
1169 (if (and (or (char-equal (preceding-char) ?\^M) | |
1170 (char-equal (preceding-char) ?\n)) | |
1171 (not (looking-at " \\|\^I"))) | |
1172 (progn;; Diary entry consists only of the sexp | |
1173 (backward-char 1) | |
1174 (setq entry "")) | |
1175 (setq entry-start (point)) | |
1176 (re-search-forward "\^M\\|\n" nil t) | |
1177 (while (looking-at " \\|\^I") | |
1178 (re-search-forward "\^M\\|\n" nil t)) | |
1179 (backward-char 1) | |
13687
9a985bcde00e
Chnaged all occurrences of buffer-substring to buffer-substring-no-properties.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13670
diff
changeset
|
1180 (setq entry (buffer-substring-no-properties entry-start (point))) |
13053 | 1181 (while (string-match "[\^M]" entry) |
1182 (aset entry (match-beginning 0) ?\n ))) | |
1183 (let ((diary-entry (diary-sexp-entry sexp entry date))) | |
1184 (if diary-entry | |
1185 (subst-char-in-region line-start (point) ?\^M ?\n t)) | |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1186 (add-to-diary-list date |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1187 (if (consp diary-entry) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1188 (cdr diary-entry) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1189 diary-entry) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1190 specifier) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1191 (setq entry-found (or entry-found diary-entry))))) |
13053 | 1192 entry-found)) |
1193 | |
1194 (defun diary-sexp-entry (sexp entry date) | |
1195 "Process a SEXP diary ENTRY for DATE." | |
1196 (let ((result (if calendar-debug-sexp | |
1197 (let ((stack-trace-on-error t)) | |
1198 (eval (car (read-from-string sexp)))) | |
1199 (condition-case nil | |
1200 (eval (car (read-from-string sexp))) | |
1201 (error | |
1202 (beep) | |
1203 (message "Bad sexp at line %d in %s: %s" | |
1204 (save-excursion | |
1205 (save-restriction | |
1206 (narrow-to-region 1 (point)) | |
1207 (goto-char (point-min)) | |
1208 (let ((lines 1)) | |
1209 (while (re-search-forward "\n\\|\^M" nil t) | |
1210 (setq lines (1+ lines))) | |
1211 lines))) | |
1212 diary-file sexp) | |
1213 (sleep-for 2)))))) | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1214 (cond ((stringp result) result) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1215 ((and (consp result) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1216 (stringp (cdr result))) result) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1217 (result entry) |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1218 (t nil)))) |
13053 | 1219 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1220 (defun diary-date (month day year &optional mark) |
13053 | 1221 "Specific date(s) diary entry. |
1222 Entry applies if date is MONTH, DAY, YEAR if `european-calendar-style' is nil, | |
1223 and DAY, MONTH, YEAR if `european-calendar-style' is t. DAY, MONTH, and YEAR | |
1224 can be lists of integers, the constant t, or an integer. The constant t means | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1225 all values. |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1226 |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1227 An optional parameter MARK specifies a face or single-character string to |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1228 use when highlighting the day in the calendar." |
13053 | 1229 (let* ((dd (if european-calendar-style |
1230 month | |
1231 day)) | |
1232 (mm (if european-calendar-style | |
1233 day | |
1234 month)) | |
1235 (m (extract-calendar-month date)) | |
1236 (y (extract-calendar-year date)) | |
1237 (d (extract-calendar-day date))) | |
1238 (if (and | |
1239 (or (and (listp dd) (memq d dd)) | |
1240 (equal d dd) | |
1241 (eq dd t)) | |
1242 (or (and (listp mm) (memq m mm)) | |
1243 (equal m mm) | |
1244 (eq mm t)) | |
1245 (or (and (listp year) (memq y year)) | |
1246 (equal y year) | |
1247 (eq year t))) | |
1248 entry))) | |
1249 | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1250 (defun diary-block (m1 d1 y1 m2 d2 y2 &optional mark) |
13053 | 1251 "Block diary entry. |
42513
22938e0c54b2
(diary-block): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41566
diff
changeset
|
1252 Entry applies if date is between, or on one of, two dates. |
22938e0c54b2
(diary-block): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
41566
diff
changeset
|
1253 The order of the parameters is |
23122 | 1254 M1, D1, Y1, M2, D2, Y2 if `european-calendar-style' is nil, and |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1255 D1, M1, Y1, D2, M2, Y2 if `european-calendar-style' is t. |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1256 |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1257 An optional parameter MARK specifies a face or single-character string to |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1258 use when highlighting the day in the calendar." |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1259 |
13053 | 1260 (let ((date1 (calendar-absolute-from-gregorian |
1261 (if european-calendar-style | |
1262 (list d1 m1 y1) | |
1263 (list m1 d1 y1)))) | |
1264 (date2 (calendar-absolute-from-gregorian | |
1265 (if european-calendar-style | |
1266 (list d2 m2 y2) | |
1267 (list m2 d2 y2)))) | |
1268 (d (calendar-absolute-from-gregorian date))) | |
1269 (if (and (<= date1 d) (<= d date2)) | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1270 (cons mark entry)))) |
13053 | 1271 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1272 (defun diary-float (month dayname n &optional day mark) |
13053 | 1273 "Floating diary entry--entry applies if date is the nth dayname of month. |
1274 Parameters are MONTH, DAYNAME, N. MONTH can be a list of months, the constant | |
1275 t, or an integer. The constant t means all months. If N is negative, count | |
17892
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1276 backward from the end of the month. |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1277 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1278 An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY. |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1279 Optional MARK specifies a face or single-character string to use when |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1280 highlighting the day in the calendar." |
17892
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1281 ;; This is messy because the diary entry may apply, but the date on which it |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1282 ;; is based can be in a different month/year. For example, asking for the |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1283 ;; first Monday after December 30. For large values of |n| the problem is |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1284 ;; more grotesque. |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1285 (and (= dayname (calendar-day-of-week date)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1286 (let* ((m (extract-calendar-month date)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1287 (d (extract-calendar-day date)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1288 (y (extract-calendar-year date)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1289 (limit; last (n>0) or first (n<0) possible base date for entry |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1290 (calendar-nth-named-absday (- n) dayname m y d)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1291 (last-abs (if (> n 0) limit (+ limit 6))) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1292 (first-abs (if (> n 0) (- limit 6) limit)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1293 (last (calendar-gregorian-from-absolute last-abs)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1294 (first (calendar-gregorian-from-absolute first-abs)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1295 ; m1, d1 is first possible base date |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1296 (m1 (extract-calendar-month first)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1297 (d1 (extract-calendar-day first)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1298 (y1 (extract-calendar-year first)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1299 ; m2, d2 is last possible base date |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1300 (m2 (extract-calendar-month last)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1301 (d2 (extract-calendar-day last)) |
b3514551f08d
(diary-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17626
diff
changeset
|
1302 (y2 (extract-calendar-year last))) |
23908
2a56bdf4cef7
(diary-float): Fix end-of-year error and typos in comments.
Karl Heuer <kwzh@gnu.org>
parents:
23247
diff
changeset
|
1303 (if (or (and (= m1 m2) ; only possible base dates in one month |
35500
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1304 (or (eq month t) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1305 (if (listp month) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1306 (memq m1 month) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1307 (= m1 month))) |
18590
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1308 (let ((d (or day (if (> n 0) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1309 1 |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1310 (calendar-last-day-of-month m1 y1))))) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1311 (and (<= d1 d) (<= d d2)))) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1312 ;; only possible base dates straddle two months |
23998
6a6bb17fba97
(diary-float): Better fix of end-of-year error.
Richard M. Stallman <rms@gnu.org>
parents:
23908
diff
changeset
|
1313 (and (or (< y1 y2) |
6a6bb17fba97
(diary-float): Better fix of end-of-year error.
Richard M. Stallman <rms@gnu.org>
parents:
23908
diff
changeset
|
1314 (and (= y1 y2) (< m1 m2))) |
18590
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1315 (or |
23908
2a56bdf4cef7
(diary-float): Fix end-of-year error and typos in comments.
Karl Heuer <kwzh@gnu.org>
parents:
23247
diff
changeset
|
1316 ;; m1, d1 works as a base date |
18590
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1317 (and |
35500
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1318 (or (eq month t) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1319 (if (listp month) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1320 (memq m1 month) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1321 (= m1 month))) |
18590
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1322 (<= d1 (or day (if (> n 0) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1323 1 |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1324 (calendar-last-day-of-month m1 y1))))) |
23908
2a56bdf4cef7
(diary-float): Fix end-of-year error and typos in comments.
Karl Heuer <kwzh@gnu.org>
parents:
23247
diff
changeset
|
1325 ;; m2, d2 works as a base date |
35500
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1326 (and (or (eq month t) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1327 (if (listp month) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1328 (memq m2 month) |
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1329 (= m2 month))) |
18590
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1330 (<= (or day (if (> n 0) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1331 1 |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1332 (calendar-last-day-of-month m2 y2))) |
7d2a26d2371d
(diary-float): Fix errors in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17892
diff
changeset
|
1333 d2))))) |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1334 (cons mark entry))))) |
13053 | 1335 |
35500
38b437f4134e
(diary-float): Fix case of MONTH
Gerd Moellmann <gerd@gnu.org>
parents:
34036
diff
changeset
|
1336 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1337 (defun diary-anniversary (month day year &optional mark) |
13053 | 1338 "Anniversary diary entry. |
1339 Entry applies if date is the anniversary of MONTH, DAY, YEAR if | |
1340 `european-calendar-style' is nil, and DAY, MONTH, YEAR if | |
1341 `european-calendar-style' is t. Diary entry can contain `%d' or `%d%s'; the | |
1342 %d will be replaced by the number of years since the MONTH DAY, YEAR and the | |
1343 %s will be replaced by the ordinal ending of that number (that is, `st', `nd', | |
1344 `rd' or `th', as appropriate. The anniversary of February 29 is considered | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1345 to be March 1 in non-leap years. |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1346 |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1347 An optional parameter MARK specifies a face or single-character string to |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1348 use when highlighting the day in the calendar." |
13053 | 1349 (let* ((d (if european-calendar-style |
1350 month | |
1351 day)) | |
1352 (m (if european-calendar-style | |
1353 day | |
1354 month)) | |
1355 (y (extract-calendar-year date)) | |
1356 (diff (- y year))) | |
1357 (if (and (= m 2) (= d 29) (not (calendar-leap-year-p y))) | |
1358 (setq m 3 | |
1359 d 1)) | |
1360 (if (and (> diff 0) (calendar-date-equal (list m d y) date)) | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1361 (cons mark (format entry diff (diary-ordinal-suffix diff)))))) |
13053 | 1362 |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1363 (defun diary-cyclic (n month day year &optional mark) |
13053 | 1364 "Cycle diary entry--entry applies every N days starting at MONTH, DAY, YEAR. |
1365 If `european-calendar-style' is t, parameters are N, DAY, MONTH, YEAR. | |
1366 ENTRY can contain `%d' or `%d%s'; the %d will be replaced by the number of | |
32415
82747626b78b
(diary-cyclic): Doc fix from Ed Reingold.
Gerd Moellmann <gerd@gnu.org>
parents:
28615
diff
changeset
|
1367 repetitions since the MONTH DAY, YEAR and %s will be replaced by the |
82747626b78b
(diary-cyclic): Doc fix from Ed Reingold.
Gerd Moellmann <gerd@gnu.org>
parents:
28615
diff
changeset
|
1368 ordinal ending of that number (that is, `st', `nd', `rd' or `th', as |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1369 appropriate. |
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1370 |
46826
e020f18c490a
(diary-mail-entries): Use `compose-mail'
Sam Steingold <sds@gnu.org>
parents:
46620
diff
changeset
|
1371 An optional parameter MARK specifies a face or single-character string to |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1372 use when highlighting the day in the calendar." |
13053 | 1373 (let* ((d (if european-calendar-style |
1374 month | |
1375 day)) | |
1376 (m (if european-calendar-style | |
1377 day | |
1378 month)) | |
1379 (diff (- (calendar-absolute-from-gregorian date) | |
1380 (calendar-absolute-from-gregorian | |
1381 (list m d year)))) | |
1382 (cycle (/ diff n))) | |
1383 (if (and (>= diff 0) (zerop (% diff n))) | |
46620
f367f20901c0
(mark-sexp-diary-entries): Retrieve mark
Richard M. Stallman <rms@gnu.org>
parents:
44732
diff
changeset
|
1384 (cons mark (format entry cycle (diary-ordinal-suffix cycle)))))) |
13053 | 1385 |
1386 (defun diary-ordinal-suffix (n) | |
1387 "Ordinal suffix for N. (That is, `st', `nd', `rd', or `th', as appropriate.)" | |
1388 (if (or (memq (% n 100) '(11 12 13)) | |
1389 (< 3 (% n 10))) | |
1390 "th" | |
1391 (aref ["th" "st" "nd" "rd"] (% n 10)))) | |
1392 | |
1393 (defun diary-day-of-year () | |
1394 "Day of year and number of days remaining in the year of date diary entry." | |
1395 (calendar-day-of-year-string date)) | |
1396 | |
17626 | 1397 (defcustom diary-remind-message |
13053 | 1398 '("Reminder: Only " |
1399 (if (= 0 (% days 7)) | |
1400 (concat (int-to-string (/ days 7)) (if (= 7 days) " week" " weeks")) | |
1401 (concat (int-to-string days) (if (= 1 days) " day" " days"))) | |
1402 " until " | |
1403 diary-entry) | |
1404 "*Pseudo-pattern giving form of reminder messages in the fancy diary | |
1405 display. | |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
1406 |
13053 | 1407 Used by the function `diary-remind', a pseudo-pattern is a list of |
1408 expressions that can involve the keywords `days' (a number), `date' (a list of | |
17626 | 1409 month, day, year), and `diary-entry' (a string)." |
1410 :type 'sexp | |
1411 :group 'diary) | |
13053 | 1412 |
1413 (defun diary-remind (sexp days &optional marking) | |
1414 "Provide a reminder of a diary entry. | |
1415 SEXP is a diary-sexp. DAYS is either a single number or a list of numbers | |
1416 indicating the number(s) of days before the event that the warning(s) should | |
1417 occur on. If the current date is (one of) DAYS before the event indicated by | |
1418 SEXP, then a suitable message (as specified by `diary-remind-message' is | |
1419 returned. | |
1420 | |
24684
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1421 In addition to the reminders beforehand, the diary entry also appears on the |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1422 date itself. |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1423 |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1424 A `diary-nonmarking-symbol' at the beginning of the line of the diary-remind |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1425 entry specifies that the diary entry (not the reminder) is non-marking. |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1426 Marking of reminders is independent of whether the entry itself is a marking |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1427 or nonmarking; if optional parameter MARKING is non-nil then the reminders are |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1428 marked on the calendar." |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1429 (let ((diary-entry (eval sexp))) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1430 (cond |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1431 ;; Diary entry applies on date |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1432 ((and diary-entry |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1433 (or (not marking-diary-entries) marking-diary-entry)) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1434 diary-entry) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1435 ;; Diary entry may apply to `days' before date |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1436 ((and (integerp days) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1437 (not diary-entry); Diary entry does not apply to date |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1438 (or (not marking-diary-entries) marking)) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1439 (let ((date (calendar-gregorian-from-absolute |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1440 (+ (calendar-absolute-from-gregorian date) days)))) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1441 (if (setq diary-entry (eval sexp)) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1442 (mapconcat 'eval diary-remind-message "")))) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1443 ;; Diary entry may apply to one of a list of days before date |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1444 ((and (listp days) days) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1445 (or (diary-remind sexp (car days) marking) |
cca41b0e7ae7
(diary-remind): Rewritten to behave sensibly for
Karl Heuer <kwzh@gnu.org>
parents:
24192
diff
changeset
|
1446 (diary-remind sexp (cdr days) marking)))))) |
13053 | 1447 |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
1448 (defun add-to-diary-list (date string specifier) |
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
1449 "Add the entry (DATE STRING SPECIFIER) to `diary-entries-list'. |
13053 | 1450 Do nothing if DATE or STRING is nil." |
1451 (and date string | |
39615
4287ce76bf9f
(diary-entry-compare): When times are identical, compare the entries
Sam Steingold <sds@gnu.org>
parents:
38422
diff
changeset
|
1452 (setq diary-entries-list |
20269
ca337d0a1553
(list-diary-entries, list-sexp-diary-entries, add-to-diary-list):
Karl Heuer <kwzh@gnu.org>
parents:
19324
diff
changeset
|
1453 (append diary-entries-list (list (list date string specifier)))))) |
13053 | 1454 |
1455 (defun make-diary-entry (string &optional nonmarking file) | |
1456 "Insert a diary entry STRING which may be NONMARKING in FILE. | |
1457 If omitted, NONMARKING defaults to nil and FILE defaults to diary-file." | |
1458 (find-file-other-window | |
1459 (substitute-in-file-name (if file file diary-file))) | |
1460 (goto-char (point-max)) | |
1461 (insert | |
1462 (if (bolp) "" "\n") | |
1463 (if nonmarking diary-nonmarking-symbol "") | |
1464 string " ")) | |
1465 | |
1466 (defun insert-diary-entry (arg) | |
1467 "Insert a diary entry for the date indicated by point. | |
1468 Prefix arg will make the entry nonmarking." | |
1469 (interactive "P") | |
1470 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t t) | |
1471 arg)) | |
1472 | |
1473 (defun insert-weekly-diary-entry (arg) | |
1474 "Insert a weekly diary entry for the day of the week indicated by point. | |
1475 Prefix arg will make the entry nonmarking." | |
1476 (interactive "P") | |
1477 (make-diary-entry (calendar-day-name (calendar-cursor-to-date t)) | |
1478 arg)) | |
1479 | |
1480 (defun insert-monthly-diary-entry (arg) | |
1481 "Insert a monthly diary entry for the day of the month indicated by point. | |
1482 Prefix arg will make the entry nonmarking." | |
1483 (interactive "P") | |
1484 (let* ((calendar-date-display-form | |
1485 (if european-calendar-style | |
1486 '(day " * ") | |
1487 '("* " day)))) | |
1488 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t) | |
1489 arg))) | |
1490 | |
1491 (defun insert-yearly-diary-entry (arg) | |
1492 "Insert an annual diary entry for the day of the year indicated by point. | |
1493 Prefix arg will make the entry nonmarking." | |
1494 (interactive "P") | |
1495 (let* ((calendar-date-display-form | |
1496 (if european-calendar-style | |
1497 '(day " " monthname) | |
1498 '(monthname " " day)))) | |
1499 (make-diary-entry (calendar-date-string (calendar-cursor-to-date t) t) | |
1500 arg))) | |
1501 | |
1502 (defun insert-anniversary-diary-entry (arg) | |
1503 "Insert an anniversary diary entry for the date given by point. | |
1504 Prefix arg will make the entry nonmarking." | |
1505 (interactive "P") | |
1506 (let* ((calendar-date-display-form | |
1507 (if european-calendar-style | |
1508 '(day " " month " " year) | |
1509 '(month " " day " " year)))) | |
1510 (make-diary-entry | |
1511 (format "%s(diary-anniversary %s)" | |
1512 sexp-diary-entry-symbol | |
1513 (calendar-date-string (calendar-cursor-to-date t) nil t)) | |
1514 arg))) | |
1515 | |
1516 (defun insert-block-diary-entry (arg) | |
1517 "Insert a block diary entry for the days between the point and marked date. | |
1518 Prefix arg will make the entry nonmarking." | |
1519 (interactive "P") | |
1520 (let* ((calendar-date-display-form | |
1521 (if european-calendar-style | |
1522 '(day " " month " " year) | |
1523 '(month " " day " " year))) | |
1524 (cursor (calendar-cursor-to-date t)) | |
1525 (mark (or (car calendar-mark-ring) | |
1526 (error "No mark set in this buffer"))) | |
1527 (start) | |
1528 (end)) | |
1529 (if (< (calendar-absolute-from-gregorian mark) | |
1530 (calendar-absolute-from-gregorian cursor)) | |
1531 (setq start mark | |
1532 end cursor) | |
1533 (setq start cursor | |
1534 end mark)) | |
1535 (make-diary-entry | |
1536 (format "%s(diary-block %s %s)" | |
1537 sexp-diary-entry-symbol | |
1538 (calendar-date-string start nil t) | |
1539 (calendar-date-string end nil t)) | |
1540 arg))) | |
1541 | |
1542 (defun insert-cyclic-diary-entry (arg) | |
1543 "Insert a cyclic diary entry starting at the date given by point. | |
1544 Prefix arg will make the entry nonmarking." | |
1545 (interactive "P") | |
1546 (let* ((calendar-date-display-form | |
1547 (if european-calendar-style | |
1548 '(day " " month " " year) | |
1549 '(month " " day " " year)))) | |
1550 (make-diary-entry | |
1551 (format "%s(diary-cyclic %d %s)" | |
1552 sexp-diary-entry-symbol | |
1553 (calendar-read "Repeat every how many days: " | |
28615
4c6883cb70ab
(fancy-diary-display, mark-diary-entries)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28575
diff
changeset
|
1554 (lambda (x) (> x 0))) |
13053 | 1555 (calendar-date-string (calendar-cursor-to-date t) nil t)) |
1556 arg))) | |
1557 | |
13650 | 1558 (provide 'diary-lib) |
13053 | 1559 |
13650 | 1560 ;;; diary-lib.el ends here |