[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 759d1145e2 2/2: image-dired: Rewrite and extend slideshow feature
From: |
Stefan Kangas |
Subject: |
master 759d1145e2 2/2: image-dired: Rewrite and extend slideshow feature |
Date: |
Fri, 23 Sep 2022 17:14:51 -0400 (EDT) |
branch: master
commit 759d1145e2cb04fde83cf721d3d1fd0644e9c8f1
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>
image-dired: Rewrite and extend slideshow feature
* lisp/image/image-dired.el
(image-dired--slideshow-start-timer)
(image-dired--slideshow-stop-timer)
(image-dired--slideshow-show-message): New functions.
(image-dired--slideshow-current-delay): New variable.
(image-dired--slideshow-initial): Delete variable.
(image-dired-slideshow-start): Simplify and ensure we display the
image at start.
* lisp/image/image-dired.el (image-dired--slideshow-stop): Add support
for pausing, and going backwards and forwards during slideshow.
---
etc/NEWS | 4 ++-
lisp/image/image-dired.el | 84 ++++++++++++++++++++++++++++++++---------------
2 files changed, 61 insertions(+), 27 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 63c4ec79d2..34025ff83d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2083,7 +2083,9 @@ thumbnail buffer. It is bound to 'W' by default.
---
*** 'image-dired-slideshow-start' is now bound to 'S'.
-It is bound in both the thumbnail and display buffer.
+It is bound in both the thumbnail and display buffer, and no longer
+prompts for a timeout; use a numerical prefix (e.g. 'C-u 8 S') to set
+the timeout.
---
*** New user option 'image-dired-marking-shows-next'.
diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el
index 41decbd341..43faccad1e 100644
--- a/lisp/image/image-dired.el
+++ b/lisp/image/image-dired.el
@@ -972,48 +972,80 @@ This is used by `image-dired-slideshow-start'."
(defvar image-dired--slideshow-timer nil
"Slideshow timer.")
-(defvar image-dired--slideshow-initial nil)
+(defvar image-dired--slideshow-current-delay image-dired-slideshow-delay)
(defun image-dired--slideshow-step ()
- "Step to next image in a slideshow."
+ "Step to the 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-timer ()
+ (image-dired--slideshow-stop-timer)
+ (setq image-dired--slideshow-timer
+ (run-with-timer image-dired--slideshow-current-delay
+ image-dired--slideshow-current-delay
+ 'image-dired--slideshow-step)))
+
+(defun image-dired--slideshow-stop-timer ()
+ (when image-dired--slideshow-timer
+ (cancel-timer image-dired--slideshow-timer)
+ (setq image-dired--slideshow-timer nil)))
+
(defun image-dired-slideshow-start (&optional arg)
- "Start a slideshow, waiting `image-dired-slideshow-delay' between images.
+ "Start a slideshow, waiting `image-dired-slideshow-delay' seconds between
images.
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 (not arg)
- image-dired-slideshow-delay
- (if (> arg 0)
- arg
- (string-to-number
- (let ((delay (number-to-string
image-dired-slideshow-delay)))
- (read-string
- (format-prompt "Delay, in seconds. Decimals are
accepted" delay))
- delay))))))
- (setq image-dired--slideshow-timer
- (run-with-timer
- 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")))
+ (let ((delay
+ (cond ((not arg)
+ image-dired-slideshow-delay)
+ ((> arg 0)
+ arg)
+ ((<= arg 0)
+ (string-to-number
+ (let ((delay (number-to-string image-dired-slideshow-delay)))
+ (read-string
+ (format-prompt "Delay, in seconds. Decimals are accepted"
+ delay))
+ delay))))))
+ (image-dired-display-thumbnail-original-image)
+ (setq image-dired--slideshow-current-delay delay)
+ (add-hook 'post-command-hook 'image-dired--slideshow-stop)))
+
+(defun image-dired--slideshow-show-message (&optional suffix)
+ "Helper function for `image-dired--slideshow-stop'."
+ (message (substitute-command-keys
+ (format
+ (concat
+ "\\[image-dired-display-next-thumbnail-original] next, "
+ "\\[image-dired-display-previous-thumbnail-original] previous, "
+ "\\[image-dired-display-thumbnail-original-image] pause/unpause,
"
+ "any other command to stop%s")
+ (or suffix "")))))
(defun image-dired--slideshow-stop ()
- "Cancel slideshow."
- ;; 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))
+ "Cancel the currently active slideshow."
+ (cond
+ ((memq this-command
+ '( image-dired-slideshow-start
+ image-dired-display-next-thumbnail-original
+ image-dired-display-previous-thumbnail-original))
+ (image-dired--slideshow-start-timer)
+ (image-dired--slideshow-show-message))
+ ((eq this-command 'image-dired-display-thumbnail-original-image)
+ (let ((pause image-dired--slideshow-timer))
+ (if pause
+ (image-dired--slideshow-stop-timer)
+ (image-dired--slideshow-start-timer))
+ (image-dired--slideshow-show-message (and pause " [PAUSED]"))))
+ (t
+ (image-dired--slideshow-stop-timer)
+ (remove-hook 'post-command-hook 'image-dired--slideshow-stop))))
;;; Thumbnail mode (cont. 3)