Rework recent image-multi-frame stuff a little

* image.el (image-current-frame): Change from variable to function.
(image-show-frame): Rename from image-nth-frame.  Update callers.

* image-mode.el (image-multi-frame): New variable.
(image-mode-map, image-mode, image-goto-frame):
Use image-multi-frame rather than image-current-frame.
(image-mode, image-goto-frame):
Use image-current-frame as function rather than as variable.
This commit is contained in:
Glenn Morris 2013-02-19 23:57:33 -08:00
parent 6181850468
commit dc50451531
3 changed files with 32 additions and 17 deletions

View file

@ -1,5 +1,13 @@
2013-02-20 Glenn Morris <rgm@gnu.org>
* image.el (image-current-frame): Change from variable to function.
(image-show-frame): Rename from image-nth-frame. Update callers.
* image-mode.el (image-multi-frame): New variable.
(image-mode-map, image-mode, image-goto-frame):
Use image-multi-frame rather than image-current-frame.
(image-mode, image-goto-frame): Use image-current-frame as
function rather than as variable.
* emacs-lisp/cl-lib.el (cl-floatp-safe): Make it an alias for floatp.
* emacs-lisp/cl-macs.el (cl--make-type-test)
(cl--compiler-macro-assoc): Use floatp rather than cl-floatp-safe.

View file

@ -329,6 +329,9 @@ call."
"The image type for the current Image mode buffer.")
(make-variable-buffer-local 'image-type)
(defvar-local image-multi-frame nil
"Non-nil if image for the current Image mode buffer has multiple frames.")
(defvar image-mode-previous-major-mode nil
"Internal variable to keep the previous non-image major mode.")
@ -390,7 +393,7 @@ call."
["Animate Image" image-toggle-animation :style toggle
:selected (let ((image (image-get-display-property)))
(and image (image-animate-timer image)))
:active image-current-frame
:active image-multi-frame
:help "Toggle image animation"]
["Loop Animation"
(lambda () (interactive)
@ -403,13 +406,13 @@ call."
(image-toggle-animation)
(image-toggle-animation)))
:style toggle :selected image-animate-loop
:active image-current-frame
:active image-multi-frame
:help "Animate images once, or forever?"]
["Next Frame" image-next-frame :active image-current-frame
["Next Frame" image-next-frame :active image-multi-frame
:help "Show the next frame of this image"]
["Previous Frame" image-previous-frame :active image-current-frame
["Previous Frame" image-previous-frame :active image-multi-frame
:help "Show the previous frame of this image"]
["Goto Frame..." image-goto-frame :active image-current-frame
["Goto Frame..." image-goto-frame :active image-multi-frame
:help "Show a specific frame of this image"]
))
map)
@ -471,12 +474,13 @@ to toggle between display as an image and display as text."
((null image)
(message "%s" (concat msg1 "an image.")))
((setq animated (image-multi-frame-p image))
(setq image-current-frame (or (plist-get (cdr image) :index) 0)
(setq image-multi-frame t
mode-line-process
`(:eval (propertize (format " [%s/%s]"
(1+ image-current-frame)
,(car animated))
'help-echo "Frame number")))
`(:eval (propertize
(format " [%s/%s]"
(1+ (image-current-frame ',image))
,(car animated))
'help-echo "Frame number")))
(message "%s"
(concat msg1 "text. This image has multiple frames.")))
;;; (substitute-command-keys
@ -694,10 +698,13 @@ current frame. Frames are indexed from 1."
(cond
((null image)
(error "No image is present"))
((null image-current-frame)
((null image-multi-frame)
(message "No image animation."))
(t
(image-nth-frame image (if relative (+ n image-current-frame) (1- n)))))))
(image-show-frame image
(if relative
(+ n (image-current-frame image))
(1- n)))))))
(defun image-next-frame (&optional n)
"Switch to the next frame of a multi-frame image.

View file

@ -660,10 +660,11 @@ number, play until that number of seconds has elapsed."
(defconst image-minimum-frame-delay 0.01
"Minimum interval in seconds between frames of an animated image.")
(defvar-local image-current-frame nil
"The frame index of the current animated image.")
(defun image-current-frame (image)
"The current frame number of IMAGE, indexed from 0."
(or (plist-get (cdr image) :index) 0))
(defun image-nth-frame (image n &optional nocheck)
(defun image-show-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."
@ -671,7 +672,6 @@ do not check N is within the range of frames present in the image."
(if (< n 0) (setq n 0)
(setq n (min n (1- (car (image-multi-frame-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,
@ -688,7 +688,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 `image-minimum-frame-delay'."
(image-nth-frame image n t)
(image-show-frame image n t)
(setq n (1+ n))
(let* ((time (float-time))
(animation (image-multi-frame-p image))