From 63f07ea22f3954c2154d831017caf494911cb515 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Thu, 9 Dec 2021 00:57:34 +0100 Subject: [PATCH] image-dired: Go to next image when marking * 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 | 6 +++++ lisp/image-dired.el | 56 ++++++++++++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index b9134d850ee..9eee04b3399 100644 --- 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 diff --git a/lisp/image-dired.el b/lisp/image-dired.el index e1c794472b7..c5cc586f252 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el @@ -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-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") + ;;; 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 () -- 2.39.2