From: Stefan Kangas Date: Fri, 12 Nov 2021 03:10:40 +0000 (+0100) Subject: image-dired: Revamp slideshow functionality X-Git-Tag: emacs-29.0.90~3668^2~27 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1d95cef0feeb8276abda379d978aa4d40c4cddde;p=emacs.git image-dired: Revamp slideshow functionality * lisp/image-dired.el (image-dired-slideshow-delay): New defcustom. (image-dired--slideshow-initial): New defvar. (image-dired-slideshow-start): Don't show any prompts when starting a slideshow, unless user gave a negative prefix argument. Use the value of the above new defcustom as the default delay. (image-dired-slideshow-stop): Don't count number of images. Instead, continue the slideshow until the next command. (image-dired-slideshow-step): Use the correct buffer. (image-dired-slideshow-count, image-dired-slideshow-times): Make obsolete. (image-dired--slideshow-timer): Rename from 'image-dired-slideshow-timer'. Make the old name into an obsolete variable alias. (image-dired-display-image-mode-map) (image-dired-thumbnail-mode-map): Bind 'image-dired-slideshow-start' to "S". (image-dired-thumbnail-mode-menu): Add 'image-dired-slideshow-start'. --- diff --git a/etc/NEWS b/etc/NEWS index 4ec7743611e..5439964891e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -425,6 +425,15 @@ If 'image-dired-thumb-mark' is non-nil (the default), this face is used for images that are flagged for deletion in the Dired buffer associated with Image-Dired. +--- +*** The 'image-dired-slideshow-start' command has been revamped. +It no longer inconveniently prompts for a number of images and a +delay: it runs indefinitely, but stops automatically on any command. +You can set the delay with a prefix argument, or a negative prefix +argument to prompt anyways. Customize the user option +'image-dired-slideshow-delay' to change the default, which is 5 +seconds. It is bound to 'S' in the thumbnail and display buffer. + --- *** Support for bookmark.el. The command 'bookmark-set' (bound to 'C-x r m') is now supported in diff --git a/lisp/image-dired.el b/lisp/image-dired.el index 4015f42c6b8..8e5a6d898c0 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el @@ -1580,6 +1580,7 @@ You probably want to use this together with (define-key map "R" 'image-dired-rotate-original-right) (define-key map "D" 'image-dired-thumbnail-set-image-description) + (define-key map "S" #'image-dired-slideshow-start) (define-key map "\C-d" 'image-dired-delete-char) (define-key map " " 'image-dired-display-next-thumbnail-original) (define-key map (kbd "DEL") 'image-dired-display-previous-thumbnail-original) @@ -1627,6 +1628,7 @@ You probably want to use this together with ["Tag current or marked thumbnails" image-dired-tag-thumbnail] ["Remove tag from current or marked thumbnails" image-dired-tag-thumbnail-remove] + ["Start slideshow" image-dired-slideshow-start] "---" ("View Options" ["Toggle movement tracking" image-dired-toggle-movement-tracking @@ -1640,6 +1642,7 @@ You probably want to use this together with (defvar image-dired-display-image-mode-map (let ((map (make-sparse-keymap))) + (define-key map "S" #'image-dired-slideshow-start) ;; Disable keybindings from `image-mode-map' that doesn't make sense here. (define-key map "o" nil) ; image-save (define-key map "n" nil) ; image-next-file @@ -1755,44 +1758,60 @@ With prefix argument ARG, create thumbnails even if they already exist (image-dired-create-thumb curr-file thumb-name))))) -;;; Slideshow. +;;; Slideshow -(defvar image-dired-slideshow-timer nil - "Slideshow timer.") +(defcustom image-dired-slideshow-delay 5.0 + "Seconds to wait before showing the next image in a slideshow. +This is used by `image-dired-slideshow-start'." + :type 'float + :version "29.1") -(defvar image-dired-slideshow-count 0 - "Keeping track on number of images in slideshow.") +(define-obsolete-variable-alias 'image-dired-slideshow-timer + 'image-dired--slideshow-timer "29.1") +(defvar image-dired--slideshow-timer nil + "Slideshow timer.") -(defvar image-dired-slideshow-times 0 - "Number of pictures to display in slideshow.") +(defvar image-dired--slideshow-initial nil) (defun image-dired-slideshow-step () - "Step to next file, if `image-dired-slideshow-times' has not been reached." - (if (< image-dired-slideshow-count image-dired-slideshow-times) - (progn - (message "%s" (1+ image-dired-slideshow-count)) - (setq image-dired-slideshow-count (1+ image-dired-slideshow-count)) - (image-dired-next-line-and-display)) + "Step to next image in a slideshow." + (if-let ((buf (get-buffer image-dired-thumbnail-buffer))) + (with-current-buffer buf + (image-dired-display-next-thumbnail-original)) (image-dired-slideshow-stop))) -(defun image-dired-slideshow-start () - "Start slideshow. -Ask user for number of images to show and the delay in between." - (interactive) - (setq image-dired-slideshow-count 0) - (setq image-dired-slideshow-times (string-to-number (read-string "How many: "))) - (let ((repeat (string-to-number - (read-string - "Delay, in seconds. Decimals are accepted : " "1")))) - (setq image-dired-slideshow-timer +(defun image-dired-slideshow-start (&optional arg) + "Start a slideshow. +Wait `image-dired-slideshow-delay' seconds before showing the +next image. + +With prefix argument ARG, wait that many seconds before going to +the next image. + +With a negative prefix argument, prompt user for the delay." + (interactive "P" image-dired-thumbnail-mode image-dired-display-image-mode) + (let ((delay (if (> arg 0) + arg + (string-to-number + (read-string + (let ((delay (number-to-string image-dired-slideshow-delay))) + (format-prompt "Delay, in seconds. Decimals are accepted" delay) delay)))))) + (setq image-dired--slideshow-timer (run-with-timer - 0 repeat - 'image-dired-slideshow-step)))) + 0 delay + 'image-dired-slideshow-step)) + (add-hook 'post-command-hook 'image-dired-slideshow-stop) + (setq image-dired--slideshow-initial t) + (message "Running slideshow; use any command to stop"))) (defun image-dired-slideshow-stop () "Cancel slideshow." - (interactive) - (cancel-timer image-dired-slideshow-timer)) + ;; Make sure we don't immediately stop after + ;; `image-dired-slideshow-start'. + (unless image-dired--slideshow-initial + (remove-hook 'post-command-hook 'image-dired-slideshow-stop) + (cancel-timer image-dired--slideshow-timer)) + (setq image-dired--slideshow-initial nil)) ;;; Thumbnail mode (cont. 3) @@ -2975,6 +2994,14 @@ Dired." (cons (list tag file) (cdr image-dired-tag-file-list)))) (setq image-dired-tag-file-list (list (list tag file)))))) +(defvar image-dired-slideshow-count 0 + "Keeping track on number of images in slideshow.") +(make-obsolete-variable 'image-dired-slideshow-count "no longer used." "29.1") + +(defvar image-dired-slideshow-times 0 + "Number of pictures to display in slideshow.") +(make-obsolete-variable 'image-dired-slideshow-times "no longer used." "29.1") + (define-obsolete-function-alias 'image-dired-create-display-image-buffer #'ignore "29.1") (define-obsolete-function-alias 'image-dired-create-gallery-lists