]> code.delx.au - gnu-emacs/commitdiff
Add commands for navigating multi-frame images
authorGlenn Morris <rgm@gnu.org>
Sat, 16 Feb 2013 03:29:39 +0000 (19:29 -0800)
committerGlenn Morris <rgm@gnu.org>
Sat, 16 Feb 2013 03:29:39 +0000 (19:29 -0800)
* lisp/image.el (image-nth-frame): New, split from image-animate-timeout.
(image-animate-timeout): Use image-nth-frame.

* lisp/image-mode.el (image-goto-frame, image-next-frame)
(image-previous-frame): New commands.
(image-mode-map): Add new frame commands.

* etc/NEWS: Mention this.

etc/NEWS
lisp/ChangeLog
lisp/image-mode.el
lisp/image.el

index 98824220cecfdb58e658afe8b29714f88ccd2000..62d84a0788d51ca97dd956498a0d9b3eb42e08a0 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -141,6 +141,10 @@ amounts of data into the ERC input.
 visit the next image file and the previous image file in the same
 directory, respectively.
 
+*** New commands to show specific frames of multi-frame images.
+`f' (`image-next-frame') and `b' (`image-previous-frame') visit the
+next or previous frame.  `F' (`image-goto-frame') shows a specific frame.
+
 ---
 *** The command `image-mode-fit-frame' deletes other windows.
 When toggling, it restores the frame's previous window configuration.
index d9e6a3eb5b417578c01ccd66c6cce4c7d1117148..e71e3d6752ea47175a9191a9d299f6b1459b7007 100644 (file)
@@ -1,3 +1,11 @@
+2013-02-16  Glenn Morris  <rgm@gnu.org>
+
+       * image.el (image-nth-frame): New, split from image-animate-timeout.
+       (image-animate-timeout): Use image-nth-frame.
+       * image-mode.el (image-goto-frame, image-next-frame)
+       (image-previous-frame): New commands.
+       (image-mode-map): Add new frame commands.
+
 2013-02-16  Jonas Bernoulli  <jonas@bernoul.li>
 
        * emacs-lisp/tabulated-list.el (tabulated-list-print-col):
index fcbea9457147c377428e5957a3374e480dec03e7..e539848675c7f08dc45658a329c51889570b31e7 100644 (file)
@@ -340,6 +340,9 @@ call."
     (define-key map (kbd "S-SPC")     'image-scroll-down)
     (define-key map (kbd "DEL")       'image-scroll-down)
     (define-key map (kbd "RET")       'image-toggle-animation)
+    (define-key map "F" 'image-goto-frame)
+    (define-key map "f" 'image-next-frame)
+    (define-key map "b" 'image-previous-frame)
     (define-key map "n" 'image-next-file)
     (define-key map "p" 'image-previous-file)
     (define-key map [remap forward-char] 'image-forward-hscroll)
@@ -627,6 +630,37 @@ Otherwise it plays once, then stops."
            (image-animate image index
                           (if image-animate-loop t)))))))))
 
+(defun image-goto-frame (n &optional relative)
+  "Show frame N of a multi-frame image.
+Optional argument OFFSET non-nil means interpret N as relative to the
+current frame.  Frames are indexed from 1."
+  (interactive
+   (list (or current-prefix-arg
+            (read-number "Show frame number: "))))
+  (let ((image (image-get-display-property))
+       animation)
+    (cond
+     ((null image)
+      (error "No image is present"))
+     ((null image-current-frame)
+      (message "No image animation."))
+     (t
+      (image-nth-frame image (if relative (+ n image-current-frame) (1- n)))))))
+
+(defun image-next-frame (&optional n)
+  "Switch to the next frame of a multi-frame image.
+With optional argument N, switch to the Nth frame after the current one.
+If N is negative, switch to the Nth frame before the current one."
+  (interactive "p")
+  (image-goto-frame n t))
+
+(defun image-previous-frame (&optional n)
+  "Switch to the previous frame of a multi-frame image.
+With optional argument N, switch to the Nth frame before the current one.
+If N is negative, switch to the Nth frame after the current one."
+  (interactive "p")
+  (image-next-frame (- n)))
+
 \f
 ;;; Switching to the next/previous image
 
index e0521ad065a44d3c66ae537d53edb5a9a9b8a068..b03a634d060a52e58265c756fa2287ceb8892217 100644 (file)
@@ -660,6 +660,17 @@ number, play until that number of seconds has elapsed."
 (defvar-local image-current-frame nil
   "The frame index of the current animated image.")
 
+(defun image-nth-frame (image n &optional nocheck)
+  "Show frame N of IMAGE.
+Frames are indexed from 0.  Optional argument NOCHECK non-nil means
+do not check N is within the range of frames present in the image."
+  (unless nocheck
+    (if (< n 0) (setq n 0)
+      (setq n (min n (1- (car (image-animated-p image)))))))
+  (plist-put (cdr image) :index n)
+  (setq image-current-frame n)
+  (force-window-update))
+
 ;; FIXME? The delay may not be the same for different sub-images,
 ;; hence we need to call image-animated-p to return it.
 ;; But it also returns count, so why do we bother passing that as an
@@ -674,9 +685,7 @@ LIMIT determines when to stop.  If t, loop forever.  If nil, stop
  after displaying the last animation frame.  Otherwise, stop
  after LIMIT seconds have elapsed.
 The minimum delay between successive frames is 0.01s."
-  (plist-put (cdr image) :index n)
-  (setq image-current-frame n)
-  (force-window-update)
+  (image-nth-frame image n t)
   (setq n (1+ n))
   (let* ((time (float-time))
         (animation (image-animated-p image))