Subject: 24.3.93; Diary can wrongly be displayed in Calendar's window

From: Stephen Berman <[email-masked]>
Date: Mon, 01 Sep 2014 16:59:26 +0200

0. emacs -Q
1. Type `M-x calendar' and then `i d' to create a diary file with an
   entry for today.
2. M-x customize-option RET calendar-view-diary-initially-flag RET,
   toggle the value to `On' and save for current session.
3. M-x diary => The diary entry made in step 1 is displayed (in the
   Fancy Diary) in the lower window (which is not the selected window).
4. M-x calendar => The lower window resizes to fit the Calendar, which
   is fleetingly displayed in it but then replaced by the Fancy Diary
   display (in the same resized window).

The same problem happens if the simple diary display is used (e.g. by
customizing diary-display-function).

A real (i.e. my) use case which exposes this problem is to add
`(appt-activate 1)' to your init-file (cf. the commentary in appt.el) so
you see e.g. today's diary entries as in step 3 on starting Emacs, and
then you open the Calendar as in step 4.

The patch below fixes the problem for me, for both types of diary
display, though I haven't yet checked whether the change to
calendar-in-read-only-buffer adversely affects the other users of this
macro, since those are functions I don't use.

This problem does not happen in 24.3 (at least not in the one packaged
with openSUSE 13.1, for which I don't have the Lisp sources at hand), so
the fix should be committed to emacs-24.

In GNU Emacs 24.3.93.7 (x86_64-suse-linux-gnu, GTK+ Version 3.10.4)
 of 2014-08-31 on rosalinde
Repository revision: 117464 [email-masked]
Windowing system distributor `The X.Org Foundation', version 11.0.11403901
System Description:	openSUSE 13.1 (Bottle) (x86_64)

Configured using:
 `configure --without-toolkit-scroll-bars 'CFLAGS=-g3 -O0''

=== modified file 'lisp/calendar/calendar.el'
*** lisp/calendar/calendar.el	2014-03-17 16:04:32 +0000
--- lisp/calendar/calendar.el	2014-09-01 13:02:00 +0000
***************
*** 1208,1214 ****
       (goto-char (point-min))
       (set-buffer-modified-p nil)
       (setq buffer-read-only t)
!      (display-buffer ,buffer)))
  
  ;; The following are in-line for speed; they can be called thousands of times
  ;; when looking up holidays or processing the diary.  Here, for example, are
--- 1208,1214 ----
       (goto-char (point-min))
       (set-buffer-modified-p nil)
       (setq buffer-read-only t)
!      (display-buffer ,buffer t)))
  
  ;; The following are in-line for speed; they can be called thousands of times
  ;; when looking up holidays or processing the diary.  Here, for example, are

=== modified file 'lisp/calendar/diary-lib.el'
*** lisp/calendar/diary-lib.el	2014-01-01 07:43:34 +0000
--- lisp/calendar/diary-lib.el	2014-09-01 12:28:23 +0000
***************
*** 1023,1029 ****
        (calendar-set-mode-line (format "Diary for %s" (cdr empty))))
      (unless (car empty)                 ; no entries
        (with-current-buffer dbuff
!         (let ((window (display-buffer (current-buffer))))
            ;; d-s-p is passed from diary-list-entries.
            (set-window-point window diary-saved-point)
            (set-window-start window (point-min)))))))
--- 1023,1029 ----
        (calendar-set-mode-line (format "Diary for %s" (cdr empty))))
      (unless (car empty)                 ; no entries
        (with-current-buffer dbuff
!         (let ((window (display-buffer (current-buffer) t)))
            ;; d-s-p is passed from diary-list-entries.
            (set-window-point window diary-saved-point)
            (set-window-start window (point-min)))))))