Subject: bug#78957: 31.0.50; Wrong mode-line in fancy diary

From: Manuel Giraud <[email-masked]>
Date: Fri, 11 Jul 2025 13:44:20 +0200

martin rudalics <[email-masked]> writes:

>  > Martin, any comments to the patch, with emphasis on its safety?
>
> If the patch is this one
>
> diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
> index 917624c489e..8b7aa71db93 100644
> --- a/lisp/calendar/calendar.el
> +++ b/lisp/calendar/calendar.el
> @@ -1168,8 +1168,9 @@ calendar-in-read-only-buffer
>              buffer-undo-list t)
>        (erase-buffer)
>        (display-buffer ,buffer)
> -     ,@body
> -     (goto-char (point-min))
> +     (with-selected-window (get-buffer-window ,buffer)
> +       ,@body
> +       (goto-char (point-min)))
>        (set-buffer-modified-p nil)
>        (setq buffer-read-only t)))
> Switch to BUFFER
> then I would write it as
>
> diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
> index 917624c489e..67764eb0b26 100644
> --- a/lisp/calendar/calendar.el
> +++ b/lisp/calendar/calendar.el
> @@ -1167,9 +1167,11 @@ calendar-in-read-only-buffer
>        (setq buffer-read-only nil
>              buffer-undo-list t)
>        (erase-buffer)
> -     (display-buffer ,buffer)
> -     ,@body
> -     (goto-char (point-min))
> +     (let ((window (display-buffer ,buffer)))
> +       (when window
> +	 (with-selected-window window
> +	   ,@body
> +	   (goto-char (point-min)))))
>        (set-buffer-modified-p nil)
>        (setq buffer-read-only t)))
>
> which selects the correct window if there is one.

So, there is something I missed with both patches.  After a complete
rebuild of Emacs with the patch, the misalignment in the mode-line is
still there.  But if afterward, I `load-file' "calendar.el" and then
"diary-lib.el", the misalignment is fixed.  What am I missing?

> But I doubt that it is a good idea to use 'set-buffer' here and talk
> about "Switch to BUFFER" in the first place.

Yes, we'd have to modify the docstring.
-- 
Manuel Giraud