Subject: bug#54800: 28.1; calc: Cursor positioned at weird position in calc stack

From: Christoph Arenz <[email-masked]>
Date: Tue, 12 Apr 2022 17:45:42 +0200

On 11.04.22 16:53, Christoph Arenz wrote:
>
> On 11.04.22 13:45, Eli Zaretskii wrote:
>>>> I noticed that while the patch fixes the problem in most cases,
>>>> depending on the height of the calc stack window, there can be the
>>>> case
>>>> that the cursor is not positioned on the top-of-stack symbol `.'
>>>> but one
>>>> line
>>>> above, at the beginning of the line with the first stack entry.
>>>>
>>>> This can be changed by using the number 4 instead of 3 in the patch.
>>>> Not sure if this is the best fix.
>>>>
>>>> (vertical-motion (- 4 (window-height win)))
>>> Can you show a reproducible recipe starting from "emacs -Q", so I
>>> could investigate?
>> And while at that, would the below fix the problem in the rare cases
>> where you saw them?
>>
>>    (vertical-motion (- 3 (window-height win 'ceiling)))
>>
>> That is, ask window-height to produce the smallest integer number
>> greater than the window's height (in case the height in line units is
>> not integer)?
>
> Seems 'ceiling does not fix it, but 'floor does, like so:
>
>   (vertical-motion (- 3 (window-height win 'floor)))

And there are still cases where above does not work correctly.
E.g. when using a theme which has different line heights for header line
and mode line than for text lines,
say M-x load-theme leuven .

Approaching it differently seems to cover those cases as well:

     (vertical-motion (- 1 (window-body-height)))

>
> How to reproduce -- I could not find a way to do so automatically,
> here is for a manual way:
>
> 1. emacs -Q
> 2. C-x * *
> 3. enter some numbers to fill calc stack window, and some more
3a. Even finer-grained risizing and watching the effects can be achieved by
M-: (setq window-resize-pixelwise t)
> 4. o (calc-realign)
> 5. watch where the cursor is placed: on the top-of-stack symbol, or
> on the beginning of the line with the first stack entry.
> 6. increase the stack window height by minimally moving the mode line
> above the stack window with the mouse; only increase height by
> sub-line-height amount
> 7. repeat 4. to 6. until you can observe the symptom
>
>