aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2008-03-17 02:30:06 +0000
committerGlenn Morris2008-03-17 02:30:06 +0000
commitbf0cce5ad9125e890ce775924e6ad85f20938ed4 (patch)
tree8af06b49e62f78729c405845447e84e41abc30f5
parent318a5488881ad5953f7467de1e678ddf849060ac (diff)
downloademacs-bf0cce5ad9125e890ce775924e6ad85f20938ed4.tar.gz
emacs-bf0cce5ad9125e890ce775924e6ad85f20938ed4.zip
(calendar-today-marker, initial-calendar-window-hook)
(today-visible-calendar-hook, today-invisible-calendar-hook) (diary-file, calendar-basic-setup, calendar-star-date) (calendar-mark-today): Doc fixes. (today-visible-calendar-hook): Add options. (calendar-in-read-only-buffer): New macro. (calendar-basic-setup): Adapt for change in calendar-read-date. Place holiday let inside if. (calendar-day-name-array, calendar-month-name-array): Make defcustoms. (calendar-read-date): Set day to 1 rather than nil in the NODAY case. (calendar-print-other-dates): Use one let rather than many. Use calendar-in-read-only-buffer to replace previous code and disable undo.
-rw-r--r--lisp/calendar/calendar.el230
1 files changed, 124 insertions, 106 deletions
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index 38fdc4f5d11..bf314499682 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -252,8 +252,7 @@ The value can be either a single-character string or a face."
252(defcustom calendar-today-marker (if (display-color-p) 'calendar-today "=") 252(defcustom calendar-today-marker (if (display-color-p) 'calendar-today "=")
253 "How to mark today's date in the calendar. 253 "How to mark today's date in the calendar.
254The value can be either a single-character string or a face. 254The value can be either a single-character string or a face.
255Marking today's date is done only if you set up `today-visible-calendar-hook' 255Used by `calendar-mark-today'."
256to request that."
257 :type '(choice string face) 256 :type '(choice string face)
258 :group 'calendar) 257 :group 'calendar)
259 258
@@ -288,48 +287,33 @@ This is the place to add key bindings to `calendar-mode-map'."
288 :group 'calendar-hooks) 287 :group 'calendar-hooks)
289 288
290(defcustom initial-calendar-window-hook nil 289(defcustom initial-calendar-window-hook nil
291 "List of functions to be called when the calendar window is first opened. 290 "List of functions to be called when the calendar window is created.
292The functions invoked are called after the calendar window is opened, but 291Qutting the calendar and re-entering it will cause these functions
293once opened is never called again. Leaving the calendar with the `q' command 292to be called again."
294and reentering it will cause these functions to be called again."
295 :type 'hook 293 :type 'hook
296 :group 'calendar-hooks) 294 :group 'calendar-hooks)
297 295
298(defcustom today-visible-calendar-hook nil 296(defcustom today-visible-calendar-hook nil
299 "List of functions called whenever the current date is visible. 297 "List of functions called whenever the current date is visible.
300This can be used, for example, to replace today's date with asterisks; a 298To mark today's date, add the function `calendar-mark-today'.
301function `calendar-star-date' is included for this purpose: 299To replace the date with asterisks, add the function `calendar-star-date'.
302 (setq today-visible-calendar-hook 'calendar-star-date) 300
303It can also be used to mark the current date with `calendar-today-marker'; 301See also `today-invisible-calendar-hook'.
304a function is also provided for this: 302
305 (setq today-visible-calendar-hook 'calendar-mark-today) 303Changing characters in the calendar buffer, except via the provided
306 304functions, may cause the calendar movement commands to fail."
307The corresponding variable `today-invisible-calendar-hook' is the list of
308functions called when the calendar function was called when the current
309date is not visible in the window.
310
311Other than the use of the provided functions, the changing of any
312characters in the calendar buffer by the hooks may cause the failure of the
313functions that move by days and weeks."
314 :type 'hook 305 :type 'hook
306 :options '(calendar-mark-today calendar-star-date)
315 :group 'calendar-hooks) 307 :group 'calendar-hooks)
316 308
317(defcustom today-invisible-calendar-hook nil 309(defcustom today-invisible-calendar-hook nil
318 "List of functions called whenever the current date is not visible. 310 "List of functions called whenever the current date is not visible.
319 311See also `today-visible-calendar-hook'."
320The corresponding variable `today-visible-calendar-hook' is the list of
321functions called when the calendar function was called when the current
322date is visible in the window.
323
324Other than the use of the provided functions, the changing of any
325characters in the calendar buffer by the hooks may cause the failure of the
326functions that move by days and weeks."
327 :type 'hook 312 :type 'hook
328 :group 'calendar-hooks) 313 :group 'calendar-hooks)
329 314
330(defcustom calendar-move-hook nil 315(defcustom calendar-move-hook nil
331 "List of functions called whenever the cursor moves in the calendar. 316 "List of functions called whenever the cursor moves in the calendar.
332
333For example, 317For example,
334 318
335 (add-hook 'calendar-move-hook (lambda () (diary-view-entries 1))) 319 (add-hook 'calendar-move-hook (lambda () (diary-view-entries 1)))
@@ -439,13 +423,14 @@ Diary entries based on the Hebrew, the Islamic and/or the Baha'i
439calendar are also possible, but because these are somewhat slow, they 423calendar are also possible, but because these are somewhat slow, they
440are ignored unless you set the `nongregorian-diary-listing-hook' and 424are ignored unless you set the `nongregorian-diary-listing-hook' and
441the `nongregorian-diary-marking-hook' appropriately. See the 425the `nongregorian-diary-marking-hook' appropriately. See the
442documentation for these functions for details. 426documentation of these hooks for details.
443 427
444Diary files can contain directives to include the contents of other files; for 428Diary files can contain directives to include the contents of other files; for
445details, see the documentation for the variable `list-diary-entries-hook'." 429details, see the documentation for the variable `list-diary-entries-hook'."
446 :type 'file 430 :type 'file
447 :group 'diary) 431 :group 'diary)
448 432
433;; FIXME do these have to be single characters?
449(defcustom diary-nonmarking-symbol "&" 434(defcustom diary-nonmarking-symbol "&"
450 "Symbol indicating that a diary entry is not to be marked in the calendar." 435 "Symbol indicating that a diary entry is not to be marked in the calendar."
451 :type 'string 436 :type 'string
@@ -466,6 +451,8 @@ details, see the documentation for the variable `list-diary-entries-hook'."
466 :type 'string 451 :type 'string
467 :group 'diary) 452 :group 'diary)
468 453
454;; FIXME explain range. FIXME tweak range to always be +-50 of
455;; present, if not already.
469(defcustom abbreviated-calendar-year t 456(defcustom abbreviated-calendar-year t
470 "Interpret a two-digit year DD in a diary entry as either 19DD or 20DD. 457 "Interpret a two-digit year DD in a diary entry as either 19DD or 20DD.
471For the Gregorian calendar; similarly for the Hebrew, Islamic and 458For the Gregorian calendar; similarly for the Hebrew, Islamic and
@@ -651,6 +638,7 @@ See the documentation of the function `calendar-date-string'."
651 (update-calendar-mode-line)) 638 (update-calendar-mode-line))
652 639
653;; FIXME move to diary-lib and adjust appt. 640;; FIXME move to diary-lib and adjust appt.
641;; Add appt-make-list as an option?
654(defcustom diary-hook nil 642(defcustom diary-hook nil
655 "List of functions called after the display of the diary. 643 "List of functions called after the display of the diary.
656Can be used for appointment notification." 644Can be used for appointment notification."
@@ -1225,6 +1213,22 @@ inclusive. The standard macro `dotimes' is preferable in most cases."
1225 ,index (1+ ,index))) 1213 ,index (1+ ,index)))
1226 sum)) 1214 sum))
1227 1215
1216(defmacro calendar-in-read-only-buffer (buffer &rest body)
1217 "Switch to BUFFER and executes the forms in BODY.
1218First creates or erases BUFFER as needed. Leaves BUFFER read-only,
1219with disabled undo. Leaves point at point-min, displays BUFFER."
1220 (declare (indent 1) (debug t))
1221 `(progn
1222 (set-buffer (get-buffer-create ,buffer))
1223 (setq buffer-read-only nil
1224 buffer-undo-list t)
1225 (erase-buffer)
1226 ,@body
1227 (goto-char (point-min))
1228 (set-buffer-modified-p nil)
1229 (setq buffer-read-only t)
1230 (display-buffer ,buffer)))
1231
1228;; The following are in-line for speed; they can be called thousands of times 1232;; The following are in-line for speed; they can be called thousands of times
1229;; when looking up holidays or processing the diary. Here, for example, are 1233;; when looking up holidays or processing the diary. Here, for example, are
1230;; the numbers of calls to calendar/diary/holiday functions in preparing the 1234;; the numbers of calls to calendar/diary/holiday functions in preparing the
@@ -1257,7 +1261,8 @@ inclusive. The standard macro `dotimes' is preferable in most cases."
1257 "Extract the month part of DATE which has the form (month day year)." 1261 "Extract the month part of DATE which has the form (month day year)."
1258 (car date)) 1262 (car date))
1259 1263
1260;; Note gives wrong answer for result of (calendar-read-date 'noday). 1264;; Note gives wrong answer for result of (calendar-read-date 'noday),
1265;; but that is only used by `calendar-other-month'.
1261(defsubst extract-calendar-day (date) 1266(defsubst extract-calendar-day (date)
1262 "Extract the day part of DATE which has the form (month day year)." 1267 "Extract the day part of DATE which has the form (month day year)."
1263 (cadr date)) 1268 (cadr date))
@@ -1381,15 +1386,12 @@ After loading the calendar, the hooks given by the variable
1381`calendar-load-hook' are run. This is the place to add key bindings to the 1386`calendar-load-hook' are run. This is the place to add key bindings to the
1382`calendar-mode-map'. 1387`calendar-mode-map'.
1383 1388
1384After preparing the calendar window initially, the hooks given by the variable
1385`initial-calendar-window-hook' are run.
1386
1387The hooks given by the variable `today-visible-calendar-hook' are run 1389The hooks given by the variable `today-visible-calendar-hook' are run
1388every time the calendar window gets scrolled, if the current date is visible 1390every time the calendar window gets scrolled, if the current date is visible
1389in the window. If it is not visible, the hooks given by the variable 1391in the window. If it is not visible, the hooks given by the variable
1390`today-invisible-calendar-hook' are run. Thus, for example, setting 1392`today-invisible-calendar-hook' are run.
1391`today-visible-calendar-hook' to 'calendar-star-date will cause today's date 1393
1392to be replaced by asterisks to highlight it whenever it is in the window." 1394Finally this command runs `initial-calendar-window-hook'."
1393 (interactive "P") 1395 (interactive "P")
1394 (set-buffer (get-buffer-create calendar-buffer)) 1396 (set-buffer (get-buffer-create calendar-buffer))
1395 (calendar-mode) 1397 (calendar-mode)
@@ -1399,9 +1401,6 @@ to be replaced by asterisks to highlight it whenever it is in the window."
1399 (calendar-current-date))) 1401 (calendar-current-date)))
1400 (month (extract-calendar-month date)) 1402 (month (extract-calendar-month date))
1401 (year (extract-calendar-year date))) 1403 (year (extract-calendar-year date)))
1402 ;; (calendar-read-date t) returns a date with day = nil, which is
1403 ;; not a valid date for the visible test in the diary section.
1404 (if arg (setcar (cdr date) 1))
1405 (increment-calendar-month month year (- calendar-offset)) 1404 (increment-calendar-month month year (- calendar-offset))
1406 ;; Display the buffer before calling generate-calendar-window so that it 1405 ;; Display the buffer before calling generate-calendar-window so that it
1407 ;; can get a chance to adjust the window sizes to the frame size. 1406 ;; can get a chance to adjust the window sizes to the frame size.
@@ -1409,10 +1408,11 @@ to be replaced by asterisks to highlight it whenever it is in the window."
1409 (generate-calendar-window month year) 1408 (generate-calendar-window month year)
1410 (if (and view-diary-entries-initially (calendar-date-is-visible-p date)) 1409 (if (and view-diary-entries-initially (calendar-date-is-visible-p date))
1411 (diary-view-entries))) 1410 (diary-view-entries)))
1412 (let* ((diary-buffer (get-file-buffer diary-file)) 1411 (if view-calendar-holidays-initially
1413 (diary-window (if diary-buffer (get-buffer-window diary-buffer))) 1412 (let* ((diary-buffer (get-file-buffer diary-file))
1414 (split-height-threshold (if diary-window 2 1000))) 1413 (diary-window (if diary-buffer (get-buffer-window diary-buffer)))
1415 (if view-calendar-holidays-initially 1414 (split-height-threshold (if diary-window 2 1000)))
1415 ;; FIXME display buffer?
1416 (calendar-list-holidays))) 1416 (calendar-list-holidays)))
1417 (run-hooks 'initial-calendar-window-hook)) 1417 (run-hooks 'initial-calendar-window-hook))
1418 1418
@@ -2075,12 +2075,21 @@ is a string to insert in the minibuffer before reading."
2075 "*Length of abbreviations to be used for day and month names. 2075 "*Length of abbreviations to be used for day and month names.
2076See also `calendar-day-abbrev-array' and `calendar-month-abbrev-array'.") 2076See also `calendar-day-abbrev-array' and `calendar-month-abbrev-array'.")
2077 2077
2078(defvar calendar-day-name-array 2078;; FIXME does it have to start from Sunday?
2079(defcustom calendar-day-name-array
2079 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"] 2080 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]
2080 "*Array of capitalized strings giving, in order, the day names. 2081 "Array of capitalized strings giving, in order, the day names.
2081The first two characters of each string will be used to head the 2082The first two characters of each string will be used to head the
2082day columns in the calendar. See also the variable 2083day columns in the calendar. See also the variable
2083`calendar-day-abbrev-array'.") 2084`calendar-day-abbrev-array'."
2085 :group 'calendar
2086 :type '(vector (string :tag "Sunday")
2087 (string :tag "Monday")
2088 (string :tag "Tuesday")
2089 (string :tag "Wednesday")
2090 (string :tag "Thursday")
2091 (string :tag "Friday")
2092 (string :tag "Saturday")))
2084 2093
2085(defvar calendar-day-abbrev-array 2094(defvar calendar-day-abbrev-array
2086 [nil nil nil nil nil nil nil] 2095 [nil nil nil nil nil nil nil]
@@ -2093,11 +2102,24 @@ you may use such in the diary file. If any element of this array
2093is nil, then the abbreviation will be constructed as the first 2102is nil, then the abbreviation will be constructed as the first
2094`calendar-abbrev-length' characters of the corresponding full name.") 2103`calendar-abbrev-length' characters of the corresponding full name.")
2095 2104
2096(defvar calendar-month-name-array 2105(defcustom calendar-month-name-array
2097 ["January" "February" "March" "April" "May" "June" 2106 ["January" "February" "March" "April" "May" "June"
2098 "July" "August" "September" "October" "November" "December"] 2107 "July" "August" "September" "October" "November" "December"]
2099 "*Array of capitalized strings giving, in order, the month names. 2108 "Array of capitalized strings giving, in order, the month names.
2100See also the variable `calendar-month-abbrev-array'.") 2109See also the variable `calendar-month-abbrev-array'."
2110 :group 'calendar
2111 :type '(vector (string :tag "January")
2112 (string :tag "February")
2113 (string :tag "March")
2114 (string :tag "April")
2115 (string :tag "May")
2116 (string :tag "June")
2117 (string :tag "July")
2118 (string :tag "August")
2119 (string :tag "September")
2120 (string :tag "October")
2121 (string :tag "November")
2122 (string :tag "December")))
2101 2123
2102(defvar calendar-month-abbrev-array 2124(defvar calendar-month-abbrev-array
2103 [nil nil nil nil nil nil nil nil nil nil nil nil] 2125 [nil nil nil nil nil nil nil nil nil nil nil nil]
@@ -2143,7 +2165,7 @@ If FILTER is provided, apply it to each key in the alist."
2143(defun calendar-read-date (&optional noday) 2165(defun calendar-read-date (&optional noday)
2144 "Prompt for Gregorian date. Return a list (month day year). 2166 "Prompt for Gregorian date. Return a list (month day year).
2145If optional NODAY is t, does not ask for day, but just returns 2167If optional NODAY is t, does not ask for day, but just returns
2146\(month nil year); if NODAY is any other non-nil value the value returned is 2168\(month 1 year); if NODAY is any other non-nil value the value returned is
2147\(month year)" 2169\(month year)"
2148 (let* ((year (calendar-read 2170 (let* ((year (calendar-read
2149 "Year (>0): " 2171 "Year (>0): "
@@ -2161,7 +2183,7 @@ If optional NODAY is t, does not ask for day, but just returns
2161 (last (calendar-last-day-of-month month year))) 2183 (last (calendar-last-day-of-month month year)))
2162 (if noday 2184 (if noday
2163 (if (eq noday t) 2185 (if (eq noday t)
2164 (list month nil year) 2186 (list month 1 year)
2165 (list month year)) 2187 (list month year))
2166 (list month 2188 (list month
2167 (calendar-read (format "Day (1-%d): " last) 2189 (calendar-read (format "Day (1-%d): " last)
@@ -2261,7 +2283,7 @@ interpreted as BC; -1 being 1 BC, and so on."
2261 (day (extract-calendar-day date)) 2283 (day (extract-calendar-day date))
2262 (year (extract-calendar-year date))) 2284 (year (extract-calendar-year date)))
2263 (and (<= 1 month) (<= month 12) 2285 (and (<= 1 month) (<= month 12)
2264 ;; (calendar-read-date t) returns a date with day = nil. 2286 ;; (calendar-read-date t) used to return a date with day = nil.
2265 ;; Should not be valid (?), since many funcs prob assume integer. 2287 ;; Should not be valid (?), since many funcs prob assume integer.
2266 ;; (calendar-read-date 'noday) returns (month year), which 2288 ;; (calendar-read-date 'noday) returns (month year), which
2267 ;; currently results in extract-calendar-year returning nil. 2289 ;; currently results in extract-calendar-year returning nil.
@@ -2332,8 +2354,7 @@ MARK defaults to `diary-entry-marker'."
2332 2354
2333(defun calendar-star-date () 2355(defun calendar-star-date ()
2334 "Replace the date under the cursor in the calendar window with asterisks. 2356 "Replace the date under the cursor in the calendar window with asterisks.
2335This function can be used with the `today-visible-calendar-hook' run after the 2357You might want to add this function to `today-visible-calendar-hook'."
2336calendar window has been prepared."
2337 (let ((inhibit-read-only t) 2358 (let ((inhibit-read-only t)
2338 (modified (buffer-modified-p))) 2359 (modified (buffer-modified-p)))
2339 (forward-char 1) 2360 (forward-char 1)
@@ -2348,12 +2369,9 @@ calendar window has been prepared."
2348 2369
2349(defun calendar-mark-today () 2370(defun calendar-mark-today ()
2350 "Mark the date under the cursor in the calendar window. 2371 "Mark the date under the cursor in the calendar window.
2351The date is marked with `calendar-today-marker'. This function can be used with 2372The date is marked with `calendar-today-marker'. You might want to add
2352the `today-visible-calendar-hook' run after the calendar window has been 2373this function to `today-visible-calendar-hook'."
2353prepared." 2374 (mark-visible-calendar-date (calendar-cursor-to-date) calendar-today-marker))
2354 (mark-visible-calendar-date
2355 (calendar-cursor-to-date)
2356 calendar-today-marker))
2357 2375
2358(defun calendar-date-compare (date1 date2) 2376(defun calendar-date-compare (date1 date2)
2359 "Return t if DATE1 is before DATE2, nil otherwise. 2377 "Return t if DATE1 is before DATE2, nil otherwise.
@@ -2430,51 +2448,51 @@ Defaults to today's date if DATE is not given."
2430(defun calendar-print-other-dates () 2448(defun calendar-print-other-dates ()
2431 "Show dates on other calendars for date under the cursor." 2449 "Show dates on other calendars for date under the cursor."
2432 (interactive) 2450 (interactive)
2433 (let ((date (calendar-cursor-to-date t))) 2451 (let ((date (calendar-cursor-to-date t))
2434 (with-current-buffer (get-buffer-create other-calendars-buffer) 2452 odate)
2435 (let ((inhibit-read-only t) 2453 (calendar-in-read-only-buffer other-calendars-buffer
2436 (modified (buffer-modified-p))) 2454 (calendar-set-mode-line (format "%s (Gregorian)"
2437 (calendar-set-mode-line 2455 (calendar-date-string date)))
2438 (concat (calendar-date-string date) " (Gregorian)")) 2456 (apply
2439 (erase-buffer) 2457 'insert
2440 (apply 2458 (delq nil
2441 'insert 2459 (list
2442 (delq nil 2460 (calendar-day-of-year-string date) "\n"
2443 (list 2461 (format "ISO date: %s\n" (calendar-iso-date-string date))
2444 (calendar-day-of-year-string date) "\n" 2462 (format "Julian date: %s\n"
2445 (format "ISO date: %s\n" (calendar-iso-date-string date)) 2463 (calendar-julian-date-string date))
2446 (format "Julian date: %s\n" 2464 (format "Astronomical (Julian) day number (at noon UTC): %s.0\n"
2447 (calendar-julian-date-string date)) 2465 (calendar-astro-date-string date))
2448 (format "Astronomical (Julian) day number (at noon UTC): %s.0\n" 2466 (format "Fixed (RD) date: %s\n"
2449 (calendar-astro-date-string date)) 2467 (calendar-absolute-from-gregorian date))
2450 (format "Fixed (RD) date: %s\n" 2468 (format "Hebrew date (before sunset): %s\n"
2451 (calendar-absolute-from-gregorian date)) 2469 (calendar-hebrew-date-string date))
2452 (format "Hebrew date (before sunset): %s\n" 2470 (format "Persian date: %s\n"
2453 (calendar-hebrew-date-string date)) 2471 (calendar-persian-date-string date))
2454 (format "Persian date: %s\n" 2472 (unless (string-equal
2455 (calendar-persian-date-string date)) 2473 (setq odate (calendar-islamic-date-string date))
2456 (let ((i (calendar-islamic-date-string date))) 2474 "")
2457 (unless (string-equal i "") 2475 (format "Islamic date (before sunset): %s\n" odate))
2458 (format "Islamic date (before sunset): %s\n" i))) 2476 (unless (string-equal
2459 (let ((b (calendar-bahai-date-string date))) 2477 (setq odate (calendar-bahai-date-string date))
2460 (unless (string-equal b "") 2478 "")
2461 (format "Baha'i date (before sunset): %s\n" b))) 2479 (format "Baha'i date (before sunset): %s\n" odate))
2462 (format "Chinese date: %s\n" 2480 (format "Chinese date: %s\n"
2463 (calendar-chinese-date-string date)) 2481 (calendar-chinese-date-string date))
2464 (let ((c (calendar-coptic-date-string date))) 2482 (unless (string-equal
2465 (unless (string-equal c "") 2483 (setq odate (calendar-coptic-date-string date))
2466 (format "Coptic date: %s\n" c))) 2484 "")
2467 (let ((e (calendar-ethiopic-date-string date))) 2485 (format "Coptic date: %s\n" odate))
2468 (unless (string-equal e "") 2486 (unless (string-equal
2469 (format "Ethiopic date: %s\n" e))) 2487 (setq odate (calendar-ethiopic-date-string date))
2470 (let ((f (calendar-french-date-string date))) 2488 "")
2471 (unless (string-equal f "") 2489 (format "Ethiopic date: %s\n" e))
2472 (format "French Revolutionary date: %s\n" f))) 2490 (unless (string-equal
2473 (format "Mayan date: %s\n" 2491 (setq odate (calendar-french-date-string date))
2474 (calendar-mayan-date-string date))))) 2492 "")
2475 (goto-char (point-min)) 2493 (format "French Revolutionary date: %s\n" odate))
2476 (restore-buffer-modified-p modified)) 2494 (format "Mayan date: %s\n"
2477 (display-buffer other-calendars-buffer)))) 2495 (calendar-mayan-date-string date))))))))
2478 2496
2479(defun calendar-print-day-of-year () 2497(defun calendar-print-day-of-year ()
2480 "Show day number in year/days remaining in year for date under the cursor." 2498 "Show day number in year/days remaining in year for date under the cursor."