comparison lisp/calendar/calendar.el @ 60292:b8747b7d8e2a

From Matt Hodges <MPHodges@member.fsf.org>: (calendar-buffer): Move above calendar-week-start-day. (calendar-week-start-day): Doc fix. Add :set function. (calendar-minimum-window-height): New variable. (generate-calendar-window): Only resize window if selected-window is displaying the calendar buffer. Use new variable calendar-minimum-window-height. (generate-calendar): Reword error message. (calendar-mode-map): Bind DEL to scroll-other-window-down.
author Glenn Morris <rgm@gnu.org>
date Sun, 27 Feb 2005 20:25:48 +0000
parents 9dadbbe9a381
children ae2850fc74dc
comparison
equal deleted inserted replaced
60291:795bc2bc5205 60292:b8747b7d8e2a
1 ;;; calendar.el --- calendar functions 1 ;;; calendar.el --- calendar functions
2 2
3 ;; Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1997, 3 ;; Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1997,
4 ;; 2000, 2001, 2003, 2004 Free Software Foundation, Inc. 4 ;; 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
5 5
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> 6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <gmorris@ast.cam.ac.uk> 7 ;; Maintainer: Glenn Morris <gmorris@ast.cam.ac.uk>
8 ;; Keywords: calendar 8 ;; Keywords: calendar
9 ;; Human-Keywords: calendar, Gregorian calendar, diary, holidays 9 ;; Human-Keywords: calendar, Gregorian calendar, diary, holidays
139 "Calendar hooks." 139 "Calendar hooks."
140 :prefix "calendar-" 140 :prefix "calendar-"
141 :group 'calendar) 141 :group 'calendar)
142 142
143 143
144 (defconst calendar-buffer "*Calendar*"
145 "Name of the buffer used for the calendar.")
146
144 ;;;###autoload 147 ;;;###autoload
145 (defcustom calendar-week-start-day 0 148 (defcustom calendar-week-start-day 0
146 "*The day of the week on which a week in the calendar begins. 149 "*The day of the week on which a week in the calendar begins.
147 0 means Sunday (default), 1 means Monday, and so on." 150 0 means Sunday (default), 1 means Monday, and so on.
151
152 If you change this variable directly (without using customize)
153 after starting `calendar', you should call `redraw-calendar' to
154 update the calendar display to reflect the change, otherwise
155 movement commands will not work correctly."
148 :type 'integer 156 :type 'integer
157 :set (lambda (sym val)
158 (set sym val)
159 (let ((buffer (get-buffer calendar-buffer)))
160 (when (buffer-live-p buffer)
161 (with-current-buffer buffer
162 (redraw-calendar)))))
149 :group 'calendar) 163 :group 'calendar)
150 164
151 ;;;###autoload 165 ;;;###autoload
152 (defcustom calendar-offset 0 166 (defcustom calendar-offset 0
153 "*The offset of the principal month from the center of the calendar window. 167 "*The offset of the principal month from the center of the calendar window.
1301 1315
1302 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... )." 1316 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... )."
1303 :type 'sexp 1317 :type 'sexp
1304 :group 'holidays) 1318 :group 'holidays)
1305 1319
1306 (defconst calendar-buffer "*Calendar*"
1307 "Name of the buffer used for the calendar.")
1308
1309 (defconst holiday-buffer "*Holidays*" 1320 (defconst holiday-buffer "*Holidays*"
1310 "Name of the buffer used for the displaying the holidays.") 1321 "Name of the buffer used for the displaying the holidays.")
1311 1322
1312 (defconst fancy-diary-buffer "*Fancy Diary Entries*" 1323 (defconst fancy-diary-buffer "*Fancy Diary Entries*"
1313 "Name of the buffer used for the optional fancy display of the diary.") 1324 "Name of the buffer used for the optional fancy display of the diary.")
1561 (defcustom calendar-setup nil 1572 (defcustom calendar-setup nil
1562 "The frame setup of the calendar. 1573 "The frame setup of the calendar.
1563 The choices are: `one-frame' (calendar and diary together in one separate, 1574 The choices are: `one-frame' (calendar and diary together in one separate,
1564 dedicated frame); `two-frames' (calendar and diary in separate, dedicated 1575 dedicated frame); `two-frames' (calendar and diary in separate, dedicated
1565 frames); `calendar-only' (calendar in a separate, dedicated frame); with 1576 frames); `calendar-only' (calendar in a separate, dedicated frame); with
1566 any other value the current frame is used. Using any of the first 1577 any other value the current frame is used. Using any of the first
1567 three options overrides the value of `view-diary-entries-initially'." 1578 three options overrides the value of `view-diary-entries-initially'."
1568 :type '(choice 1579 :type '(choice
1569 (const :tag "calendar and diary in separate frame" one-frame) 1580 (const :tag "calendar and diary in separate frame" one-frame)
1570 (const :tag "calendar and diary each in own frame" two-frames) 1581 (const :tag "calendar and diary each in own frame" two-frames)
1571 (const :tag "calendar in separate frame" calendar-only) 1582 (const :tag "calendar in separate frame" calendar-only)
1572 (const :tag "use current frame" nil)) 1583 (const :tag "use current frame" nil))
1584 :group 'calendar)
1585
1586 (defcustom calendar-minimum-window-height 8
1587 "Minimum height `generate-calendar-window' should use for calendar window."
1588 :type 'integer
1589 :version "22.1"
1573 :group 'calendar) 1590 :group 'calendar)
1574 1591
1575 ;;;###autoload 1592 ;;;###autoload
1576 (defun calendar (&optional arg) 1593 (defun calendar (&optional arg)
1577 "Choose between the one frame, two frame, or basic calendar displays. 1594 "Choose between the one frame, two frame, or basic calendar displays.
2037 (year (extract-calendar-year today)) 2054 (year (extract-calendar-year today))
2038 (today-visible 2055 (today-visible
2039 (or (not mon) 2056 (or (not mon)
2040 (let ((offset (calendar-interval mon yr month year))) 2057 (let ((offset (calendar-interval mon yr month year)))
2041 (and (<= offset 1) (>= offset -1))))) 2058 (and (<= offset 1) (>= offset -1)))))
2042 (day-in-week (calendar-day-of-week today))) 2059 (day-in-week (calendar-day-of-week today))
2060 (in-calendar-window (eq (window-buffer (selected-window))
2061 (get-buffer calendar-buffer))))
2043 (update-calendar-mode-line) 2062 (update-calendar-mode-line)
2044 (if mon 2063 (if mon
2045 (generate-calendar mon yr) 2064 (generate-calendar mon yr)
2046 (generate-calendar month year)) 2065 (generate-calendar month year))
2047 (calendar-cursor-to-visible-date 2066 (calendar-cursor-to-visible-date
2048 (if today-visible today (list displayed-month 1 displayed-year))) 2067 (if today-visible today (list displayed-month 1 displayed-year)))
2049 (set-buffer-modified-p nil) 2068 (set-buffer-modified-p nil)
2050 (if (or (one-window-p t) (/= (frame-width) (window-width))) 2069 ;; Don't do any window-related stuff if we weren't called from a
2051 ;; Don't mess with the window size, but ensure that the first 2070 ;; window displaying the calendar
2052 ;; line is fully visible 2071 (when in-calendar-window
2053 (set-window-vscroll nil 0) 2072 (if (or (one-window-p t) (/= (frame-width) (window-width)))
2054 ;; Adjust the window to exactly fit the displayed calendar 2073 ;; Don't mess with the window size, but ensure that the first
2055 (fit-window-to-buffer)) 2074 ;; line is fully visible
2056 (sit-for 0) 2075 (set-window-vscroll nil 0)
2076 ;; Adjust the window to exactly fit the displayed calendar
2077 (fit-window-to-buffer nil nil calendar-minimum-window-height))
2078 (sit-for 0))
2057 (if (and (boundp 'font-lock-mode) 2079 (if (and (boundp 'font-lock-mode)
2058 font-lock-mode) 2080 font-lock-mode)
2059 (font-lock-fontify-buffer)) 2081 (font-lock-fontify-buffer))
2060 (and mark-holidays-in-calendar 2082 (and mark-holidays-in-calendar
2061 ;;; (calendar-date-is-legal-p today) ; useful for BC dates 2083 ;;; (calendar-date-is-legal-p today) ; useful for BC dates
2062 (mark-calendar-holidays) 2084 (mark-calendar-holidays)
2063 (sit-for 0)) 2085 (and in-calendar-window (sit-for 0)))
2064 (unwind-protect 2086 (unwind-protect
2065 (if mark-diary-entries-in-calendar (mark-diary-entries)) 2087 (if mark-diary-entries-in-calendar (mark-diary-entries))
2066 (if today-visible 2088 (if today-visible
2067 (run-hooks 'today-visible-calendar-hook) 2089 (run-hooks 'today-visible-calendar-hook)
2068 (run-hooks 'today-invisible-calendar-hook))))) 2090 (run-hooks 'today-invisible-calendar-hook)))))
2069 2091
2070 (defun generate-calendar (month year) 2092 (defun generate-calendar (month year)
2071 "Generate a three-month Gregorian calendar centered around MONTH, YEAR." 2093 "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
2072 ;;; A negative YEAR is interpreted as BC; -1 being 1 BC, and so on. 2094 ;;; A negative YEAR is interpreted as BC; -1 being 1 BC, and so on.
2073 ;;; Note that while calendars for years BC could be displayed as it 2095 ;;; Note that while calendars for years BC could be displayed as it
2074 ;;; stands, almost all other calendar functions (eg holidays) would 2096 ;;; stands, almost all other calendar functions (eg holidays) would
2075 ;;; at best have unpredictable results for such dates. 2097 ;;; at best have unpredictable results for such dates.
2076 (if (< (+ month (* 12 (1- year))) 2) 2098 (if (< (+ month (* 12 (1- year))) 2)
2077 (error "Months before February, 1 AD are not available")) 2099 (error "Months before January, 1 AD cannot be displayed"))
2078 (setq displayed-month month 2100 (setq displayed-month month
2079 displayed-year year) 2101 displayed-year year)
2080 (erase-buffer) 2102 (erase-buffer)
2081 (increment-calendar-month month year -1) 2103 (increment-calendar-month month year -1)
2082 (calendar-for-loop i from 0 to 2 do 2104 (calendar-for-loop i from 0 to 2 do
2227 (define-key calendar-mode-map "Aa" 'appt-add) 2249 (define-key calendar-mode-map "Aa" 'appt-add)
2228 (define-key calendar-mode-map "Ad" 'appt-delete) 2250 (define-key calendar-mode-map "Ad" 'appt-delete)
2229 (define-key calendar-mode-map "S" 'calendar-sunrise-sunset) 2251 (define-key calendar-mode-map "S" 'calendar-sunrise-sunset)
2230 (define-key calendar-mode-map "M" 'calendar-phases-of-moon) 2252 (define-key calendar-mode-map "M" 'calendar-phases-of-moon)
2231 (define-key calendar-mode-map " " 'scroll-other-window) 2253 (define-key calendar-mode-map " " 'scroll-other-window)
2254 (define-key calendar-mode-map (kbd "DEL") 'scroll-other-window-down)
2232 (define-key calendar-mode-map "\C-c\C-l" 'redraw-calendar) 2255 (define-key calendar-mode-map "\C-c\C-l" 'redraw-calendar)
2233 (define-key calendar-mode-map "." 'calendar-goto-today) 2256 (define-key calendar-mode-map "." 'calendar-goto-today)
2234 (define-key calendar-mode-map "o" 'calendar-other-month) 2257 (define-key calendar-mode-map "o" 'calendar-other-month)
2235 (define-key calendar-mode-map "q" 'exit-calendar) 2258 (define-key calendar-mode-map "q" 'exit-calendar)
2236 (define-key calendar-mode-map "a" 'list-calendar-holidays) 2259 (define-key calendar-mode-map "a" 'list-calendar-holidays)