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: Yuan Fu
Subject: Re: Set-window-vscroll sometimes doesn't work
Date: Mon, 19 Oct 2020 16:39:11 -0400

>> 
>> What I came up with is this:
>> 
>> For (scroll-up 1):
> 
> That's your problem, right there: scroll-up is not the right command
> for this.  Scroll commands work by setting window-start, and you don't
> want that with large images.  They also move by window-full, again
> something that is not appropriate for scrolling images.  You'd need a
> different command for your use case.
> 
> Please read the code in simple.el, the functions line-move,
> line-move-1, and line-move-partial -- those perform scrolling of tall
> images when needed.  You will find there how to decide when to set
> vscroll and to what value; I suggest to use a similar strategy.

Sorry for the confusion, I didn't mean to use scroll-up directly, I meant 
“(my-scroll-up 1)”.

These functions only handle the case where the line is taller than the window, 
so they either adjust vscroll or scroll with scroll-up/down but never both, 
which isn’t too helpful. Because in my use case I sometimes need to scroll and 
adjust vscroll in the same time. Suppose I have a line followed by an image in 
my buffer:

+------------------------------------+
|        first line                  |
+------------------------------------+
|        image                       |
|                                    |
|                                    |
|                                    |
|                                    |
|                                    |
|                                    |
+------------------------------------+


And I want to “scroll 3 lines up", then with my strategy I need to scroll up 
one display line and adjust vscroll to 2x default-line-height. In other word:

(set-window-start nil point-of-image t)
(set-window-vscroll nil (* 2 (default-line-height)) t)

> 
>> 
>> 1. If the first row is a normal line (i.e., with normal height), scroll up 
>> normally by one display line.
>> 2. If the first row is an image, adjust vscroll += 
>> frame-default-pixel-line-height
>> 3. If the first row is an image and we have scrolled to the bottom of the 
>> image, i.e., vscroll = image-height, scroll up one display line and set 
>> vscroll to 0.
> 
> You can do it this way, but I think it will be confusing because
> scroll-up is rarely used with an argument of 1.
> 
> But if you insist on doing this inside scroll-up, then items 2 and 3
> should do what line-move-visual etc. in simple.el do when they need to
> scroll a tall image.  They do exactly what you describe above (they
> also do other stuff, which you can remove if you want).

The strategy also works with an argument larger than 1. Again, those functions 
never need to scroll and adjust vscroll in the same time.

> 
>> In other words, sometimes we are not really scrolling, but faking a scroll 
>> by adjusting vscroll. IIUC window_scroll_pixel_based moves it by 
>> move_it_by_lines and set window-start to it. That’s not what we want when we 
>> want to fake scroll by adjusting vscroll: in that case we don’t want to 
>> change window-start.
> 
> Indeed, that's not what we want.  Which is why scroll commands are not
> the right starting point for what you want to do.

Maybe I should state what I want to do clearly: I want to achieve the smooth 
scrolling when both scrolling and moving point, i.e., both scroll-up/down and 
next/previous-line, that ensures I never have annoying jumpy images.

With my limited knowledge, setting window-start (aka scroll) and setting 
vscroll in the same time is the only way to to get what I want. But it is 
against the design of the display engine. Is there anyway out of this?


Thanks,
Yuan




reply via email to

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