diff options
| author | Stefan Kangas | 2022-09-23 23:12:10 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2022-09-23 23:14:14 +0200 |
| commit | 759d1145e2cb04fde83cf721d3d1fd0644e9c8f1 (patch) | |
| tree | 97b133326aa10d2e3725b71741a1d33c4457dfa6 | |
| parent | e6f1ad6474d3352125b53a90bb259997ecd1fc5d (diff) | |
| download | emacs-759d1145e2cb04fde83cf721d3d1fd0644e9c8f1.tar.gz emacs-759d1145e2cb04fde83cf721d3d1fd0644e9c8f1.zip | |
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.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/image/image-dired.el | 84 |
2 files changed, 61 insertions, 27 deletions
| @@ -2083,7 +2083,9 @@ thumbnail buffer. It is bound to 'W' by default. | |||
| 2083 | 2083 | ||
| 2084 | --- | 2084 | --- |
| 2085 | *** 'image-dired-slideshow-start' is now bound to 'S'. | 2085 | *** 'image-dired-slideshow-start' is now bound to 'S'. |
| 2086 | It is bound in both the thumbnail and display buffer. | 2086 | It is bound in both the thumbnail and display buffer, and no longer |
| 2087 | prompts for a timeout; use a numerical prefix (e.g. 'C-u 8 S') to set | ||
| 2088 | the timeout. | ||
| 2087 | 2089 | ||
| 2088 | --- | 2090 | --- |
| 2089 | *** New user option 'image-dired-marking-shows-next'. | 2091 | *** New user option 'image-dired-marking-shows-next'. |
diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el index 41decbd3414..43faccad1ec 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'." | |||
| 972 | (defvar image-dired--slideshow-timer nil | 972 | (defvar image-dired--slideshow-timer nil |
| 973 | "Slideshow timer.") | 973 | "Slideshow timer.") |
| 974 | 974 | ||
| 975 | (defvar image-dired--slideshow-initial nil) | 975 | (defvar image-dired--slideshow-current-delay image-dired-slideshow-delay) |
| 976 | 976 | ||
| 977 | (defun image-dired--slideshow-step () | 977 | (defun image-dired--slideshow-step () |
| 978 | "Step to next image in a slideshow." | 978 | "Step to the next image in a slideshow." |
| 979 | (if-let ((buf (get-buffer image-dired-thumbnail-buffer))) | 979 | (if-let ((buf (get-buffer image-dired-thumbnail-buffer))) |
| 980 | (with-current-buffer buf | 980 | (with-current-buffer buf |
| 981 | (image-dired-display-next-thumbnail-original)) | 981 | (image-dired-display-next-thumbnail-original)) |
| 982 | (image-dired--slideshow-stop))) | 982 | (image-dired--slideshow-stop))) |
| 983 | 983 | ||
| 984 | (defun image-dired--slideshow-start-timer () | ||
| 985 | (image-dired--slideshow-stop-timer) | ||
| 986 | (setq image-dired--slideshow-timer | ||
| 987 | (run-with-timer image-dired--slideshow-current-delay | ||
| 988 | image-dired--slideshow-current-delay | ||
| 989 | 'image-dired--slideshow-step))) | ||
| 990 | |||
| 991 | (defun image-dired--slideshow-stop-timer () | ||
| 992 | (when image-dired--slideshow-timer | ||
| 993 | (cancel-timer image-dired--slideshow-timer) | ||
| 994 | (setq image-dired--slideshow-timer nil))) | ||
| 995 | |||
| 984 | (defun image-dired-slideshow-start (&optional arg) | 996 | (defun image-dired-slideshow-start (&optional arg) |
| 985 | "Start a slideshow, waiting `image-dired-slideshow-delay' between images. | 997 | "Start a slideshow, waiting `image-dired-slideshow-delay' seconds between images. |
| 986 | 998 | ||
| 987 | With prefix argument ARG, wait that many seconds before going to | 999 | With prefix argument ARG, wait that many seconds before going to |
| 988 | the next image. | 1000 | the next image. |
| 989 | 1001 | ||
| 990 | With a negative prefix argument, prompt user for the delay." | 1002 | With a negative prefix argument, prompt user for the delay." |
| 991 | (interactive "P" image-dired-thumbnail-mode image-dired-display-image-mode) | 1003 | (interactive "P" image-dired-thumbnail-mode image-dired-display-image-mode) |
| 992 | (let ((delay (if (not arg) | 1004 | (let ((delay |
| 993 | image-dired-slideshow-delay | 1005 | (cond ((not arg) |
| 994 | (if (> arg 0) | 1006 | image-dired-slideshow-delay) |
| 995 | arg | 1007 | ((> arg 0) |
| 996 | (string-to-number | 1008 | arg) |
| 997 | (let ((delay (number-to-string image-dired-slideshow-delay))) | 1009 | ((<= arg 0) |
| 998 | (read-string | 1010 | (string-to-number |
| 999 | (format-prompt "Delay, in seconds. Decimals are accepted" delay)) | 1011 | (let ((delay (number-to-string image-dired-slideshow-delay))) |
| 1000 | delay)))))) | 1012 | (read-string |
| 1001 | (setq image-dired--slideshow-timer | 1013 | (format-prompt "Delay, in seconds. Decimals are accepted" |
| 1002 | (run-with-timer | 1014 | delay)) |
| 1003 | 0 delay | 1015 | delay)))))) |
| 1004 | 'image-dired--slideshow-step)) | 1016 | (image-dired-display-thumbnail-original-image) |
| 1005 | (add-hook 'post-command-hook 'image-dired--slideshow-stop) | 1017 | (setq image-dired--slideshow-current-delay delay) |
| 1006 | (setq image-dired--slideshow-initial t) | 1018 | (add-hook 'post-command-hook 'image-dired--slideshow-stop))) |
| 1007 | (message "Running slideshow; use any command to stop"))) | 1019 | |
| 1020 | (defun image-dired--slideshow-show-message (&optional suffix) | ||
| 1021 | "Helper function for `image-dired--slideshow-stop'." | ||
| 1022 | (message (substitute-command-keys | ||
| 1023 | (format | ||
| 1024 | (concat | ||
| 1025 | "\\[image-dired-display-next-thumbnail-original] next, " | ||
| 1026 | "\\[image-dired-display-previous-thumbnail-original] previous, " | ||
| 1027 | "\\[image-dired-display-thumbnail-original-image] pause/unpause, " | ||
| 1028 | "any other command to stop%s") | ||
| 1029 | (or suffix ""))))) | ||
| 1008 | 1030 | ||
| 1009 | (defun image-dired--slideshow-stop () | 1031 | (defun image-dired--slideshow-stop () |
| 1010 | "Cancel slideshow." | 1032 | "Cancel the currently active slideshow." |
| 1011 | ;; Make sure we don't immediately stop after | 1033 | (cond |
| 1012 | ;; `image-dired-slideshow-start'. | 1034 | ((memq this-command |
| 1013 | (unless image-dired--slideshow-initial | 1035 | '( image-dired-slideshow-start |
| 1014 | (remove-hook 'post-command-hook 'image-dired--slideshow-stop) | 1036 | image-dired-display-next-thumbnail-original |
| 1015 | (cancel-timer image-dired--slideshow-timer)) | 1037 | image-dired-display-previous-thumbnail-original)) |
| 1016 | (setq image-dired--slideshow-initial nil)) | 1038 | (image-dired--slideshow-start-timer) |
| 1039 | (image-dired--slideshow-show-message)) | ||
| 1040 | ((eq this-command 'image-dired-display-thumbnail-original-image) | ||
| 1041 | (let ((pause image-dired--slideshow-timer)) | ||
| 1042 | (if pause | ||
| 1043 | (image-dired--slideshow-stop-timer) | ||
| 1044 | (image-dired--slideshow-start-timer)) | ||
| 1045 | (image-dired--slideshow-show-message (and pause " [PAUSED]")))) | ||
| 1046 | (t | ||
| 1047 | (image-dired--slideshow-stop-timer) | ||
| 1048 | (remove-hook 'post-command-hook 'image-dired--slideshow-stop)))) | ||
| 1017 | 1049 | ||
| 1018 | 1050 | ||
| 1019 | ;;; Thumbnail mode (cont. 3) | 1051 | ;;; Thumbnail mode (cont. 3) |