Subject: Re: 30.0.50; [PATCH] Defaults to zero for image-dired--number-of-thumbnails

From: Manuel Giraud <[email-masked]>
Date: Thu, 23 Feb 2023 21:17:55 +0100

Manuel Giraud <[email-masked]> writes:

> Hi,
>
> Here is a patch to avoid "wrong type error" upon comparision to zero of
> image-dired--number-of-thumbnails.  How to reproduce:
>
>     - Do not have an existing *image-dired* buffer
>     - Hit 'C-t a' (image-dired-display-thumbs-append) on an image file
>       from Dired

Maybe this new version can go in too.  It updates the thumbnails counter
when removing a thumbnail.  What is not updated though is the number of
the image which is assign with a text-property at insertion...  So it is
not complete but an improvement nevertheless.
>From 04a3bc1cf9b3c2685c3edba1e0f792d8f28de6b2 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Thu, 23 Feb 2023 16:42:48 +0100
Subject: [PATCH] Defaults to zero for image-dired--number-of-thumbnails
 (bug#61734)

* lisp/image/image-dired.el (image-dired--number-of-thumbnails):
Defaults to zero to avoid wrong type error down the line.
(image-dired-delete-char): Update thumbnails counter upon deletion.
---
 lisp/image/image-dired.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el
index 8e2a75a418f..2c2968b1b49 100644
--- a/lisp/image/image-dired.el
+++ b/lisp/image/image-dired.el
@@ -546,7 +546,7 @@ image-dired--line-up-with-method
         (t
          (image-dired-line-up-dynamic))))
 
-(defvar-local image-dired--number-of-thumbnails nil)
+(defvar-local image-dired--number-of-thumbnails 0)
 
 ;;;###autoload
 (defun image-dired-display-thumbs (&optional arg append do-not-pop)
@@ -1127,9 +1127,11 @@ image-dired-delete-char
   "Remove current thumbnail from thumbnail buffer and line up."
   (interactive nil image-dired-thumbnail-mode)
   (let ((inhibit-read-only t))
-    (delete-char 1))
+    (delete-char 1)
+    (cl-decf image-dired--number-of-thumbnails))
   (let ((pos (point)))
     (image-dired--line-up-with-method)
+    (image-dired--update-header-line)
     (goto-char pos)))
 
 (defun image-dired-line-up ()
-- 
2.39.1

-- 
Manuel Giraud