comparison lisp/calendar/calendar.el @ 92988:189ca7ef805d

(calendar-mod): Remove. (calendar-for-loop): Add indent spec.
author Glenn Morris <rgm@gnu.org>
date Sun, 16 Mar 2008 01:22:58 +0000
parents bb4fc128d00d
children 8e1a78482251
comparison
equal deleted inserted replaced
92987:fe7a1170342d 92988:189ca7ef805d
105 ;; date, entry: bound in list-sexp-diary-entries (qv) 105 ;; date, entry: bound in list-sexp-diary-entries (qv)
106 106
107 ;; Bound in diary-list-entries: 107 ;; Bound in diary-list-entries:
108 ;; diary-entries-list: use in d-l, appt.el, and by add-to-diary-list 108 ;; diary-entries-list: use in d-l, appt.el, and by add-to-diary-list
109 ;; diary-saved-point: only used in diary-lib.el, passed to the display func 109 ;; diary-saved-point: only used in diary-lib.el, passed to the display func
110 ;; date-string: only used in diary-lib.el FIXME could be removed? 110 ;; date-string: only used in diary-lib.el
111 ;; list-only: don't modify the diary-buffer, just return a list of entries
112 ;; file-glob-attrs: yuck
111 113
112 ;;; Code: 114 ;;; Code:
113 115
114 ;; (elisp) Eval During Compile: "Effectively `require' is 116 ;; (elisp) Eval During Compile: "Effectively `require' is
115 ;; automatically `eval-and-compile'" [but `load' is not] 117 ;; automatically `eval-and-compile'" [but `load' is not]
224 :foreground "yellow") 226 :foreground "yellow")
225 (t 227 (t
226 :weight bold)) 228 :weight bold))
227 "Face for highlighting diary entries." 229 "Face for highlighting diary entries."
228 :group 'diary) 230 :group 'diary)
229 ;; Backward-compatibility alias. FIXME make obsolete. 231 ;; Backward-compatibility alias. FIXME make obsolete.
230 (put 'diary-face 'face-alias 'diary) 232 (put 'diary-face 'face-alias 'diary)
231 233
232 (defface holiday 234 (defface holiday
233 '((((class color) (background light)) 235 '((((class color) (background light))
234 :background "pink") 236 :background "pink")
633 :group 'calendar) 635 :group 'calendar)
634 636
635 (defun european-calendar () 637 (defun european-calendar ()
636 "Set the interpretation and display of dates to the European style." 638 "Set the interpretation and display of dates to the European style."
637 (interactive) 639 (interactive)
638 (setq european-calendar-style t) 640 (setq european-calendar-style t
639 (setq calendar-date-display-form european-calendar-display-form) 641 calendar-date-display-form european-calendar-display-form
640 (setq diary-date-forms european-date-diary-pattern) 642 diary-date-forms european-date-diary-pattern)
641 (update-calendar-mode-line)) 643 (update-calendar-mode-line))
642 644
643 (defun american-calendar () 645 (defun american-calendar ()
644 "Set the interpretation and display of dates to the American style." 646 "Set the interpretation and display of dates to the American style."
645 (interactive) 647 (interactive)
646 (setq european-calendar-style nil) 648 (setq european-calendar-style nil
647 (setq calendar-date-display-form american-calendar-display-form) 649 calendar-date-display-form american-calendar-display-form
648 (setq diary-date-forms american-date-diary-pattern) 650 diary-date-forms american-date-diary-pattern)
649 (update-calendar-mode-line)) 651 (update-calendar-mode-line))
650 652
651 ;; FIXME move to diary-lib and adjust appt. 653 ;; FIXME move to diary-lib and adjust appt.
652 (defcustom diary-hook nil 654 (defcustom diary-hook nil
653 "List of functions called after the display of the diary. 655 "List of functions called after the display of the diary.
1205 1207
1206 (defmacro calendar-for-loop (var from init to final do &rest body) 1208 (defmacro calendar-for-loop (var from init to final do &rest body)
1207 "Execute a for loop. 1209 "Execute a for loop.
1208 Evaluate BODY with VAR bound to successive integers from INIT to FINAL, 1210 Evaluate BODY with VAR bound to successive integers from INIT to FINAL,
1209 inclusive. The standard macro `dotimes' is preferable in most cases." 1211 inclusive. The standard macro `dotimes' is preferable in most cases."
1210 (declare (debug (symbolp "from" form "to" form "do" body))) 1212 (declare (debug (symbolp "from" form "to" form "do" body))
1213 (indent defun))
1211 `(let ((,var (1- ,init))) 1214 `(let ((,var (1- ,init)))
1212 (while (>= ,final (setq ,var (1+ ,var))) 1215 (while (>= ,final (setq ,var (1+ ,var)))
1213 ,@body))) 1216 ,@body)))
1214 1217
1215 (defmacro calendar-sum (index initial condition expression) 1218 (defmacro calendar-sum (index initial condition expression)
1835 (strings (cdr strings)) 1838 (strings (cdr strings))
1836 (i 0)) 1839 (i 0))
1837 (dolist (string strings) 1840 (dolist (string strings)
1838 (setq s (concat s 1841 (setq s (concat s
1839 (make-string (max 0 (/ (+ n i) m)) char) 1842 (make-string (max 0 (/ (+ n i) m)) char)
1840 string)) 1843 string)
1841 (setq i (1+ i))) 1844 i (1+ i)))
1842 (substring s 0 length))) 1845 (substring s 0 length)))
1843 1846
1844 (defun update-calendar-mode-line () 1847 (defun update-calendar-mode-line ()
1845 "Update the calendar mode line with the current date and date style." 1848 "Update the calendar mode line with the current date and date style."
1846 (if (bufferp (get-buffer calendar-buffer)) 1849 (if (bufferp (get-buffer calendar-buffer))
1996 (list month day year))))) 1999 (list month day year)))))
1997 2000
1998 (defun calendar-other-month (month year) 2001 (defun calendar-other-month (month year)
1999 "Display a three-month calendar centered around MONTH and YEAR." 2002 "Display a three-month calendar centered around MONTH and YEAR."
2000 (interactive (calendar-read-date 'noday)) 2003 (interactive (calendar-read-date 'noday))
2001 (if (and (= month displayed-month) 2004 (unless (and (= month displayed-month)
2002 (= year displayed-year)) 2005 (= year displayed-year))
2003 nil
2004 (let ((old-date (calendar-cursor-to-date)) 2006 (let ((old-date (calendar-cursor-to-date))
2005 (today (calendar-current-date))) 2007 (today (calendar-current-date)))
2006 (generate-calendar-window month year) 2008 (generate-calendar-window month year)
2007 (calendar-cursor-to-visible-date 2009 (calendar-cursor-to-visible-date
2008 (cond 2010 (cond
2240 (mod (calendar-absolute-from-gregorian date) 7)) 2242 (mod (calendar-absolute-from-gregorian date) 7))
2241 2243
2242 (defun calendar-unmark () 2244 (defun calendar-unmark ()
2243 "Delete all diary/holiday marks/highlighting from the calendar." 2245 "Delete all diary/holiday marks/highlighting from the calendar."
2244 (interactive) 2246 (interactive)
2245 (setq mark-holidays-in-calendar nil) 2247 (setq mark-holidays-in-calendar nil
2246 (setq mark-diary-entries-in-calendar nil) 2248 mark-diary-entries-in-calendar nil)
2247 (redraw-calendar)) 2249 (redraw-calendar))
2248 2250
2249 (defun calendar-date-is-visible-p (date) 2251 (defun calendar-date-is-visible-p (date)
2250 "Return t if DATE is valid and is visible in the calendar window." 2252 "Return t if DATE is valid and is visible in the calendar window."
2251 (let ((gap (calendar-interval 2253 (let ((gap (calendar-interval
2450 (format "Hebrew date (before sunset): %s\n" 2452 (format "Hebrew date (before sunset): %s\n"
2451 (calendar-hebrew-date-string date)) 2453 (calendar-hebrew-date-string date))
2452 (format "Persian date: %s\n" 2454 (format "Persian date: %s\n"
2453 (calendar-persian-date-string date)) 2455 (calendar-persian-date-string date))
2454 (let ((i (calendar-islamic-date-string date))) 2456 (let ((i (calendar-islamic-date-string date)))
2455 (if (not (string-equal i "")) 2457 (unless (string-equal i "")
2456 (format "Islamic date (before sunset): %s\n" i))) 2458 (format "Islamic date (before sunset): %s\n" i)))
2457 (let ((b (calendar-bahai-date-string date))) 2459 (let ((b (calendar-bahai-date-string date)))
2458 (if (not (string-equal b "")) 2460 (unless (string-equal b "")
2459 (format "Baha'i date (before sunset): %s\n" b))) 2461 (format "Baha'i date (before sunset): %s\n" b)))
2460 (format "Chinese date: %s\n" 2462 (format "Chinese date: %s\n"
2461 (calendar-chinese-date-string date)) 2463 (calendar-chinese-date-string date))
2462 (let ((c (calendar-coptic-date-string date))) 2464 (let ((c (calendar-coptic-date-string date)))
2463 (if (not (string-equal c "")) 2465 (unless (string-equal c "")
2464 (format "Coptic date: %s\n" c))) 2466 (format "Coptic date: %s\n" c)))
2465 (let ((e (calendar-ethiopic-date-string date))) 2467 (let ((e (calendar-ethiopic-date-string date)))
2466 (if (not (string-equal e "")) 2468 (unless (string-equal e "")
2467 (format "Ethiopic date: %s\n" e))) 2469 (format "Ethiopic date: %s\n" e)))
2468 (let ((f (calendar-french-date-string date))) 2470 (let ((f (calendar-french-date-string date)))
2469 (if (not (string-equal f "")) 2471 (unless (string-equal f "")
2470 (format "French Revolutionary date: %s\n" f))) 2472 (format "French Revolutionary date: %s\n" f)))
2471 (format "Mayan date: %s\n" 2473 (format "Mayan date: %s\n"
2472 (calendar-mayan-date-string date))))) 2474 (calendar-mayan-date-string date)))))
2473 (goto-char (point-min)) 2475 (goto-char (point-min))
2474 (restore-buffer-modified-p modified)) 2476 (restore-buffer-modified-p modified))
2475 (display-buffer other-calendars-buffer)))) 2477 (display-buffer other-calendars-buffer))))
2489 `("-" mode-line-modified 2491 `("-" mode-line-modified
2490 ,(calendar-string-spread (list str) ?- (- width 6)) 2492 ,(calendar-string-spread (list str) ?- (- width 6))
2491 "---") 2493 "---")
2492 (calendar-string-spread (list str) ?- width))))) 2494 (calendar-string-spread (list str) ?- width)))))
2493 2495
2494 (defun calendar-mod (m n)
2495 "Non-negative remainder of M/N with N instead of 0."
2496 (1+ (mod (1- m) n)))
2497
2498
2499 (defun calendar-version () 2496 (defun calendar-version ()
2500 "Display the Calendar version." 2497 "Display the Calendar version."
2501 (interactive) 2498 (interactive)
2502 (message "GNU Emacs %s" emacs-version)) 2499 (message "GNU Emacs %s" emacs-version))
2503 2500