]> git.eshelyaron.com Git - emacs.git/commitdiff
image-dired: Go to next image when marking
authorStefan Kangas <stefan@marxist.se>
Wed, 8 Dec 2021 23:57:34 +0000 (00:57 +0100)
committerStefan Kangas <stefan@marxist.se>
Wed, 8 Dec 2021 23:57:34 +0000 (00:57 +0100)
* lisp/image-dired.el
(image-dired-marking-shows-next): New user option to show the next
image after marking, unmarking or flagging an image.
(image-dired--do-mark-command): New macro.
(image-dired-mark-thumb-original-file)
(image-dired-unmark-thumb-original-file)
(image-dired-flag-thumb-original-file)
(image-dired-toggle-mark-thumb-original-file)
(image-dired-unmark-all-marks): Use above new macro.

etc/NEWS
lisp/image-dired.el

index b9134d850ee74b95c335ecf69b1e1a90d5b6d7f7..9eee04b33998f690c95463df6c39ed5e4d49b036 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -610,6 +610,12 @@ The command 'bookmark-set' (bound to 'C-x r m') is now supported in
 the thumbnail view, and will create a bookmark that opens the current
 directory in Image-Dired.
 
+---
+*** New user option 'image-dired-marking-shows-next'.
+If this option is non-nil (the default), marking, unmarking or
+flagging an image in either the thumbnail or display buffer shows the
+next image.
+
 +++
 *** 'image-dired-show-all-from-dir-max-files' has been increased to 500.
 This option controls asking for confirmation when starting Image-Dired
index e1c794472b7ad3b889b1fad03c4ed2c36b57f42f..c5cc586f252a0ae41862878883cfc74e6772b95b 100644 (file)
@@ -490,6 +490,17 @@ variable is nil, it will never ask."
                  (const :tag "Disable warning" nil))
   :version "29.1")
 
+(defcustom image-dired-marking-shows-next t
+  "If non-nil, marking, unmarking or flagging an image shows the next image.
+
+This affects the following commands:
+\\<image-dired-thumbnail-mode-map>
+    `image-dired-flag-thumb-original-file'   (bound to \\[image-dired-flag-thumb-original-file])
+    `image-dired-mark-thumb-original-file'   (bound to \\[image-dired-mark-thumb-original-file])
+    `image-dired-unmark-thumb-original-file' (bound to \\[image-dired-unmark-thumb-original-file])"
+  :type 'boolean
+  :version "29.1")
+
 \f
 ;;; Util functions
 
@@ -1459,46 +1470,53 @@ Should be called from commands in `image-dired-thumbnail-mode'."
            ,@body
            (image-dired-thumb-update-marks))))))
 
+(defmacro image-dired--do-mark-command (maybe-next &rest body)
+  "Helper macro for the mark, unmark and flag commands.
+Run BODY in Dired buffer.
+If optional argument MAYBE-NEXT is non-nil, show next image
+according to `image-dired-marking-shows-next'."
+  (declare (indent defun) (debug t))
+  `(image-dired--with-thumbnail-buffer
+     (image-dired--on-file-in-dired-buffer
+       ,@body)
+     ,(when maybe-next
+        '(if image-dired-marking-shows-next
+             (image-dired-display-next-thumbnail-original)
+           (image-dired-next-line)))))
+
 (defun image-dired-mark-thumb-original-file ()
   "Mark original image file in associated Dired buffer."
   (interactive nil image-dired-thumbnail-mode image-dired-display-image-mode)
-  (image-dired--with-thumbnail-buffer
-    (image-dired--on-file-in-dired-buffer
-      (dired-mark 1))
-    (image-dired-forward-image)))
+  (image-dired--do-mark-command t
+    (dired-mark 1)))
 
 (defun image-dired-unmark-thumb-original-file ()
   "Unmark original image file in associated Dired buffer."
   (interactive nil image-dired-thumbnail-mode image-dired-display-image-mode)
-  (image-dired--with-thumbnail-buffer
-    (image-dired--on-file-in-dired-buffer
-      (dired-unmark 1))
-    (image-dired-forward-image)))
+  (image-dired--do-mark-command t
+    (dired-unmark 1)))
 
 (defun image-dired-flag-thumb-original-file ()
   "Flag original image file for deletion in associated Dired buffer."
   (interactive nil image-dired-thumbnail-mode image-dired-display-image-mode)
-  (image-dired--with-thumbnail-buffer
-    (image-dired--on-file-in-dired-buffer
-      (dired-flag-file-deletion 1))
-    (image-dired-forward-image)))
+  (image-dired--do-mark-command t
+    (dired-flag-file-deletion 1)))
 
 (defun image-dired-toggle-mark-thumb-original-file ()
   "Toggle mark on original image file in associated Dired buffer."
   (interactive nil image-dired-thumbnail-mode image-dired-display-image-mode)
-  (image-dired--with-thumbnail-buffer
-    (image-dired--on-file-in-dired-buffer
-      (if (image-dired-dired-file-marked-p)
-          (dired-unmark 1)
-        (dired-mark 1)))))
+  (image-dired--do-mark-command nil
+    (if (image-dired-dired-file-marked-p)
+        (dired-unmark 1)
+      (dired-mark 1))))
 
 (defun image-dired-unmark-all-marks ()
   "Remove all marks from all files in associated Dired buffer.
 Also update the marks in the thumbnail buffer."
   (interactive nil image-dired-thumbnail-mode image-dired-display-image-mode)
+  (image-dired--do-mark-command nil
+    (dired-unmark-all-marks))
   (image-dired--with-thumbnail-buffer
-    (with-current-buffer (image-dired-associated-dired-buffer)
-      (dired-unmark-all-marks))
     (image-dired-thumb-update-marks)))
 
 (defun image-dired-jump-original-dired-buffer ()