Mercurial > emacs
comparison lisp/calendar/calendar.el @ 82203:3d0d3af343ac
(calendar-mode): Make sure displayed-(month|year) are set.
(calendar-basic-setup): Display buffer before adjusting window sizes.
(generate-calendar-window): Use inhibit-read-only. Simplify.
Generate buffer and set displayed-month and displayed-year before
calling update-calendar-mode-line.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 29 Jul 2007 20:49:13 +0000 |
parents | 7b6bc42d5f2c |
children | e5a68f18fcb9 539530fa389c |
comparison
equal
deleted
inserted
replaced
82202:2cd425573329 | 82203:3d0d3af343ac |
---|---|
1676 (year (extract-calendar-year date))) | 1676 (year (extract-calendar-year date))) |
1677 ;; (calendar-read-date t) returns a date with day = nil, which is | 1677 ;; (calendar-read-date t) returns a date with day = nil, which is |
1678 ;; not a legal date for the visible test in the diary section. | 1678 ;; not a legal date for the visible test in the diary section. |
1679 (if arg (setcar (cdr date) 1)) | 1679 (if arg (setcar (cdr date) 1)) |
1680 (increment-calendar-month month year (- calendar-offset)) | 1680 (increment-calendar-month month year (- calendar-offset)) |
1681 ;; Display the buffer before calling generate-calendar-window so that it | |
1682 ;; can get a chance to adjust the window sizes to the frame size. | |
1683 (pop-to-buffer calendar-buffer) | |
1681 (generate-calendar-window month year) | 1684 (generate-calendar-window month year) |
1682 ;; Display the buffer *after* generating it, so that menu entries that | |
1683 ;; use display-month do not fail when creating the new frame. | |
1684 (pop-to-buffer calendar-buffer) | |
1685 (if (and view-diary-entries-initially (calendar-date-is-visible-p date)) | 1685 (if (and view-diary-entries-initially (calendar-date-is-visible-p date)) |
1686 (diary-view-entries))) | 1686 (diary-view-entries))) |
1687 (let* ((diary-buffer (get-file-buffer diary-file)) | 1687 (let* ((diary-buffer (get-file-buffer diary-file)) |
1688 (diary-window (if diary-buffer (get-buffer-window diary-buffer))) | 1688 (diary-window (if diary-buffer (get-buffer-window diary-buffer))) |
1689 (split-height-threshold (if diary-window 2 1000))) | 1689 (split-height-threshold (if diary-window 2 1000))) |
2058 t) | 2058 t) |
2059 | 2059 |
2060 (defun generate-calendar-window (&optional mon yr) | 2060 (defun generate-calendar-window (&optional mon yr) |
2061 "Generate the calendar window for the current date. | 2061 "Generate the calendar window for the current date. |
2062 Or, for optional MON, YR." | 2062 Or, for optional MON, YR." |
2063 (let* ((buffer-read-only nil) | 2063 (let* ((inhibit-read-only t) |
2064 (today (calendar-current-date)) | 2064 (today (calendar-current-date)) |
2065 (month (extract-calendar-month today)) | 2065 (month (extract-calendar-month today)) |
2066 (day (extract-calendar-day today)) | 2066 (day (extract-calendar-day today)) |
2067 (year (extract-calendar-year today)) | 2067 (year (extract-calendar-year today)) |
2068 (today-visible | 2068 (today-visible |
2070 (let ((offset (calendar-interval mon yr month year))) | 2070 (let ((offset (calendar-interval mon yr month year))) |
2071 (and (<= offset 1) (>= offset -1))))) | 2071 (and (<= offset 1) (>= offset -1))))) |
2072 (day-in-week (calendar-day-of-week today)) | 2072 (day-in-week (calendar-day-of-week today)) |
2073 (in-calendar-window (eq (window-buffer (selected-window)) | 2073 (in-calendar-window (eq (window-buffer (selected-window)) |
2074 (get-buffer calendar-buffer)))) | 2074 (get-buffer calendar-buffer)))) |
2075 (generate-calendar (or mon month) (or yr year)) | |
2075 (update-calendar-mode-line) | 2076 (update-calendar-mode-line) |
2076 (if mon | |
2077 (generate-calendar mon yr) | |
2078 (generate-calendar month year)) | |
2079 (calendar-cursor-to-visible-date | 2077 (calendar-cursor-to-visible-date |
2080 (if today-visible today (list displayed-month 1 displayed-year))) | 2078 (if today-visible today (list displayed-month 1 displayed-year))) |
2081 (set-buffer-modified-p nil) | 2079 (set-buffer-modified-p nil) |
2082 ;; Don't do any window-related stuff if we weren't called from a | 2080 ;; Don't do any window-related stuff if we weren't called from a |
2083 ;; window displaying the calendar | 2081 ;; window displaying the calendar |
2473 (use-local-map calendar-mode-map) | 2471 (use-local-map calendar-mode-map) |
2474 (setq buffer-read-only t) | 2472 (setq buffer-read-only t) |
2475 (setq indent-tabs-mode nil) | 2473 (setq indent-tabs-mode nil) |
2476 (update-calendar-mode-line) | 2474 (update-calendar-mode-line) |
2477 (make-local-variable 'calendar-mark-ring) | 2475 (make-local-variable 'calendar-mark-ring) |
2478 (make-local-variable 'displayed-month);; Month in middle of window. | 2476 (make-local-variable 'displayed-month) ;; Month in middle of window. |
2479 (make-local-variable 'displayed-year) ;; Year in middle of window. | 2477 (make-local-variable 'displayed-year) ;; Year in middle of window. |
2478 ;; Most functions only work if displayed-month and displayed-year are set, | |
2479 ;; so let's make sure they're always set. Most likely, this will be reset | |
2480 ;; soon in generate-calendar, but better safe than sorry. | |
2481 (unless (boundp 'displayed-month) (setq displayed-month 1)) | |
2482 (unless (boundp 'displayed-year) (setq displayed-year 2001)) | |
2480 (set (make-local-variable 'font-lock-defaults) | 2483 (set (make-local-variable 'font-lock-defaults) |
2481 '(calendar-font-lock-keywords t)) | 2484 '(calendar-font-lock-keywords t)) |
2482 (run-mode-hooks 'calendar-mode-hook)) | 2485 (run-mode-hooks 'calendar-mode-hook)) |
2483 | 2486 |
2484 (defun calendar-string-spread (strings char length) | 2487 (defun calendar-string-spread (strings char length) |