]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/calendar.el
* etc/NEWS: Mention nil `calendar-mode-line-format' will not modify
[gnu-emacs] / lisp / calendar / calendar.el
index bba3e520e1a1adf985b3ad401fe52bfd728ab868..199b21ecd773ef5050dd023ce89ae67378407da9 100644 (file)
@@ -1,7 +1,6 @@
 ;;; calendar.el --- calendar functions
 
-;; Copyright (C) 1988-1995, 1997, 2000-2014 Free Software Foundation,
-;; Inc.
+;; Copyright (C) 1988-1995, 1997, 2000-2014 Free Software Foundation, Inc.
 
 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
 ;; Maintainer: Glenn Morris <rgm@gnu.org>
@@ -1424,10 +1423,16 @@ display the generated calendar."
         ;; the right thing in that case.
         ;;
         ;; Is this a wide frame?  If so, split it horizontally.
-        (if (window-splittable-p t) (split-window-right))
+
+       ;; The following doesn't sound useful: If we split horizontally
+       ;; here, the subsequent `pop-to-buffer' will likely split again
+       ;; horizontally and we end up with three side-by-side windows.
+        (when (window-splittable-p (selected-window) t)
+         (split-window-right))
         (pop-to-buffer calendar-buffer)
         ;; Has the window already been split vertically?
         (when (and (not (window-dedicated-p))
+                  (window-splittable-p (selected-window))
                    (window-full-height-p))
           (let ((win (split-window-below)))
             ;; In the upper window, show whatever was visible before.
@@ -1438,9 +1443,14 @@ display the generated calendar."
       (calendar-generate-window month year)
       (if (and calendar-view-diary-initially-flag
                (calendar-date-is-visible-p date))
-          (diary-view-entries))))
+          ;; Do not clobber the calendar with the diary, if the diary
+          ;; has previously been shown in the window that now shows the
+          ;; calendar (bug#18381).
+          (let ((display-buffer-overriding-action
+                 '(nil . ((inhibit-same-window . t)))))
+            (diary-view-entries)))))
   (if calendar-view-holidays-initially-flag
-      (let* ((diary-buffer (get-file-buffer diary-file))
+      (let* ((diary-buffer (diary-live-p))
              (diary-window (if diary-buffer (get-buffer-window diary-buffer)))
              (split-height-threshold (if diary-window 2 1000)))
         ;; FIXME display buffer?
@@ -1474,17 +1484,15 @@ Optional integers MON and YR are used instead of today's date."
        ;; combined don't fit height to that of its buffer.
        (set-window-vscroll nil 0))
       (sit-for 0))
-    (and (bound-and-true-p font-lock-mode)
-         (font-lock-fontify-buffer))
     (and calendar-mark-holidays-flag
-;;;         (calendar-date-is-valid-p today) ; useful for BC dates
+         ;; (calendar-date-is-valid-p today) ; useful for BC dates
          (calendar-mark-holidays)
          (and in-calendar-window (sit-for 0)))
     (unwind-protect
         (if calendar-mark-diary-entries-flag (diary-mark-entries))
-      (if today-visible
-          (run-hooks 'calendar-today-visible-hook)
-        (run-hooks 'calendar-today-invisible-hook)))))
+      (run-hooks (if today-visible
+                     'calendar-today-visible-hook
+                   'calendar-today-invisible-hook)))))
 
 (defun calendar-generate (month year)
   "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
@@ -1796,14 +1804,18 @@ is COMMAND's keybinding, STRING describes the binding."
                               nil "today"))
    '(calendar-date-string (calendar-current-date) t)
    (calendar-mode-line-entry 'calendar-scroll-left "next month" ">"))
-  "The mode line of the calendar buffer.
+  "If non-nil, the mode line of the calendar buffer.
 This is a list of items that evaluate to strings.  The elements
 are evaluated and concatenated, evenly separated by blanks.
 During evaluation, the variable `date' is available as the date
 nearest the cursor (or today's date if that fails).  To update
-the mode-line as the cursor moves, add `calendar-update-mode-line'
-to `calendar-move-hook'.  Here is an example that has the Hebrew date,
-the day number/days remaining in the year, and the ISO week/year numbers:
+the mode-line as the cursor moves, add
+`calendar-update-mode-line' to `calendar-move-hook'.
+
+If nil, do not modify the mode line at all.
+
+Here is an example that has the Hebrew date, the day number/days
+remaining in the year, and the ISO week/year numbers:
 
   (list
    \"\"
@@ -1881,7 +1893,8 @@ the STRINGS are just concatenated and the result truncated."
 
 (defun calendar-update-mode-line ()
   "Update the calendar mode line with the current date and date style."
-  (if (bufferp (get-buffer calendar-buffer))
+  (if (and calendar-mode-line-format
+           (bufferp (get-buffer calendar-buffer)))
       (with-current-buffer calendar-buffer
         (let ((start (- calendar-left-margin 2))
               (date (condition-case nil