comparison lisp/calendar/calendar.el @ 31730:719a230f8091

Docstring fixes. (calendar-make-alist): Don't quote lambda. (calendar-star-date): Use make-local-variable.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 19 Sep 2000 15:50:54 +0000
parents 83d51ddd6e3e
children 387b549687a3
comparison
equal deleted inserted replaced
31729:3f1d7c3629aa 31730:719a230f8091
162 :group 'diary) 162 :group 'diary)
163 163
164 ;;;###autoload 164 ;;;###autoload
165 (defcustom number-of-diary-entries 1 165 (defcustom number-of-diary-entries 1
166 "*Specifies how many days of diary entries are to be displayed initially. 166 "*Specifies how many days of diary entries are to be displayed initially.
167 This variable affects the diary display when the command M-x diary is used, 167 This variable affects the diary display when the command \\[diary] is used,
168 or if the value of the variable `view-diary-entries-initially' is t. For 168 or if the value of the variable `view-diary-entries-initially' is t. For
169 example, if the default value 1 is used, then only the current day's diary 169 example, if the default value 1 is used, then only the current day's diary
170 entries will be displayed. If the value 2 is used, then both the current 170 entries will be displayed. If the value 2 is used, then both the current
171 day's and the next day's entries will be displayed. 171 day's and the next day's entries will be displayed.
172 172
487 :type 'string 487 :type 'string
488 :group 'diary) 488 :group 'diary)
489 489
490 ;;;###autoload 490 ;;;###autoload
491 (defcustom sexp-diary-entry-symbol "%%" 491 (defcustom sexp-diary-entry-symbol "%%"
492 "*The string used to indicate a sexp diary entry in diary-file. 492 "*The string used to indicate a sexp diary entry in `diary-file'.
493 See the documentation for the function `list-sexp-diary-entries'." 493 See the documentation for the function `list-sexp-diary-entries'."
494 :type 'string 494 :type 'string
495 :group 'diary) 495 :group 'diary)
496 496
497 ;;;###autoload 497 ;;;###autoload
740 ;;;###autoload 740 ;;;###autoload
741 (defcustom mark-diary-entries-hook nil 741 (defcustom mark-diary-entries-hook nil
742 "*List of functions called after marking diary entries in the calendar. 742 "*List of functions called after marking diary entries in the calendar.
743 743
744 A function `mark-included-diary-files' is also provided for use as the 744 A function `mark-included-diary-files' is also provided for use as the
745 mark-diary-entries-hook; it enables you to use shared diary files together 745 `mark-diary-entries-hook'; it enables you to use shared diary files together
746 with your own. The files included are specified in the diary file by lines 746 with your own. The files included are specified in the diary file by lines
747 of the form 747 of the form
748 #include \"filename\" 748 #include \"filename\"
749 This is recursive; that is, #include directives in files thus included are 749 This is recursive; that is, #include directives in files thus included are
750 obeyed. You can change the \"#include\" to some other string by changing the 750 obeyed. You can change the \"#include\" to some other string by changing the
1034 (put 'calendar-holidays 'risky-local-variable t) 1034 (put 'calendar-holidays 'risky-local-variable t)
1035 (defcustom calendar-holidays 1035 (defcustom calendar-holidays
1036 (append general-holidays local-holidays other-holidays 1036 (append general-holidays local-holidays other-holidays
1037 christian-holidays hebrew-holidays islamic-holidays 1037 christian-holidays hebrew-holidays islamic-holidays
1038 oriental-holidays solar-holidays) 1038 oriental-holidays solar-holidays)
1039 "*List of notable days for the command M-x holidays. 1039 "*List of notable days for the command \\[holidays].
1040 1040
1041 Additional holidays are easy to add to the list, just put them in the list 1041 Additional holidays are easy to add to the list, just put them in the list
1042 `other-holidays' in your .emacs file. Similarly, by setting any of 1042 `other-holidays' in your .emacs file. Similarly, by setting any of
1043 `general-holidays', `local-holidays' `christian-holidays', `hebrew-holidays', 1043 `general-holidays', `local-holidays' `christian-holidays', `hebrew-holidays',
1044 `islamic-holidays', `oriental-holidays', or `solar-holidays' to nil in your 1044 `islamic-holidays', `oriental-holidays', or `solar-holidays' to nil in your
1053 1053
1054 (holiday-fixed MONTH DAY STRING) is a fixed date on the Gregorian calendar 1054 (holiday-fixed MONTH DAY STRING) is a fixed date on the Gregorian calendar
1055 (holiday-float MONTH DAYNAME K STRING &optional day) is the Kth DAYNAME in 1055 (holiday-float MONTH DAYNAME K STRING &optional day) is the Kth DAYNAME in
1056 MONTH on the Gregorian calendar (0 for Sunday, 1056 MONTH on the Gregorian calendar (0 for Sunday,
1057 etc.); K<0 means count back from the end of the 1057 etc.); K<0 means count back from the end of the
1058 month. An optional parameter DAY means the Kth 1058 month. An optional parameter DAY means the Kth
1059 DAYNAME after/before MONTH DAY. 1059 DAYNAME after/before MONTH DAY.
1060 (holiday-hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar 1060 (holiday-hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar
1061 (holiday-islamic MONTH DAY STRING) a fixed date on the Islamic calendar 1061 (holiday-islamic MONTH DAY STRING) a fixed date on the Islamic calendar
1062 (holiday-julian MONTH DAY STRING) a fixed date on the Julian calendar 1062 (holiday-julian MONTH DAY STRING) a fixed date on the Julian calendar
1063 (holiday-sexp SEXP STRING) SEXP is a Gregorian-date-valued expression 1063 (holiday-sexp SEXP STRING) SEXP is a Gregorian-date-valued expression
1203 (defsubst extract-calendar-year (date) 1203 (defsubst extract-calendar-year (date)
1204 "Extract the year part of DATE which has the form (month day year)." 1204 "Extract the year part of DATE which has the form (month day year)."
1205 (car (cdr (cdr date)))) 1205 (car (cdr (cdr date))))
1206 1206
1207 (defsubst calendar-leap-year-p (year) 1207 (defsubst calendar-leap-year-p (year)
1208 "Returns t if YEAR is a Gregorian leap year." 1208 "Return t if YEAR is a Gregorian leap year."
1209 (and (zerop (% year 4)) 1209 (and (zerop (% year 4))
1210 (or (not (zerop (% year 100))) 1210 (or (not (zerop (% year 100)))
1211 (zerop (% year 400))))) 1211 (zerop (% year 400)))))
1212 1212
1213 ;; The foregoing is a bit faster, but not as clear as the following: 1213 ;; The foregoing is a bit faster, but not as clear as the following:
1393 and the minus sign are automatically prefixes. The window is replotted as 1393 and the minus sign are automatically prefixes. The window is replotted as
1394 necessary to display the desired date. 1394 necessary to display the desired date.
1395 1395
1396 Diary entries can be marked on the calendar or displayed in another window. 1396 Diary entries can be marked on the calendar or displayed in another window.
1397 1397
1398 Use M-x describe-mode for details of the key bindings in the calendar window. 1398 Use \\[describe-mode] for details of the key bindings in the calendar window.
1399 1399
1400 The Gregorian calendar is assumed. 1400 The Gregorian calendar is assumed.
1401 1401
1402 After loading the calendar, the hooks given by the variable 1402 After loading the calendar, the hooks given by the variable
1403 `calendar-load-hook' are run. This is the place to add key bindings to the 1403 `calendar-load-hook' are run. This is the place to add key bindings to the
2189 (delete-window window)) 2189 (delete-window window))
2190 (t (set-buffer buffer) 2190 (t (set-buffer buffer)
2191 (bury-buffer)))))) 2191 (bury-buffer))))))
2192 2192
2193 (defun calendar-current-date () 2193 (defun calendar-current-date ()
2194 "Returns the current date in a list (month day year)." 2194 "Return the current date in a list (month day year)."
2195 (let ((now (decode-time))) 2195 (let ((now (decode-time)))
2196 (list (nth 4 now) (nth 3 now) (nth 5 now)))) 2196 (list (nth 4 now) (nth 3 now) (nth 5 now))))
2197 2197
2198 (defun calendar-cursor-to-date (&optional error) 2198 (defun calendar-cursor-to-date (&optional error)
2199 "Returns a list (month day year) of current cursor position. 2199 "Return a list (month day year) of current cursor position.
2200 If cursor is not on a specific date, signals an error if optional parameter 2200 If cursor is not on a specific date, signals an error if optional parameter
2201 ERROR is t, otherwise just returns nil." 2201 ERROR is t, otherwise just returns nil."
2202 (let* ((segment (/ (current-column) 25)) 2202 (let* ((segment (/ (current-column) 25))
2203 (month (% (+ displayed-month segment -1) 12)) 2203 (month (% (+ displayed-month segment -1) 12))
2204 (month (if (= 0 month) 12 month)) 2204 (month (if (= 0 month) 12 month))
2348 (while (not (funcall acceptable value)) 2348 (while (not (funcall acceptable value))
2349 (setq value (read-minibuffer prompt initial-contents))) 2349 (setq value (read-minibuffer prompt initial-contents)))
2350 value)) 2350 value))
2351 2351
2352 (defun calendar-read-date (&optional noday) 2352 (defun calendar-read-date (&optional noday)
2353 "Prompt for Gregorian date. Returns a list (month day year). 2353 "Prompt for Gregorian date. Return a list (month day year).
2354 If optional NODAY is t, does not ask for day, but just returns 2354 If optional NODAY is t, does not ask for day, but just returns
2355 \(month nil year); if NODAY is any other non-nil value the value returned is 2355 \(month nil year); if NODAY is any other non-nil value the value returned is
2356 \(month year) " 2356 \(month year)"
2357 (let* ((year (calendar-read 2357 (let* ((year (calendar-read
2358 "Year (>0): " 2358 "Year (>0): "
2359 (lambda (x) (> x 0)) 2359 (lambda (x) (> x 0))
2360 (int-to-string (extract-calendar-year 2360 (int-to-string (extract-calendar-year
2361 (calendar-current-date))))) 2361 (calendar-current-date)))))
2381 "The number of months difference between MON1, YR1 and MON2, YR2." 2381 "The number of months difference between MON1, YR1 and MON2, YR2."
2382 (+ (* 12 (- yr2 yr1)) 2382 (+ (* 12 (- yr2 yr1))
2383 (- mon2 mon1))) 2383 (- mon2 mon1)))
2384 2384
2385 (defun calendar-day-name (date &optional width absolute) 2385 (defun calendar-day-name (date &optional width absolute)
2386 "Returns a string with the name of the day of the week of DATE. 2386 "Return a string with the name of the day of the week of DATE.
2387 If WIDTH is non-nil, return just the first WIDTH characters of the name. 2387 If WIDTH is non-nil, return just the first WIDTH characters of the name.
2388 If ABSOLUTE is non-nil, then DATE is actually the day-of-the-week 2388 If ABSOLUTE is non-nil, then DATE is actually the day-of-the-week
2389 rather than a date." 2389 rather than a date."
2390 (let ((string (aref calendar-day-name-array 2390 (let ((string (aref calendar-day-name-array
2391 (if absolute date (calendar-day-of-week date))))) 2391 (if absolute date (calendar-day-of-week date)))))
2406 "Make an assoc list corresponding to SEQUENCE. 2406 "Make an assoc list corresponding to SEQUENCE.
2407 Start at index 1, unless optional START-INDEX is provided. 2407 Start at index 1, unless optional START-INDEX is provided.
2408 If FILTER is provided, apply it to each item in the list." 2408 If FILTER is provided, apply it to each item in the list."
2409 (let ((index (if start-index (1- start-index) 0))) 2409 (let ((index (if start-index (1- start-index) 0)))
2410 (mapcar 2410 (mapcar
2411 '(lambda (x) 2411 (lambda (x)
2412 (setq index (1+ index)) 2412 (setq index (1+ index))
2413 (cons (if filter (funcall filter x) x) 2413 (cons (if filter (funcall filter x) x)
2414 index)) 2414 index))
2415 (append sequence nil)))) 2415 (append sequence nil))))
2416 2416
2427 (setq i (1+ i))) 2427 (setq i (1+ i)))
2428 result) 2428 result)
2429 string))) 2429 string)))
2430 2430
2431 (defun calendar-day-of-week (date) 2431 (defun calendar-day-of-week (date)
2432 "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc." 2432 "Return the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc."
2433 (% (calendar-absolute-from-gregorian date) 7)) 2433 (% (calendar-absolute-from-gregorian date) 7))
2434 2434
2435 (defun calendar-unmark () 2435 (defun calendar-unmark ()
2436 "Delete all diary/holiday marks/highlighting from the calendar." 2436 "Delete all diary/holiday marks/highlighting from the calendar."
2437 (interactive) 2437 (interactive)
2438 (setq mark-holidays-in-calendar nil) 2438 (setq mark-holidays-in-calendar nil)
2439 (setq mark-diary-entries-in-calendar nil) 2439 (setq mark-diary-entries-in-calendar nil)
2440 (redraw-calendar)) 2440 (redraw-calendar))
2441 2441
2442 (defun calendar-date-is-visible-p (date) 2442 (defun calendar-date-is-visible-p (date)
2443 "Returns t if DATE is legal and is visible in the calendar window." 2443 "Return t if DATE is legal and is visible in the calendar window."
2444 (let ((gap (calendar-interval 2444 (let ((gap (calendar-interval
2445 displayed-month displayed-year 2445 displayed-month displayed-year
2446 (extract-calendar-month date) (extract-calendar-year date)))) 2446 (extract-calendar-month date) (extract-calendar-year date))))
2447 (and (calendar-date-is-legal-p date) (> 2 gap) (< -2 gap)))) 2447 (and (calendar-date-is-legal-p date) (> 2 gap) (< -2 gap))))
2448 2448
2449 (defun calendar-date-is-legal-p (date) 2449 (defun calendar-date-is-legal-p (date)
2450 "Returns t if DATE is a legal date." 2450 "Return t if DATE is a legal date."
2451 (let ((month (extract-calendar-month date)) 2451 (let ((month (extract-calendar-month date))
2452 (day (extract-calendar-day date)) 2452 (day (extract-calendar-day date))
2453 (year (extract-calendar-year date))) 2453 (year (extract-calendar-year date)))
2454 (and (<= 1 month) (<= month 12) 2454 (and (<= 1 month) (<= month 12)
2455 (<= 1 day) (<= day (calendar-last-day-of-month month year)) 2455 (<= 1 day) (<= day (calendar-last-day-of-month month year))
2456 (<= 1 year)))) 2456 (<= 1 year))))
2457 2457
2458 (defun calendar-date-equal (date1 date2) 2458 (defun calendar-date-equal (date1 date2)
2459 "Returns t if the DATE1 and DATE2 are the same." 2459 "Return t if the DATE1 and DATE2 are the same."
2460 (and 2460 (and
2461 (= (extract-calendar-month date1) (extract-calendar-month date2)) 2461 (= (extract-calendar-month date1) (extract-calendar-month date2))
2462 (= (extract-calendar-day date1) (extract-calendar-day date2)) 2462 (= (extract-calendar-day date1) (extract-calendar-day date2))
2463 (= (extract-calendar-year date1) (extract-calendar-year date2)))) 2463 (= (extract-calendar-year date1) (extract-calendar-year date2))))
2464 2464
2480 (overlay-put 2480 (overlay-put
2481 (make-overlay (1- (point)) (1+ (point))) 'face mark)))))) 2481 (make-overlay (1- (point)) (1+ (point))) 'face mark))))))
2482 2482
2483 (defun calendar-star-date () 2483 (defun calendar-star-date ()
2484 "Replace the date under the cursor in the calendar window with asterisks. 2484 "Replace the date under the cursor in the calendar window with asterisks.
2485 This function can be used with the today-visible-calendar-hook run after the 2485 This function can be used with the `today-visible-calendar-hook' run after the
2486 calendar window has been prepared." 2486 calendar window has been prepared."
2487 (let ((buffer-read-only nil)) 2487 (let ((inhibit-read-only t))
2488 (make-variable-buffer-local 'calendar-starred-day) 2488 (make-local-variable 'calendar-starred-day)
2489 (forward-char 1) 2489 (forward-char 1)
2490 (setq calendar-starred-day 2490 (setq calendar-starred-day
2491 (string-to-int 2491 (string-to-int
2492 (buffer-substring (point) (- (point) 2)))) 2492 (buffer-substring (point) (- (point) 2))))
2493 (delete-char -2) 2493 (delete-char -2)
2496 (set-buffer-modified-p nil))) 2496 (set-buffer-modified-p nil)))
2497 2497
2498 (defun calendar-mark-today () 2498 (defun calendar-mark-today ()
2499 "Mark the date under the cursor in the calendar window. 2499 "Mark the date under the cursor in the calendar window.
2500 The date is marked with calendar-today-marker. This function can be used with 2500 The date is marked with calendar-today-marker. This function can be used with
2501 the today-visible-calendar-hook run after the calendar window has been 2501 the `today-visible-calendar-hook' run after the calendar window has been
2502 prepared." 2502 prepared."
2503 (mark-visible-calendar-date 2503 (mark-visible-calendar-date
2504 (calendar-cursor-to-date) 2504 (calendar-cursor-to-date)
2505 calendar-today-marker)) 2505 calendar-today-marker))
2506 2506
2507 (defun calendar-date-compare (date1 date2) 2507 (defun calendar-date-compare (date1 date2)
2508 "Returns t if DATE1 is before DATE2, nil otherwise. 2508 "Return t if DATE1 is before DATE2, nil otherwise.
2509 The actual dates are in the car of DATE1 and DATE2." 2509 The actual dates are in the car of DATE1 and DATE2."
2510 (< (calendar-absolute-from-gregorian (car date1)) 2510 (< (calendar-absolute-from-gregorian (car date1))
2511 (calendar-absolute-from-gregorian (car date2)))) 2511 (calendar-absolute-from-gregorian (car date2))))
2512 2512
2513 (defun calendar-date-string (date &optional abbreviate nodayname) 2513 (defun calendar-date-string (date &optional abbreviate nodayname)
2530 (month (int-to-string month)) 2530 (month (int-to-string month))
2531 (year (int-to-string (extract-calendar-year date)))) 2531 (year (int-to-string (extract-calendar-year date))))
2532 (mapconcat 'eval calendar-date-display-form ""))) 2532 (mapconcat 'eval calendar-date-display-form "")))
2533 2533
2534 (defun calendar-dayname-on-or-before (dayname date) 2534 (defun calendar-dayname-on-or-before (dayname date)
2535 "Returns the absolute date of the DAYNAME on or before absolute DATE. 2535 "Return the absolute date of the DAYNAME on or before absolute DATE.
2536 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on. 2536 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
2537 2537
2538 Note: Applying this function to d+6 gives us the DAYNAME on or after an 2538 Note: Applying this function to d+6 gives us the DAYNAME on or after an
2539 absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to 2539 absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
2540 absolute date d, applying it to d-1 gives the DAYNAME previous to absolute 2540 absolute date d, applying it to d-1 gives the DAYNAME previous to absolute