help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set-window-vscroll sometimes doesn't work


From: Eli Zaretskii
Subject: Re: Set-window-vscroll sometimes doesn't work
Date: Sun, 18 Oct 2020 17:34:21 +0300

> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 17 Oct 2020 20:35:00 -0400
> 
> Normally if you scroll back onto an image, the image appears completely. I 
> want to instead only show part of the image, like what pixel scrolling would 
> do. If everything works as expected I should only see the bottom of the 
> image, instead I see the whole image.
> 
> It seems to be because (set-window-vscroll nil (- img-height 
> (frame-char-height)) t) didn’t take effect, if you call that again with M-: 
> or wrap it in (run-with-timer), then it works as expected.
> 
> Is this caused by some redisplay optimization or something?

No.  The problem is in your code.  First, you use set-window-start and
scroll-down, both of which tramp window-vscroll (as you probably
realize if you think about what those do).  And after all that, you
need one "normal" redisplay cycle before you can set the vscroll, so,
for example, a single change below should make the code work as you
expect.

(progn
  (switch-to-buffer (get-buffer-create "test"))
  (erase-buffer)
  (insert "\n\n")
  (insert-image (create-image "abby road.jpeg" nil nil :scale 0.1)
                "x")
  (insert "\n")
  (let ((after-img (point)))
    (set-window-start nil (point))
    (scroll-down 1)
    (sit-for 0)  ;; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    (let* ((img (plist-get (text-properties-at (window-start)) 'display))
           (img-height (cdr (image-size img t))))
      (set-window-vscroll nil (- img-height (frame-char-height)) t))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]