Subject: Re: bug#65052: 30.0.50; [PATCH] Scroll-{up, down} does not update tracking info in image-dired

From: Manuel Giraud <[email-masked]>
Date: Fri, 04 Aug 2023 22:58:25 +0200

Eli Zaretskii <[email-masked]> writes:

[...]

> OK, but then this part:
>
>> +  ;; "one line" dance to update tracking and header
>> +  (image-dired-next-line)
>> +  (image-dired-previous-line))
>
> looks like a kludge.  Can't we have a cleaner code for updating the
> header data?  If image-dired-previous/next-line can update the data,
> why cannot the scroll commands do the same without calling the
> line-movement commands?

You're right.  Here is a cleaner version inspired by
`image-dired--movement-command-line'.
-- 
Manuel Giraud
>From 9395c814d5664f5d31490ee63de43fa3478b7143 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Thu, 9 Mar 2023 14:35:31 +0100
Subject: [PATCH] Scroll up and down in image-dired

* lisp/image/image-dired.el (image-dired--movement-command-scroll):
Macro to manage scroll in image-dired.
(image-dired-scroll-up, image-dired-scroll-down): Scroll up and down
command in image-dired.
(image-dired-thumbnail-mode-map): Use them.
---
 lisp/image/image-dired.el | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el
index 33beb5b3e49..067134fd331 100644
--- a/lisp/image/image-dired.el
+++ b/lisp/image/image-dired.el
@@ -740,6 +740,16 @@ image-dired--movement-command-line
        (point))
      ,reverse))
 
+(defmacro image-dired--movement-command-scroll (&optional reverse)
+  `(image-dired--movement-command
+     (let ((goal-column (current-column)))
+       ,(if reverse
+            '(scroll-down)
+          '(scroll-up))
+       (move-to-column goal-column)
+       (point))
+     ,reverse))
+
 (defun image-dired-next-line ()
   "Move to next line in the thumbnail buffer."
   (interactive nil image-dired-thumbnail-mode)
@@ -770,6 +780,16 @@ image-dired-move-end-of-line
   (interactive nil image-dired-thumbnail-mode)
   (image-dired--movement-command (pos-eol) 'reverse))
 
+(defun image-dired-scroll-up ()
+  "Scroll up the in thumbnail buffer."
+  (interactive nil image-dired-thumbnail-mode)
+  (image-dired--movement-command-scroll))
+
+(defun image-dired-scroll-down ()
+  "Scroll down the in thumbnail buffer."
+  (interactive nil image-dired-thumbnail-mode)
+  (image-dired--movement-command-scroll 'reverse))
+
 
 ;;; Header line
 
@@ -980,6 +1000,8 @@ image-dired-thumbnail-mode-map
   "<remap> <end-of-buffer>"          #'image-dired-end-of-buffer
   "<remap> <move-beginning-of-line>" #'image-dired-move-beginning-of-line
   "<remap> <move-end-of-line>"       #'image-dired-move-end-of-line
+  "<remap> <scroll-up-command>"      #'image-dired-scroll-up
+  "<remap> <scroll-down-command>"    #'image-dired-scroll-down
 
   :menu
   '("Image-Dired"
-- 
2.40.0