Subject: Re: bug#34138: 27.0.50; Delayed display of PDF file images

From: Andreas Politz <[email-masked]>
Date: Mon, 21 Jan 2019 20:14:07 +0100

Eli Zaretskii <[email-masked]> writes:

> In any case, is it certain that once
> pdf-view-maybe-redisplay-resized-windows starts running, the image is
> displayed immediately without delays?

I don't think that pdf-view-maybe-redisplay-resized-windows is related
to this problem.  It does basically nothing on the first call, except
store the window's size, i.e. no redisplay.

pdf-tools, like doc-view, uses image-mode to manage the displayed image
of the current pdf page.  I.e. it adds a function to the hook
image-mode-new-window-functions.

image-mode uses window-configuration-change-hook to check whether a new
window for the buffer it was activated for was created.  In this case it
runs the hook image-mode-new-window-functions.  This is the hook
pdf-tools attaches itself to in order to create an overlay with a window
property and the image of the current page.

Usually, i.e. in Emacs 26.1, this is sufficient for the image to be
visible immediately (or at least immediately after the function has
returned and Emacs is idle).  Conversely, in the current master branch,
the image is not visible until, as it seems, the next redraw cycle.

Note, that I don't see a delay. Rather nothing seems to happen until I
trigger a redisplay, for example via M-x.

I also traced the mentioned function (pdf-view-new-window-function) and
verified that there is no different in both Emacs versions regarding the
number of times they are called and the nature of their arguments.  The
trace, opening a PDF document in a single windowed frame via dired,
looks like this

======================================================================
1 -> (pdf-view-new-window-function (t))
1 <- pdf-view-new-window-function: #<overlay in no buffer>
======================================================================
1 -> (pdf-view-new-window-function (#<window 3 on The_Joy_of_Clojure.pdf> (page . 1) (overlay . #<overlay in no buffer>)))
1 <- pdf-view-new-window-function: #<overlay from 1 to 9221925 in The_Joy_of_Clojure.pdf>

The first call happens when pdf-view-mode initiates image-mode.  The car
of argument is usually a window.  Unless the buffer is not displayed, in
which case t is used.  The cdr is a property list.

The second call creates the relevant overlay with the image property.
Note that I modified the function to return the used overlay, usually it
returns nil.

Andreas