GNU bug report logs - #78957
31.0.50; Wrong mode-line in fancy diary

Previous Next

Package: emacs;

Reported by: Manuel Giraud <manuel <at> ledu-giraud.fr>

Date: Fri, 4 Jul 2025 19:16:02 UTC

Severity: normal

Found in version 31.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #14 received at 78957 <at> debbugs.gnu.org (full text, mbox):

From: Stephen Berman <stephen.berman <at> gmx.net>
To: Manuel Giraud <manuel <at> ledu-giraud.fr>
Cc: 78957 <at> debbugs.gnu.org
Subject: Re: bug#78957: 31.0.50; Wrong mode-line in fancy diary
Date: Sat, 05 Jul 2025 12:02:52 +0200
[Message part 1 (text/plain, inline)]
On Sat, 05 Jul 2025 10:53:11 +0200 Manuel Giraud <manuel <at> ledu-giraud.fr> wrote:

> Stephen Berman <stephen.berman <at> gmx.net> writes:
>
>> On Fri, 04 Jul 2025 21:14:52 +0200 Manuel Giraud <manuel <at> ledu-giraud.fr> wrote:
>>
>>> Hi,
>>>
>>> When viewing diary entry from the calendar, the mode line could be set
>>> erroneously.  The recipe:
>>>
>>>           - Have a file "/tmp/diary" with the following content:
>>>
>>> July 4, 2025 A bitter day for many
>>>
>>>           - emacs -Q
>>>           - M-: (setopt diary-file "/tmp/diary") <RET>
>>>           - M-: (toggle-frame-fullscreen) <RET>
>>>           - M-: (calendar) <RET>
>>>           - g d
>>>           - 2025 <RET>
>>>           - July <RET>
>>>           - 4 <RET>
>>>           - d
>>>
>>> Observe that the date in the mode line of the diary view buffer is not
>>> centered and maybe partly out of sight.  This seems to come from the
>>> fact that the call to `window-edges' in `calendar-set-mode-line' does
>>> not return correct values but I can't figure out why.
>>
>> I think it's because both times `window-edges' is called in
>> `diary-fancy-display' the selected window is the one displaying the
>> Calendar, whose `window-width' is the full screen width due to
>> `toggle-frame-fullscreen', while the window displaying the Fancy Diary
>> is half as wide.  The following patch seems to fix the problem for me:
>>
>> diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el
>> index 8fb6fadfe4c..3b0275d4cee 100644
>> --- a/lisp/calendar/diary-lib.el
>> +++ b/lisp/calendar/diary-lib.el
>> @@ -1058,7 +1058,8 @@ diary-fancy-display
>>    (unless (car (diary-display-no-entries)) ; no entries
>>      ;; Prepare the fancy diary buffer.
>>      (calendar-in-read-only-buffer diary-fancy-buffer
>> -      (calendar-set-mode-line "Diary Entries")
>> +      (with-selected-window (get-buffer-window diary-fancy-buffer)
>> +        (calendar-set-mode-line "Diary Entries"))
>>        (let ((holiday-list-last-month 1)
>>              (holiday-list-last-year 1)
>>              (date (list 0 0 0))
>> @@ -1139,7 +1140,8 @@ diary-fancy-display
>>        (if (eq major-mode 'diary-fancy-display-mode)
>>            (run-hooks 'diary-fancy-display-mode-hook)
>>          (diary-fancy-display-mode))
>> -      (calendar-set-mode-line diary--date-string))))
>> +      (with-selected-window (get-buffer-window diary-fancy-buffer)
>> +        (calendar-set-mode-line diary--date-string)))))
>
> Thanks!  That works as expected.  I thought that the set-buffer (from
> calendar-in-read-only-buffer) was enough but apparently not.
>
> While here, I will complete your patch for other calls of
> calendar-set-mode-line (lunar phases,...)

I hope you haven't spent time on that yet, because it occurred to me
that the following patch might suffice:

[Message part 2 (text/x-patch, inline)]
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index 917624c489e..6b23cbcd1d4 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -1167,7 +1167,7 @@ calendar-in-read-only-buffer
      (setq buffer-read-only nil
            buffer-undo-list t)
      (erase-buffer)
-     (display-buffer ,buffer)
+     (select-window (display-buffer ,buffer))
      ,@body
      (goto-char (point-min))
      (set-buffer-modified-p nil)
[Message part 3 (text/plain, inline)]
It seems to DTRT for all users of `calendar-in-read-only-buffer' (after
byte-compiling), if I haven't overlooked anything.

Steve Berman

This bug report was last modified 13 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.