Subject: bug#70038: 29.3.50; Shift up/down in buffer with images on M-x other-window with some fonts

From: Ramon Diaz-Uriarte <[email-masked]>
Date: Sun, 31 Mar 2024 20:43:48 +0200

For me, this setting fixes the problem when there is no dependence on fonts:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq read-minibuffer-restore-windows nil)
(progn
  (defun pin-vscroll-down (win)
    (set-window-vscroll win 200 t))
   (let* ((height (/ (* 2 (frame-pixel-height)) 5))
         (image1 (create-image "/tmp/image1.png" nil nil :height height))
         (image2 (create-image "/tmp/image2.png" nil nil :height height))
         (image3 (create-image "/tmp/image3.png" nil nil :height height)))
    (with-current-buffer (get-buffer-create "*image-scroll-test*")
      (insert " \n \n \n \n \n \n")
      (put-image image1 1)
      (put-image image2 5)
      (put-image image3 9)
      ;; With larger image sizes (goto-char 3)
      ;; also consistently triggers the problem.
      (goto-char 11)
      (add-hook 'pre-redisplay-functions #'pin-vscroll-down nil t))
    (split-window-right)
    (other-window 1)
    (switch-to-buffer "*image-scroll-test*")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

However, it does not solve the problem when I change fonts:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq read-minibuffer-restore-windows nil)
(progn
  (defun pin-vscroll-down (win)
    (set-window-vscroll win 200 t))
  ;; Any of the following leads to the bug
  (set-frame-font "JuliaMono" nil t)
  ;; (set-frame-font "DM Mono" nil t)
  ;; (set-frame-font "Intel One Mono" nil t)
  (let* ((height (/ (* 2 (frame-pixel-height)) 15))
         (image1 (create-image "/tmp/image1.png" nil nil :height height))
         (image2 (create-image "/tmp/image2.png" nil nil :height height))
         (image3 (create-image "/tmp/image3.png" nil nil :height height)))
    (with-current-buffer (get-buffer-create "*image-scroll-test*")
      (insert " \n \n \n \n \n \n")
      (put-image image1 1)
      (put-image image2 5)
      (put-image image3 9)
      ;; With larger image sizes (goto-char 3)
      ;; also triggers the problem.
      (goto-char 11)
      (add-hook 'pre-redisplay-functions #'pin-vscroll-down nil t))
    (split-window-right)
    (other-window 1)
    (switch-to-buffer "*image-scroll-test*")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

As mentioned initially, this issue was found when trying to solve a similar problem with pdf-tools: https://github.com/vedang/pdf-tools/pull/224#issuecomment-2014151358

Setting

(setq read-minibuffer-restore-windows nil)

solves the pdf-tools continuous scrolling issue when there is no change in font but not when we change font (https://github.com/vedang/pdf-tools/pull/224#issuecomment-2026142343 )

Best,

R.

On Thu, 28-March-2024, at 21:50:49, Rahguzar <[email-masked]> wrote:
> On further testing,
>
> (setq read-minibuffer-restore-windows nil)
>
> makes the problem go away.
>
> Rahguzar <[email-masked]> writes:
>
>> Hi Ramon,
>>
>> Ramon Diaz-Uriarte <[email-masked]> writes:
>>
>>> Actually, maybe I can claim those bonus points: this does not depend on fonts, though I am triggering it using the package vertico (so maybe this example is vertico's fault):
>>>
>>>
>>> Steps:
>>>
>>> 1. emacs -Q
>>> 2. eval this code
>>>
>>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>> (package-initialize)
>>> (vertico-mode 1)
>>>
>>> (progn
>>>   (defun pin-vscroll-down (win)
>>>     (set-window-vscroll win 200 t))
>>>    (let* ((height (/ (* 2 (frame-pixel-height)) 15))
>>>          (image1 (create-image "/tmp/image1.png" nil nil :height height))
>>>          (image2 (create-image "/tmp/image2.png" nil nil :height height))
>>>          (image3 (create-image "/tmp/image3.png" nil nil :height height)))
>>>     (with-current-buffer (get-buffer-create "*image-scroll-test*")
>>>       (insert " \n \n \n \n \n \n")
>>>       (put-image image1 1)
>>>       (put-image image2 5)
>>>       (put-image image3 9)
>>>       ;; With larger image sizes (goto-char 3)
>>>       ;; also consistently triggers the problem.
>>>       (goto-char 11)
>>>       (add-hook 'pre-redisplay-functions #'pin-vscroll-down nil t))
>>>     (split-window-right)
>>>     (other-window 1)
>>>     (switch-to-buffer "*image-scroll-test*")))
>>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>>
>>> 3. Do `M-x` (or C-x b). No need to execute anything or switch buffers, just have the minibuffer show options.
>>>
>>> 4. `C-x o`  a few times. You'll see the images move up and down.
>>>
>>> I am seeing this in Lucid and GTK builds.
>>
>> I can also reproduce this now! And vertico mode can be replaced with the
>> builtin icomplete-vertical-mode. So, the following recipe starting with
>> emacs -Q works for me:
>>
>> 1) Paste
>> (let ((height (/ (* 2 (frame-pixel-height)) 15)))
>>   (icomplete-vertical-mode)
>>   (defun pin-vscroll-down (win)
>>     (set-window-vscroll win (/ height 2) t))
>>   (let ((image1 (create-image "~/Downloads/image1.png" nil nil :height height))
>>         (image2 (create-image "~/Downloads/image2.png" nil nil :height height))
>>         (image3 (create-image "~/Downloads/image3.png" nil nil :height height)))
>>     (with-current-buffer (get-buffer-create "*image-scroll-test*")
>>       (insert " \n \n \n \n \n \n")
>>       (put-image image1 1)
>>       (put-image image2 5)
>>       (put-image image3 9)
>>       ;; With larger image sizes (goto-char 3)
>>       ;; also consistently triggers the problem.
>>       (goto-char 11)
>>       (add-hook 'pre-redisplay-functions #'pin-vscroll-down nil t))
>>     (split-window-right)
>>     (other-window 1)
>>     (switch-to-buffer "*image-scroll-test*")))
>>
>> into scratch buffer.
>>
>> 2) Evaluate the form above using `C-M-x`.
>>
>> 3) Type M-x t
>>
>> 4) Wait till minibuffer expands to show completions, then type `C-g` to
>> quit minibuffer.
>>
>> 5) Typing `C-x 0` results in the window with images losing vscroll.
>>
>>> Best,
>>>
>>> R.
>>
>> Rahguzar

-- 
Ramon Diaz-Uriarte
Department of Biochemistry, Lab B-31
Facultad de Medicina 
Universidad Autónoma de Madrid 
Arzobispo Morcillo, 4
28029 Madrid
Spain