unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 61734@debbugs.gnu.org
Subject: bug#61734: 30.0.50; [PATCH] Defaults to zero for image-dired--number-of-thumbnails
Date: Fri, 24 Feb 2023 10:35:38 +0100	[thread overview]
Message-ID: <87a6134d91.fsf@ledu-giraud.fr> (raw)
In-Reply-To: <87zg94gmq4.fsf@ledu-giraud.fr> (Manuel Giraud's message of "Thu,  23 Feb 2023 21:17:55 +0100")

[-- Attachment #1: Type: text/plain, Size: 154 bytes --]

Hi,

Here is another version that fixes all the "out of sync" counter that I
have… but maybe it start to grow outside the scope of this bug report.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fixes-on-image-dired-thumbnails-counter-bug-61734.patch --]
[-- Type: text/x-patch, Size: 3900 bytes --]

From 078cff71abc7125558ed492e894aa7d1b487d9bd Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Thu, 23 Feb 2023 16:42:48 +0100
Subject: [PATCH] Fixes on image-dired thumbnails counter (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.
(image-dired-insert-thumbnail, image-dired--update-header-line,
image-dired-display-thumbs): Remove 'image-number text-property and
rely on the (point).
---
 lisp/image/image-dired.el | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el
index 8e2a75a418f..c33a977e5dc 100644
--- a/lisp/image/image-dired.el
+++ b/lisp/image/image-dired.el
@@ -424,11 +424,10 @@ image-dired--get-create-thumbnail-file
                          (file-name-nondirectory thumb-file)))
     thumb-file))
 
-(defun image-dired-insert-thumbnail ( file original-file-name
-                           associated-dired-buffer image-number)
+(defun image-dired-insert-thumbnail (file original-file-name
+                                          associated-dired-buffer)
   "Insert thumbnail image FILE.
-Add text properties ORIGINAL-FILE-NAME, ASSOCIATED-DIRED-BUFFER
-and IMAGE-NUMBER."
+Add text properties ORIGINAL-FILE-NAME, ASSOCIATED-DIRED-BUFFER."
   (let (beg end)
     (setq beg (point))
     (image-dired-insert-image
@@ -452,7 +451,6 @@ image-dired-insert-thumbnail
            'keymap nil
            'original-file-name original-file-name
            'associated-dired-buffer associated-dired-buffer
-           'image-number image-number
            'tags (image-dired-list-tags original-file-name)
            'mouse-face 'highlight
            'comment (image-dired-get-comment original-file-name)))))
@@ -546,7 +544,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)
@@ -587,8 +585,8 @@ image-dired-display-thumbs
         (dolist (file files)
           (when (string-match-p (image-dired--file-name-regexp) file)
             (image-dired-insert-thumbnail
-             (image-dired--get-create-thumbnail-file file) file dired-buf
-             (cl-incf image-dired--number-of-thumbnails)))))
+             (image-dired--get-create-thumbnail-file file) file dired-buf)
+            (cl-incf image-dired--number-of-thumbnails))))
       (if (> image-dired--number-of-thumbnails 0)
           (if do-not-pop
               (display-buffer buf)
@@ -789,7 +787,7 @@ image-dired--update-header-line
     (let ((file-name (image-dired-original-file-name))
           (dired-buf (buffer-name (image-dired-associated-dired-buffer)))
           (image-count (format "%s/%s"
-                               (get-text-property (point) 'image-number)
+                               (1+ (/ (point) 2)) ;; Why this magical formula?
                                image-dired--number-of-thumbnails))
           (props (string-join (get-text-property (point) 'tags) ", "))
           (comment (get-text-property (point) 'comment))
@@ -1127,10 +1125,12 @@ 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)
-    (goto-char pos)))
+    (goto-char pos)
+    (image-dired--update-header-line)))
 
 (defun image-dired-line-up ()
   "Line up thumbnails according to `image-dired-thumbs-per-row'.
-- 
2.39.1


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

  reply	other threads:[~2023-02-24  9:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 16:02 bug#61734: 30.0.50; [PATCH] Defaults to zero for image-dired--number-of-thumbnails Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-23 20:17 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-24  9:35   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-02-27 13:20     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-27 13:59       ` Eli Zaretskii
2023-02-27 16:20         ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-28 13:26           ` Eli Zaretskii
2023-02-28 13:31             ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-28 14:23               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6134d91.fsf@ledu-giraud.fr \
    --to=bug-gnu-emacs@gnu.org \
    --cc=61734@debbugs.gnu.org \
    --cc=manuel@ledu-giraud.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).