From fa4a63c689864a75b2439b9a5f858158fa1a7c7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20M=C3=BCnster?= Date: Wed, 18 Aug 2021 14:53:25 +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 (bug#50000). --- etc/NEWS | 3 +-- lisp/image-dired.el | 63 ++++++++++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 8b536541702..f77fc8243f7 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2447,8 +2447,7 @@ 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 7092f758dbd..1e1614af9b6 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el @@ -797,6 +797,22 @@ 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 +1161,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." + "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) @@ -1173,12 +1184,13 @@ With prefix argument ARG, remove tag from file at point." (image-dired-remove-tag files tag))) (defun image-dired-tag-thumbnail-remove () - "Remove tag from thumbnail." + "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 +1530,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 +2315,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.39.2