[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Set-window-vscroll sometimes doesn't work
From: |
Yuan Fu |
Subject: |
Re: Set-window-vscroll sometimes doesn't work |
Date: |
Sun, 18 Oct 2020 13:24:25 -0400 |
> On Oct 18, 2020, at 10:34 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> 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).
Why is so? Is there any material that I can read about these?
> 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))))
This works, but brings flickers: the image first shows completely then the
vscroll takes effect, which is reasonable but not preferred. I found that using
(set-window-start nil (point) t) with the third argument non-nil gives me the
desired effect. My guess is that, as the doctoring said, setting that to
non-nil prevents redisplay to try to make point completely visible, so
redisplay doesn’t modify vscroll, so my vscroll value survived. Is that right?
Thanks,
Yuan
- Set-window-vscroll sometimes doesn't work, Yuan Fu, 2020/10/17
- Re: Set-window-vscroll sometimes doesn't work, Eli Zaretskii, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work,
Yuan Fu <=
- Re: Set-window-vscroll sometimes doesn't work, Eli Zaretskii, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work, Yuan Fu, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work, Eli Zaretskii, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work, Yuan Fu, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work, Yuan Fu, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work, Eli Zaretskii, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work, Yuan Fu, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work, Eli Zaretskii, 2020/10/18
- Re: Set-window-vscroll sometimes doesn't work, Yuan Fu, 2020/10/19
- Re: Set-window-vscroll sometimes doesn't work, Yuan Fu, 2020/10/19