On Sat, 05 Jul 2025 10:53:11 +0200 Manuel Giraud wrote: > Stephen Berman writes: > >> On Fri, 04 Jul 2025 21:14:52 +0200 Manuel Giraud 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") >>> - M-: (toggle-frame-fullscreen) >>> - M-: (calendar) >>> - g d >>> - 2025 >>> - July >>> - 4 >>> - 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: