unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#50000: 27.2; tagging marked thumbnails
@ 2021-08-11 10:01 Peter Münster
  2021-08-11 12:21 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Münster @ 2021-08-11 10:01 UTC (permalink / raw)
  To: 50000

Hi,

It would be nice, if one could tag all images, that are marked in
image-dired-thumbnail-mode.

Here is the function image-dired-tag-marked-thumbnails, that does it:
https://github.com/p-m/image-dired/blob/master/image-dired.el

What do think about that?

-- 
           Peter





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-11 10:01 bug#50000: 27.2; tagging marked thumbnails Peter Münster
@ 2021-08-11 12:21 ` Lars Ingebrigtsen
  2021-08-11 14:31   ` Peter Münster
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-11 12:21 UTC (permalink / raw)
  To: Peter Münster; +Cc: 50000

Peter Münster <pm@a16n.net> writes:

> It would be nice, if one could tag all images, that are marked in
> image-dired-thumbnail-mode.
>
> Here is the function image-dired-tag-marked-thumbnails, that does it:
> https://github.com/p-m/image-dired/blob/master/image-dired.el
>
> What do think about that?

Sure; makes sense to me.  Can you submit it as a patch?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-11 12:21 ` Lars Ingebrigtsen
@ 2021-08-11 14:31   ` Peter Münster
  2021-08-11 16:02     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Münster @ 2021-08-11 14:31 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50000

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

On Wed, Aug 11 2021, Lars Ingebrigtsen wrote:

> Can you submit it as a patch?

Yes, I attach it here.

There are 2 more things: image-dired-delete-marked and a suggestion for
another placement of the calls to image-dired-thumb-update-marks.

--- image-dired.el-orig	2021-08-11 16:09:03.312541533 +0200
+++ image-dired.el	2021-08-11 13:13:01.561075067 +0200
@@ -1005,6 +1003,19 @@
       (set-window-configuration image-dired-saved-window-configuration)
     (message "No saved window configuration")))
 
+(defun image-dired-line-up-with-method ()
+  "Line up thumbnails according to `image-dired-line-up-method'."
+  (cond ((eq 'dynamic image-dired-line-up-method)
+         (image-dired-line-up-dynamic))
+        ((eq 'fixed image-dired-line-up-method)
+         (image-dired-line-up))
+        ((eq 'interactive image-dired-line-up-method)
+         (image-dired-line-up-interactive))
+        ((eq 'none image-dired-line-up-method)
+         nil)
+        (t
+         (image-dired-line-up-dynamic))))
+
 ;;;###autoload
 (defun image-dired-display-thumbs (&optional arg append do-not-pop)
   "Display thumbnails of all marked files, in `image-dired-thumbnail-buffer'.
@@ -1046,16 +1057,7 @@
       (if do-not-pop
           (display-buffer buf)
         (pop-to-buffer buf))
-      (cond ((eq 'dynamic image-dired-line-up-method)
-             (image-dired-line-up-dynamic))
-            ((eq 'fixed image-dired-line-up-method)
-             (image-dired-line-up))
-            ((eq 'interactive image-dired-line-up-method)
-             (image-dired-line-up-interactive))
-            ((eq 'none image-dired-line-up-method)
-             nil)
-            (t
-             (image-dired-line-up-dynamic))))))
+      (image-dired-line-up-with-method))))
 
 ;;;###autoload
 (defun image-dired-show-all-from-dir (dir)
@@ -1186,6 +1188,14 @@
         (cons x tag))
       files))))
 
+(defun image-dired-tag-marked-thumbnails ()
+  "Tag marked thumbnails."
+  (interactive)
+  (let ((dired-buf (image-dired-associated-dired-buffer)))
+    (if dired-buf
+        (with-current-buffer dired-buf
+          (image-dired-tag-files nil)))))
+
 (defun image-dired-tag-thumbnail ()
   "Tag current thumbnail."
   (interactive)
@@ -1417,27 +1427,26 @@
         (message "No image, or image with correct properties, at point.")
     (with-current-buffer dired-buf
         (message "%s" file-name)
-        (if (dired-goto-file file-name)
-            (cond ((eq command 'mark) (dired-mark 1))
-                  ((eq command 'unmark) (dired-unmark 1))
-                  ((eq command 'toggle)
-                   (if (image-dired-dired-file-marked-p)
-                       (dired-unmark 1)
-                     (dired-mark 1)))
-                  ((eq command 'flag) (dired-flag-file-deletion 1))))))))
+        (when (dired-goto-file file-name)
+          (cond ((eq command 'mark) (dired-mark 1))
+                ((eq command 'unmark) (dired-unmark 1))
+                ((eq command 'toggle)
+                 (if (image-dired-dired-file-marked-p)
+                     (dired-unmark 1)
+                   (dired-mark 1)))
+                ((eq command 'flag) (dired-flag-file-deletion 1)))
+          (image-dired-thumb-update-marks))))))
 
 (defun image-dired-mark-thumb-original-file ()
   "Mark original image file in associated dired buffer."
   (interactive)
   (image-dired-modify-mark-on-thumb-original-file 'mark)
-  (image-dired-thumb-update-marks)
   (image-dired-forward-image))
 
 (defun image-dired-unmark-thumb-original-file ()
   "Unmark original image file in associated dired buffer."
   (interactive)
   (image-dired-modify-mark-on-thumb-original-file 'unmark)
-  (image-dired-thumb-update-marks)
   (image-dired-forward-image))
 
 (defun image-dired-flag-thumb-original-file ()
@@ -1449,8 +1458,7 @@
 (defun image-dired-toggle-mark-thumb-original-file ()
   "Toggle mark on original image file in associated dired buffer."
   (interactive)
-  (image-dired-modify-mark-on-thumb-original-file 'toggle)
-  (image-dired-thumb-update-marks))
+  (image-dired-modify-mark-on-thumb-original-file 'toggle))
 
 (defun image-dired-jump-original-dired-buffer ()
   "Jump to the dired buffer associated with the current image file.
@@ -2331,19 +2339,32 @@
   "Check if file is marked in associated dired buffer."
   (let ((file-name (image-dired-original-file-name))
         (dired-buf (image-dired-associated-dired-buffer)))
    (when (and dired-buf file-name)
      (with-current-buffer dired-buf
        (when (dired-goto-file file-name)
          (image-dired-dired-file-marked-p))))))
+
+(defun image-dired-delete-marked ()
+  "Delete marked thumbnails and associated images."
+  (interactive)
+  (goto-char (point-min))
+  (let ((dired-buf (image-dired-associated-dired-buffer)))
+    (while (not (eobp))
+      (if (image-dired-thumb-file-marked-p)
+          (image-dired-delete-char)
+        (forward-char)))
+    (image-dired-line-up-with-method)
+    (with-current-buffer dired-buf
+      (dired-do-delete))))
 
 (defun image-dired-thumb-update-marks ()
   "Update the marks in the thumbnail buffer."
   (when image-dired-thumb-visible-marks
     (with-current-buffer image-dired-thumbnail-buffer
-      (save-excursion
+      (save-mark-and-excursion ; todo: mark-active is not restored, bug #49999
         (goto-char (point-min))
         (let ((inhibit-read-only t))
           (while (not (eobp))
             (if (image-dired-thumb-file-marked-p)
                 (add-face-text-property
                  (point) (1+ (point))

-- 
           Peter

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 211 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-11 14:31   ` Peter Münster
@ 2021-08-11 16:02     ` Lars Ingebrigtsen
  2021-08-13 13:04       ` Peter Münster
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-11 16:02 UTC (permalink / raw)
  To: Peter Münster; +Cc: 50000

Peter Münster <pm@a16n.net> writes:

>> Can you submit it as a patch?
>
> Yes, I attach it here.
>
> There are 2 more things: image-dired-delete-marked and a suggestion for
> another placement of the calls to image-dired-thumb-update-marks.

Makes sense.  Applied to Emacs 28.  Should these new commands have key
bindings?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-11 16:02     ` Lars Ingebrigtsen
@ 2021-08-13 13:04       ` Peter Münster
  2021-08-14 11:51         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Münster @ 2021-08-13 13:04 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50000


[-- Attachment #1.1: Type: text/plain, Size: 354 bytes --]

On Wed, Aug 11 2021, Lars Ingebrigtsen wrote:

> Makes sense.  Applied to Emacs 28.  Should these new commands have key
> bindings?

I don't know. And if yes, how to chose the best bindings? (I have
private key-bindings in my init.el).

Perhaps at least menu bindings. A patch is attached (with also some
refactoring).

-- 
           Peter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Add-menu-bindings-to-new-functions-in-image-dired.el.patch --]
[-- Type: text/x-patch, Size: 6581 bytes --]

From 2bee2a5a92a4d3593a60ded577731966c09c68cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Fri, 13 Aug 2021 15:02:03 +0200
Subject: [PATCH] Add menu bindings to new functions in image-dired.el

* lisp/image-dired.el (image-dired--with-marked): New macro for
cycling over marked thumbnails.
(image-dired-tag-thumbnail, image-dired-tag-thumbnail-remove): Rename to
plural forms, because they can handle now also all marked thumbnails.
(image-dired-tag-marked-thumbnails): Remove it, because it's obsoleted by
`image-dired-tag-thumbnails' now.
(image-dired-delete-marked): Use new macro `image-dired--with-marked', and
add command to menu.
---
 etc/NEWS            |  7 +++--
 lisp/image-dired.el | 70 ++++++++++++++++++++++++++-------------------
 2 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 26ede71523..6aa574eda3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2415,10 +2415,13 @@ This command, called interactively, toggles the local value of
 If non-nil (the default), use 'image-dired-thumb-mark' to say what
 images are marked.
 
-*** New command 'image-dired-tag-marked-thumbnails'.
-
 *** New command 'image-dired-delete-marked'.
 
+*** New names for some functions.
+Function 'image-dired-tag-thumbnail' is renamed 'image-dired-tag-thumbnails'.
+Function 'image-dired-tag-thumbnail-remove' is renamed
+'image-dired-tag-thumbnails-remove'.
+
 ** Miscellaneous
 
 ---
diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 7092f758db..520d8cdb34 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -797,6 +797,21 @@ Queued items live in `image-dired-queue'."
                (list (list original-file thumbnail-file))))
   (run-at-time 0 nil #'image-dired-thumb-queue-run))
 
+(defmacro image-dired--with-marked (&rest body)
+  "Eval BODY with point on each marked thumbnail. If no marked file could
+be found, execute BODY on the current thumbnail."
+  `(with-current-buffer image-dired-thumbnail-buffer
+     (let (found)
+       (save-mark-and-excursion
+         (goto-char (point-min))
+         (while (not (eobp))
+           (when (image-dired-thumb-file-marked-p)
+             (setq found t)
+             ,@body)
+           (forward-char)))
+       (unless found
+         ,@body))))
+
 ;;;###autoload
 (defun image-dired-dired-toggle-marked-thumbs (&optional arg)
   "Toggle thumbnails in front of file names in the dired buffer.
@@ -1145,20 +1160,15 @@ FILE-TAGS is an alist in the following form:
         (cons x tag))
       files))))
 
-(defun image-dired-tag-marked-thumbnails ()
-  "Tag marked thumbnails."
-  (interactive)
-  (when-let ((dired-buf (image-dired-associated-dired-buffer)))
-    (with-current-buffer dired-buf
-      (image-dired-tag-files nil))))
-
-(defun image-dired-tag-thumbnail ()
-  "Tag current thumbnail."
+(defun image-dired-tag-thumbnails ()
+  "Tag current or marked thumbnails."
   (interactive)
   (let ((tag (read-string "Tags to add (separate tags with a semicolon): ")))
-    (image-dired-write-tags (list (cons (image-dired-original-file-name) tag))))
-  (image-dired-update-property
-   'tags (image-dired-list-tags (image-dired-original-file-name))))
+    (image-dired--with-marked
+     (image-dired-write-tags
+      (list (cons (image-dired-original-file-name) tag)))
+     (image-dired-update-property
+      'tags (image-dired-list-tags (image-dired-original-file-name))))))
 
 ;;;###autoload
 (defun image-dired-delete-tag (arg)
@@ -1172,13 +1182,14 @@ With prefix argument ARG, remove tag from file at point."
       (setq files (dired-get-marked-files)))
     (image-dired-remove-tag files tag)))
 
-(defun image-dired-tag-thumbnail-remove ()
-  "Remove tag from thumbnail."
+(defun image-dired-tag-thumbnails-remove ()
+  "Remove tag from current or marked thumbnails."
   (interactive)
   (let ((tag (read-string "Tag to remove: ")))
-    (image-dired-remove-tag (image-dired-original-file-name) tag))
-  (image-dired-update-property
-   'tags (image-dired-list-tags (image-dired-original-file-name))))
+    (image-dired--with-marked
+     (image-dired-remove-tag (image-dired-original-file-name) tag)
+     (image-dired-update-property
+      'tags (image-dired-list-tags (image-dired-original-file-name))))))
 
 (defun image-dired-original-file-name ()
   "Get original file name for thumbnail or display image at point."
@@ -1458,9 +1469,9 @@ You probably want to use this together with
 (defvar image-dired-thumbnail-mode-tag-map
   (let ((map (make-sparse-keymap)))
     ;; map it to "t" so that the user can press it more quickly
-    (define-key map "t" 'image-dired-tag-thumbnail)
+    (define-key map "t" 'image-dired-tag-thumbnails)
     ;; "r" for "remove"
-    (define-key map "r" 'image-dired-tag-thumbnail-remove)
+    (define-key map "r" 'image-dired-tag-thumbnails-remove)
     map)
   "Keymap for tag commands in `image-dired-thumbnail-mode'.")
 
@@ -1518,8 +1529,10 @@ You probably want to use this together with
       '("Image-Dired"
         ["Quit" quit-window]
         ["Delete thumbnail from buffer" image-dired-delete-char]
-        ["Remove tag from thumbnail" image-dired-tag-thumbnail-remove]
-        ["Tag thumbnail" image-dired-tag-thumbnail]
+        ["Delete marked images" image-dired-delete-marked]
+        ["Remove tag from current or marked thumbnails"
+         image-dired-tag-thumbnails-remove]
+        ["Tag current or marked thumbnails" image-dired-tag-thumbnails]
         ["Comment thumbnail" image-dired-comment-thumbnail]
         ["Refresh thumb" image-dired-refresh-thumb]
         ["Dynamic line up" image-dired-line-up-dynamic]
@@ -2301,15 +2314,12 @@ non-nil."
 (defun image-dired-delete-marked ()
   "Delete marked thumbnails and associated images."
   (interactive)
-  (goto-char (point-min))
-  (let ((dired-buf (image-dired-associated-dired-buffer)))
-    (while (not (eobp))
-      (if (image-dired-thumb-file-marked-p)
-          (image-dired-delete-char)
-        (forward-char)))
-    (image-dired--line-up-with-method)
-    (with-current-buffer dired-buf
-      (dired-do-delete))))
+  (image-dired--with-marked
+   (image-dired-delete-char)
+   (backward-char))
+  (image-dired--line-up-with-method)
+  (with-current-buffer (image-dired-associated-dired-buffer)
+    (dired-do-delete)))
 
 (defun image-dired-thumb-update-marks ()
   "Update the marks in the thumbnail buffer."
-- 
2.26.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 211 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-13 13:04       ` Peter Münster
@ 2021-08-14 11:51         ` Lars Ingebrigtsen
  2021-08-16  7:38           ` Peter Münster
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-14 11:51 UTC (permalink / raw)
  To: Peter Münster; +Cc: 50000

Peter Münster <pm@a16n.net> writes:

> Perhaps at least menu bindings. A patch is attached (with also some
> refactoring).

Looks mostly good, but:

> (image-dired-tag-thumbnail, image-dired-tag-thumbnail-remove): Rename to
> plural forms, because they can handle now also all marked thumbnails.

We can't rename functions in this way -- people may be referring to the
old names, and that could would then break.  You could add obsolete
aliases, but it's generally not worth it.  Can you respin the patch
without the function renames?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-14 11:51         ` Lars Ingebrigtsen
@ 2021-08-16  7:38           ` Peter Münster
  2021-08-16 12:07             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Münster @ 2021-08-16  7:38 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50000

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

On Sat, Aug 14 2021, Lars Ingebrigtsen wrote:

> You could add obsolete aliases, but it's generally not worth it. Can
> you respin the patch without the function renames?

I can do both, whatever you prefer.
Personally I prefer the former, because the new names make sense to me.

-- 
           Peter

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 211 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-16  7:38           ` Peter Münster
@ 2021-08-16 12:07             ` Lars Ingebrigtsen
  2021-08-16 15:33               ` Peter Münster
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-16 12:07 UTC (permalink / raw)
  To: Peter Münster; +Cc: 50000

Peter Münster <pm@a16n.net> writes:

>> You could add obsolete aliases, but it's generally not worth it. Can
>> you respin the patch without the function renames?
>
> I can do both, whatever you prefer.
> Personally I prefer the former, because the new names make sense to me.

I don't think the renames bring a lot of value here, so I'd rather avoid
them.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-16 12:07             ` Lars Ingebrigtsen
@ 2021-08-16 15:33               ` Peter Münster
  2021-08-18 12:54                 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Münster @ 2021-08-16 15:33 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50000


[-- Attachment #1.1: Type: text/plain, Size: 200 bytes --]

On Mon, Aug 16 2021, Lars Ingebrigtsen wrote:

> I don't think the renames bring a lot of value here, so I'd rather avoid
> them.

Ok. Please find attached a new patch.

-- 
           Peter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Add-menu-bindings-to-new-functions-in-image-dired.el.patch --]
[-- Type: text/x-patch, Size: 5771 bytes --]

From 2bee2a5a92a4d3593a60ded577731966c09c68cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Fri, 13 Aug 2021 15:02:03 +0200
Subject: [PATCH] Add menu bindings to new functions in image-dired.el

* lisp/image-dired.el (image-dired--with-marked): New macro for
cycling over marked thumbnails.
(image-dired-tag-thumbnail, image-dired-tag-thumbnail-remove): Can handle
now also all marked thumbnails.
(image-dired-tag-marked-thumbnails): Remove it, because it's obsoleted by
`image-dired-tag-thumbnail' now.
(image-dired-delete-marked): Use new macro `image-dired--with-marked', and
add command to menu.
---
 etc/NEWS            |  7 +++--
 lisp/image-dired.el | 70 ++++++++++++++++++++++++++-------------------
 2 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 26ede71523..6aa574eda3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2415,10 +2415,8 @@ This command, called interactively, toggles the local value of
 If non-nil (the default), use 'image-dired-thumb-mark' to say what
 images are marked.
 
-*** New command 'image-dired-tag-marked-thumbnails'.
-
 *** New command 'image-dired-delete-marked'.
 
 ** Miscellaneous
 
 ---
diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 7092f758db..520d8cdb34 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -797,6 +797,21 @@ Queued items live in `image-dired-queue'."
                (list (list original-file thumbnail-file))))
   (run-at-time 0 nil #'image-dired-thumb-queue-run))
 
+(defmacro image-dired--with-marked (&rest body)
+  "Eval BODY with point on each marked thumbnail. If no marked file could
+be found, execute BODY on the current thumbnail."
+  `(with-current-buffer image-dired-thumbnail-buffer
+     (let (found)
+       (save-mark-and-excursion
+         (goto-char (point-min))
+         (while (not (eobp))
+           (when (image-dired-thumb-file-marked-p)
+             (setq found t)
+             ,@body)
+           (forward-char)))
+       (unless found
+         ,@body))))
+
 ;;;###autoload
 (defun image-dired-dired-toggle-marked-thumbs (&optional arg)
   "Toggle thumbnails in front of file names in the dired buffer.
@@ -1145,20 +1160,15 @@ FILE-TAGS is an alist in the following form:
         (cons x tag))
       files))))
 
-(defun image-dired-tag-marked-thumbnails ()
-  "Tag marked thumbnails."
-  (interactive)
-  (when-let ((dired-buf (image-dired-associated-dired-buffer)))
-    (with-current-buffer dired-buf
-      (image-dired-tag-files nil))))
-
-(defun image-dired-tag-thumbnail ()
-  "Tag current thumbnail."
+(defun image-dired-tag-thumbnail ()
+  "Tag current or marked thumbnails."
   (interactive)
   (let ((tag (read-string "Tags to add (separate tags with a semicolon): ")))
-    (image-dired-write-tags (list (cons (image-dired-original-file-name) tag))))
-  (image-dired-update-property
-   'tags (image-dired-list-tags (image-dired-original-file-name))))
+    (image-dired--with-marked
+     (image-dired-write-tags
+      (list (cons (image-dired-original-file-name) tag)))
+     (image-dired-update-property
+      'tags (image-dired-list-tags (image-dired-original-file-name))))))
 
 ;;;###autoload
 (defun image-dired-delete-tag (arg)
@@ -1172,13 +1182,14 @@ With prefix argument ARG, remove tag from file at point."
       (setq files (dired-get-marked-files)))
     (image-dired-remove-tag files tag)))
 
-(defun image-dired-tag-thumbnail-remove ()
-  "Remove tag from thumbnail."
+(defun image-dired-tag-thumbnail-remove ()
+  "Remove tag from current or marked thumbnails."
   (interactive)
   (let ((tag (read-string "Tag to remove: ")))
-    (image-dired-remove-tag (image-dired-original-file-name) tag))
-  (image-dired-update-property
-   'tags (image-dired-list-tags (image-dired-original-file-name))))
+    (image-dired--with-marked
+     (image-dired-remove-tag (image-dired-original-file-name) tag)
+     (image-dired-update-property
+      'tags (image-dired-list-tags (image-dired-original-file-name))))))
 
 (defun image-dired-original-file-name ()
   "Get original file name for thumbnail or display image at point."
@@ -1518,8 +1529,10 @@ You probably want to use this together with
       '("Image-Dired"
         ["Quit" quit-window]
         ["Delete thumbnail from buffer" image-dired-delete-char]
-        ["Remove tag from thumbnail" image-dired-tag-thumbnail-remove]
-        ["Tag thumbnail" image-dired-tag-thumbnail]
+        ["Delete marked images" image-dired-delete-marked]
+        ["Remove tag from current or marked thumbnails"
+         image-dired-tag-thumbnail-remove]
+        ["Tag current or marked thumbnails" image-dired-tag-thumbnail]
         ["Comment thumbnail" image-dired-comment-thumbnail]
         ["Refresh thumb" image-dired-refresh-thumb]
         ["Dynamic line up" image-dired-line-up-dynamic]
@@ -2301,15 +2314,12 @@ non-nil."
 (defun image-dired-delete-marked ()
   "Delete marked thumbnails and associated images."
   (interactive)
-  (goto-char (point-min))
-  (let ((dired-buf (image-dired-associated-dired-buffer)))
-    (while (not (eobp))
-      (if (image-dired-thumb-file-marked-p)
-          (image-dired-delete-char)
-        (forward-char)))
-    (image-dired--line-up-with-method)
-    (with-current-buffer dired-buf
-      (dired-do-delete))))
+  (image-dired--with-marked
+   (image-dired-delete-char)
+   (backward-char))
+  (image-dired--line-up-with-method)
+  (with-current-buffer (image-dired-associated-dired-buffer)
+    (dired-do-delete)))
 
 (defun image-dired-thumb-update-marks ()
   "Update the marks in the thumbnail buffer."
-- 
2.26.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 211 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-16 15:33               ` Peter Münster
@ 2021-08-18 12:54                 ` Lars Ingebrigtsen
  2021-08-18 15:01                   ` Peter Münster
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-18 12:54 UTC (permalink / raw)
  To: Peter Münster; +Cc: 50000

Peter Münster <pm@a16n.net> writes:

> Ok. Please find attached a new patch.

Thanks; applied with one minor change:

> +(defmacro image-dired--with-marked (&rest body)
> +  "Eval BODY with point on each marked thumbnail. If no marked file could
> +be found, execute BODY on the current thumbnail."

The first line of a doc string should be a complete sentence, so I added
a newline after the full stop.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-18 12:54                 ` Lars Ingebrigtsen
@ 2021-08-18 15:01                   ` Peter Münster
  2021-08-19 13:03                     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Münster @ 2021-08-18 15:01 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50000


[-- Attachment #1.1: Type: text/plain, Size: 219 bytes --]

On Wed, Aug 18 2021, Lars Ingebrigtsen wrote:

> Thanks; applied with one minor change:

Thanks. Please find attached some further patches for image-dired.el.
I hope that they are useful.

-- 
           Peter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0003-Fix-deletion-of-associated-image.patch --]
[-- Type: text/x-patch, Size: 1340 bytes --]

From 7cfc8ad4effd5820d1bdef2027148df8219b8408 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Tue, 17 Aug 2021 00:19:08 +0200
Subject: [PATCH 3/6] Fix deletion of associated image

* lisp/image-dired.el (image-dired-delete-marked): Treat original images
first, because point position is used when there are no marked files.
---
 lisp/image-dired.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 1d8e27d39e..5ae6b21766 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -2312,14 +2312,14 @@ image-dired-thumb-file-marked-p
           (image-dired-dired-file-marked-p))))))
 
 (defun image-dired-delete-marked ()
-  "Delete marked thumbnails and associated images."
+  "Delete current or marked thumbnails and associated images."
   (interactive)
+  (with-current-buffer (image-dired-associated-dired-buffer)
+    (dired-do-delete))
   (image-dired--with-marked
    (image-dired-delete-char)
    (backward-char))
-  (image-dired--line-up-with-method)
-  (with-current-buffer (image-dired-associated-dired-buffer)
-    (dired-do-delete)))
+  (image-dired--line-up-with-method))
 
 (defun image-dired-thumb-update-marks ()
   "Update the marks in the thumbnail buffer."
-- 
2.26.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.3: 0004-New-placement-of-newline-characters-in-image-dired-d.patch --]
[-- Type: text/x-patch, Size: 1977 bytes --]

From ba6e4282f69c13dc57d00fdd7ff63f9565b8afe9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Wed, 18 Aug 2021 01:37:43 +0200
Subject: [PATCH 4/6] New placement of newline characters in
 image-dired-db-file

It's more usual to have the newline at the end of the line, instead of the
beginning. This change avoids missing newline at the end of the file, an
empty line at the start and eventually a lot of empty lines when
`require-final-newline' is not nil.

* lisp/image-dired.el (image-dired-write-tags): Insert newline at the end
of the line, instead of the beginning.
(image-dired-remove-tag): Do not delete empty line at end of buffer.
---
 lisp/image-dired.el | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 5ae6b21766..428b20d6eb 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -1095,7 +1095,7 @@ image-dired-write-tags
 	       (end-of-line)
 	       (insert (format ";%s" tag))))
 	 (goto-char (point-max))
-	 (insert (format "\n%s;%s" file tag))))
+	 (insert (format "%s;%s\n" file tag))))
      (save-buffer))))
 
 (defun image-dired-remove-tag (files tag)
@@ -1122,11 +1122,7 @@ image-dired-remove-tag
 	   (setq end (point))
 	   (beginning-of-line)
 	   (when (not (search-forward ";" end t))
-	     (kill-line 1)
-	     ;; If on empty line at end of buffer
-	     (and (eobp)
-		  (looking-at "^$")
-		  (delete-char -1)))))))
+	     (kill-line 1))))))
    (save-buffer)))
 
 (defun image-dired-list-tags (file)
@@ -2184,7 +2180,7 @@ image-dired-write-comments
 	     (insert (format "comment:%s;" comment)))
 	 ;; File does not exist in database - add it.
 	 (goto-char (point-max))
-	 (insert (format "\n%s;comment:%s" file comment))))
+	 (insert (format "%s;comment:%s\n" file comment))))
      (save-buffer))))
 
 (defun image-dired-update-property (prop value)
-- 
2.26.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.4: 0005-Avoid-problems-when-one-tag-file-is-a-substring-of-a.patch --]
[-- Type: text/x-patch, Size: 1327 bytes --]

From 2163c4c3894272d2022e5fb78d2c0be1310d9da9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Wed, 18 Aug 2021 02:02:02 +0200
Subject: [PATCH 5/6] Avoid problems when one tag/file is a substring of
 another

* lisp/image-dired.el (image-dired-remove-tag): End of filename is bound
by ";" and end of tag is bound by ";" or end of line.
---
 lisp/image-dired.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 428b20d6eb..5ee66b0e90 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -1110,11 +1110,12 @@ image-dired-remove-tag
 	 (error "Files must be a string or a list of strings!")))
      (dolist (file files)
        (goto-char (point-min))
-       (when (search-forward-regexp (format "^%s" file) nil t)
+       (when (search-forward-regexp (format "^%s;" file) nil t)
 	 (end-of-line)
 	 (setq end (point))
 	 (beginning-of-line)
-	 (when (search-forward-regexp (format "\\(;%s\\)" tag) end t)
+	 (when (search-forward-regexp
+                (format "\\(;%s\\)\\($\\|;\\)" tag) end t)
 	   (delete-region (match-beginning 1) (match-end 1))
 	   ;; Check if file should still be in the database. If
 	   ;; it has no tags or comments, it will be removed.
-- 
2.26.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.5: 0006-Add-support-for-history-of-image-tags-and-completion.patch --]
[-- Type: text/x-patch, Size: 3078 bytes --]

From 364beec6d1470712415a36f5810e4f7d320c6b0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Wed, 18 Aug 2021 11:21:51 +0200
Subject: [PATCH 6/6] Add support for history of image tags and completion in
 the minibuffer

* lisp/image-dired.el (image-dired-tag-history): New variable holding the
tag history.
(image-dired-tag-files, image-dired-tag-thumbnail, image-dired-delete-tag)
(image-dired-tag-thumbnail-remove): Use it for the user input.
---
 lisp/image-dired.el | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 5ee66b0e90..5a332964d5 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -652,6 +652,8 @@ image-dired-queue-active-limit
   "Maximum number of concurrent jobs permitted for generating images.
 Increase at own risk.")
 
+(defvar image-dired-tag-history nil "Variable holding the tag history.")
+
 (defun image-dired-pngnq-thumb (spec)
   "Quantize thumbnail described by format SPEC with pngnq(1)."
   (let ((process
@@ -1146,7 +1148,9 @@ image-dired-list-tags
 (defun image-dired-tag-files (arg)
   "Tag marked file(s) in dired.  With prefix ARG, tag file at point."
   (interactive "P")
-  (let ((tag (read-string "Tags to add (separate tags with a semicolon): "))
+  (let ((tag (completing-read
+              "Tags to add (separate tags with a semicolon): "
+              image-dired-tag-history nil nil nil 'image-dired-tag-history))
         files)
     (if arg
         (setq files (list (dired-get-filename)))
@@ -1160,7 +1164,9 @@ image-dired-tag-files
 (defun image-dired-tag-thumbnail ()
   "Tag current or marked thumbnails."
   (interactive)
-  (let ((tag (read-string "Tags to add (separate tags with a semicolon): ")))
+  (let ((tag (completing-read
+              "Tags to add (separate tags with a semicolon): "
+              image-dired-tag-history nil nil nil 'image-dired-tag-history)))
     (image-dired--with-marked
      (image-dired-write-tags
       (list (cons (image-dired-original-file-name) tag)))
@@ -1172,7 +1178,8 @@ image-dired-delete-tag
   "Remove tag for selected file(s).
 With prefix argument ARG, remove tag from file at point."
   (interactive "P")
-  (let ((tag (read-string "Tag to remove: "))
+  (let ((tag (completing-read "Tag to remove: " image-dired-tag-history
+                              nil nil nil 'image-dired-tag-history))
         files)
     (if arg
         (setq files (list (dired-get-filename)))
@@ -1182,7 +1189,8 @@ image-dired-delete-tag
 (defun image-dired-tag-thumbnail-remove ()
   "Remove tag from current or marked thumbnails."
   (interactive)
-  (let ((tag (read-string "Tag to remove: ")))
+  (let ((tag (completing-read "Tag to remove: " image-dired-tag-history
+                              nil nil nil 'image-dired-tag-history)))
     (image-dired--with-marked
      (image-dired-remove-tag (image-dired-original-file-name) tag)
      (image-dired-update-property
-- 
2.26.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 211 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-18 15:01                   ` Peter Münster
@ 2021-08-19 13:03                     ` Lars Ingebrigtsen
  2021-08-20  7:13                       ` Peter Münster
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-19 13:03 UTC (permalink / raw)
  To: Peter Münster; +Cc: 50000

Peter Münster <pm@a16n.net> writes:

> Thanks. Please find attached some further patches for image-dired.el.
> I hope that they are useful.

Looks good to me; applied to Emacs 28.

> Subject: [PATCH 3/6] Fix deletion of associated image

The first one was 3/6?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#50000: 27.2; tagging marked thumbnails
  2021-08-19 13:03                     ` Lars Ingebrigtsen
@ 2021-08-20  7:13                       ` Peter Münster
  0 siblings, 0 replies; 13+ messages in thread
From: Peter Münster @ 2021-08-20  7:13 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50000

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

On Thu, Aug 19 2021, Lars Ingebrigtsen wrote:

> The first one was 3/6?

Patch 1 was "Add menu bindings...", that you've already applied. And
patch 2 was "Revert name changes" for keeping the old function names.

-- 
           Peter

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 211 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-08-20  7:13 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11 10:01 bug#50000: 27.2; tagging marked thumbnails Peter Münster
2021-08-11 12:21 ` Lars Ingebrigtsen
2021-08-11 14:31   ` Peter Münster
2021-08-11 16:02     ` Lars Ingebrigtsen
2021-08-13 13:04       ` Peter Münster
2021-08-14 11:51         ` Lars Ingebrigtsen
2021-08-16  7:38           ` Peter Münster
2021-08-16 12:07             ` Lars Ingebrigtsen
2021-08-16 15:33               ` Peter Münster
2021-08-18 12:54                 ` Lars Ingebrigtsen
2021-08-18 15:01                   ` Peter Münster
2021-08-19 13:03                     ` Lars Ingebrigtsen
2021-08-20  7:13                       ` Peter Münster

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).