emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: image-transform.el and image-mode.el rewrite


From: Vitalie Spinu
Subject: Re: image-transform.el and image-mode.el rewrite
Date: Mon, 15 Dec 2014 01:33:03 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Hi,

I have finally got down to this.

The image-transform.el and refactored image-mode.el:

  https://github.com/vspinu/image-transform

Diff:

  https://github.com/vspinu/image-transform/compare/emacs...master

Tests and examples:

  https://github.com/vspinu/image-transform/blob/master/tests.el


The documentation is in `image-transform` and `image-transform-backends`
docstrings.

The biggest change on image-mode.el side is the introduction of the
local `image-manipulation-map` that includes all commands that are also
meaningful outside of `image-mode.el`.

I changed functions that are meaningful outside of `image-mode` not to
include "-mode-" infix and to operate on &optional image instead of
current image. Once the patch is agreed upon, I would like to isolate
all these functions into a separate `image-manip.el`. The
`image-mode.el` is better kept for image-mode, image-minor-mode and
multi-image-mode (still to be written).

At this stage the stuff is ready for a review as I have only minor
things to fix. I will be traveling till 18th and will resume once I am
back. Would be really great if interested people could have a quick look
till then.

Thanks,

  Vitalie


        Modified   image-mode.el
diff --git a/image-mode.el b/image-mode.el
index b94162d..630b2e0 100644
--- a/image-mode.el
+++ b/image-mode.el
@@ -39,9 +39,50 @@
 ;;; Code:
 
 (require 'image)
-(eval-when-compile (require 'cl-lib))
+(require 'image-transform)
+;; fixme: VS: why did I remove this?
+;; (eval-when-compile (require 'cl-lib))
+
+(defgroup image-mode ()
+  "Support for visiting image files."
+  :group 'multimedia)
+
+(defcustom image-mode-auto-resize 'fit-if-large
+  "Image auto-resize default.
+
+If null, don't auto resize.  If set to a symbol, must take one of
+the following values:
+
+   *`fit' - maximally scale IMAGE to fit into window
+   *`fit-if-large' - like `fit', but only when image is larger than window
+   *`fit-height' - fit the image to window height
+   *`fit-width' - fit the image to window width
+   *`fit-stretch' - stretch the image to fit to both height and
+    width of the window
+
+A number is interpreted as width in pixels.  Cons cell, string and
+list values are as the VALUE argument of `image-transform-spec:geometry'."
+  :type '(choice
+         (const :tag "No Resize" nil)
+         (const :tag "Fit" fit)
+         (const :tag "Fit if Large" fit-if-large)
+         (const :tag "Fit Height" fit-height)
+         (const :tag "Fit Width" fit-width)
+         (const :tag "Fit Stretch" fit-stretch)
+         (number :tag "Width")
+         (string)
+         (cons number number)
+         (list number number string))
+  :group 'image-mode
+  :version "25.1")
+
+(defcustom image-mode-show-cursor t
+  "Non-nil if the cursor should be shown in `image-mode'."
+  :group 'image-mode
+  :type 'boolean)
 
-;;; Image mode window-info management.
+
+;;; Window Info Management.
 
 (defvar-local image-mode-winprops-alist t)
 
@@ -49,31 +90,13 @@
   "Special hook run when image data is requested in a new window.
 It is called with one argument, the initial WINPROPS.")
 
-;; FIXME this doesn't seem mature yet. Document in manual when it is.
-(defvar image-transform-resize nil
-  "The image resize operation.
-Its value should be one of the following:
- - nil, meaning no resizing.
- - `fit-height', meaning to fit the image to the window height.
- - `fit-width', meaning to fit the image to the window width.
- - A number, which is a scale factor (the default size is 1).")
-
-(defvar image-transform-scale 1.0
-  "The scale factor of the image being displayed.")
-
-(defvar image-transform-rotation 0.0
-  "Rotation angle for the image in the current Image mode buffer.")
-
-(defvar image-transform-right-angle-fudge 0.0001
-  "Snap distance to a multiple of a right angle.
-There's no deep theory behind the default value, it should just
-be somewhat larger than ImageMagick's MagickEpsilon.")
-
 (defun image-mode-winprops (&optional window cleanup)
   "Return winprops of WINDOW.
-A winprops object has the shape (WINDOW . ALIST).
-WINDOW defaults to `selected-window' if it displays the current buffer, and
-otherwise it defaults to t, used for times when the buffer is not displayed."
+A winprops object has the shape (WINDOW . ALIST).  WINDOW defaults
+to `selected-window' if it displays the current buffer, and
+otherwise it defaults to t, used for times when the buffer is not
+displayed.  When CLEANUP is non-nil, remove all winprops with
+deleted window."
   (cond ((null window)
          (setq window
                (if (eq (current-buffer) (window-buffer)) (selected-window) t)))
@@ -144,13 +167,45 @@ otherwise it defaults to t, used for times when the 
buffer is not displayed."
   (add-hook 'window-configuration-change-hook
            'image-mode-reapply-winprops nil t))
 
-;;; Image scrolling functions
-
-(defun image-get-display-property ()
-  (get-char-property (point-min) 'display
-                     ;; There might be different images for different displays.
-                     (if (eq (window-buffer) (current-buffer))
-                         (selected-window))))
+
+;;; Access Images at Point
+
+(defun image-get-display-property (&optional pos)
+  (setq pos (or pos (point)))
+  (or (get-char-property pos 'display
+                        ;; There might be different images for different 
displays.
+                        (if (eq (window-buffer) (current-buffer))
+                            (selected-window)))
+      ;; overlay before-string/after-string display property, like in put-image
+      (let ((OVS (overlays-at pos))
+           ov disp)
+       (while (setq ov (pop OVS))
+         (let ((bs (overlay-get ov 'before-string))
+               (as (overlay-get ov 'after-string)))
+           ;; last one takes precedence
+           (setq disp (or (and as (get-text-property 0 'display as))
+                          (and bs (get-text-property 0 'display bs))))))
+       disp)))
+
+(defun image-at-point (&optional pos)
+  "Return image at POS if there is one, or nil otherwise.
+Search text and overlays at POS for a 'display' property that
+holds an image.  POS defaults to point."
+  ;; fixme: check preceding point as well
+  (let* ((disp (image-get-display-property pos)))
+    (or (and (eq (car-safe disp) 'image)
+            disp)
+       ;; margin images
+       (and (eq (car-safe (cdr-safe disp)) 'image)
+            (cdr disp)))))
+
+(defun image-get-transforms (&optional image)
+  "Return transformation chain of the IMAGE.
+IMAGE defaults to `image-at-point'."
+  (interactive)
+  (setq image (or image (image-at-point)))
+  (or (plist-get (cdr image) :transforms)
+      '(tr)))
 
 (declare-function image-size "image.c" (spec &optional pixels frame))
 
@@ -179,6 +234,10 @@ but not `slice', return the `image-size' of the specified 
image."
            (t
             (error "Invalid image specification: %s" spec))))))
 
+
+;;; Image Scrolling
+;; fixme: operate on images?
+
 (defun image-forward-hscroll (&optional n)
   "Scroll image in current window to the left by N character widths.
 Stop if the right edge of the image is reached."
@@ -305,21 +364,22 @@ stopping if the top or bottom edge of the image is 
reached."
     (image-set-window-hscroll (max 0 (- img-width win-width)))
     (image-set-window-vscroll (max 0 (- img-height win-height)))))
 
-;; Adjust frame and image size.
+
+;;; Adjust frame and image size.
 
-(defun image-mode-fit-frame (&optional frame toggle)
-  "Fit FRAME to the current image.
+(defun image-scale-frame-to-fit-image (&optional frame toggle image)
+  "Fit FRAME to the image.
 If FRAME is omitted or nil, it defaults to the selected frame.
 All other windows on the frame are deleted.
 
 If called interactively, or if TOGGLE is non-nil, toggle between
-fitting FRAME to the current image and restoring the size and
-window configuration prior to the last `image-mode-fit-frame'
-call."
+fitting FRAME to the IMAGE and restoring the size and window
+configuration prior to the last `image-scale-frame-to-fit-image'
+call.  IMAGE defaults to `image-at-point'."
   (interactive (list nil t))
   (let* ((buffer (current-buffer))
-         (display (image-get-display-property))
-         (size (image-display-size display))
+         (image (image-at-point))
+         (size (image-display-size image))
         (saved (frame-parameter frame 'image-mode-saved-params))
         (window-configuration (current-window-configuration frame))
         (width  (frame-width  frame))
@@ -352,34 +412,27 @@ call."
                                     (cons width height)
                                     window-configuration)))))))
 
-;;; Image Mode setup
+(define-obsolete-function-alias 'image-mode-fit-frame 
'image-scale-frame-to-fit-image "25.1")
+
+
+;;; Image Mode
 
 (defvar-local image-type nil
   "The image type for the current Image mode buffer.")
 
-(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.")
 
 (defvar image-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map special-mode-map)
-    (define-key map "\C-c\C-c" 'image-toggle-display)
+    (define-key map "\C-c\C-c" 'image-mode-toggle-display)
     (define-key map (kbd "SPC")       'image-scroll-up)
     (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 "a+" 'image-increase-speed)
-    (define-key map "a-" 'image-decrease-speed)
-    (define-key map "a0" 'image-reset-speed)
-    (define-key map "ar" 'image-reverse-speed)
+    (define-key map "n" 'image-mode-next-file)
+    (define-key map "p" 'image-mode-previous-file)
     (define-key map [remap forward-char] 'image-forward-hscroll)
     (define-key map [remap backward-char] 'image-backward-hscroll)
     (define-key map [remap right-char] 'image-forward-hscroll)
@@ -396,82 +449,22 @@ call."
     (define-key map [remap end-of-buffer] 'image-eob)
     (easy-menu-define image-mode-menu map "Menu for Image mode."
       '("Image"
-       ["Show as Text" image-toggle-display :active t
+       ["Show as Text" image-mode-toggle-display :active t
         :help "Show image as text"]
        "--"
-       ["Fit to Window Height" image-transform-fit-to-height
-        :visible (eq image-type 'imagemagick)
-        :help "Resize image to match the window height"]
-       ["Fit to Window Width" image-transform-fit-to-width
-        :visible (eq image-type 'imagemagick)
-        :help "Resize image to match the window width"]
-       ["Rotate Image..." image-transform-set-rotation
-        :visible (eq image-type 'imagemagick)
-        :help "Rotate the image"]
-       ["Reset Transformations" image-transform-reset
-        :visible (eq image-type 'imagemagick)
-        :help "Reset all image transformations"]
-       "--"
-       ["Show Thumbnails"
-        (lambda ()
-          (interactive)
-          (image-dired default-directory))
-        :active default-directory
+       ["Show Thumbnails" image-mode-show-thumbnails :active default-directory
         :help "Show thumbnails for all images in this directory"]
-       ["Next Image" image-next-file :active buffer-file-name
+       ["Next Image" image-mode-next-file :active buffer-file-name
          :help "Move to next image in this directory"]
-       ["Previous Image" image-previous-file :active buffer-file-name
+       ["Previous Image" image-mode-previous-file :active buffer-file-name
          :help "Move to previous image in this directory"]
-       "--"
-       ["Fit Frame to Image" image-mode-fit-frame :active t
-        :help "Resize frame to match image"]
-       "--"
-       ["Animate Image" image-toggle-animation :style toggle
-        :selected (let ((image (image-get-display-property)))
-                    (and image (image-animate-timer image)))
-        :active image-multi-frame
-         :help "Toggle image animation"]
-       ["Loop Animation"
-        (lambda () (interactive)
-          (setq image-animate-loop (not image-animate-loop))
-          ;; FIXME this is a hacky way to make it affect a currently
-          ;; animating image.
-          (when (let ((image (image-get-display-property)))
-                  (and image (image-animate-timer image)))
-            (image-toggle-animation)
-            (image-toggle-animation)))
-        :style toggle :selected image-animate-loop
-        :active image-multi-frame
-        :help "Animate images once, or forever?"]
-       ["Reverse Animation" image-reverse-speed
-        :style toggle :selected (let ((image (image-get-display-property)))
-                                  (and image (<
-                                              (image-animate-get-speed image)
-                                              0)))
-        :active image-multi-frame
-        :help "Reverse direction of this image's animation?"]
-       ["Speed Up Animation" image-increase-speed
-        :active image-multi-frame
-        :help "Speed up this image's animation"]
-       ["Slow Down Animation" image-decrease-speed
-        :active image-multi-frame
-        :help "Slow down this image's animation"]
-       ["Reset Animation Speed" image-reset-speed
-        :active image-multi-frame
-        :help "Reset the speed of this image's animation"]
-       ["Next Frame" image-next-frame :active image-multi-frame
-        :help "Show the next frame of this image"]
-       ["Previous Frame" image-previous-frame :active image-multi-frame
-        :help "Show the previous frame of this image"]
-       ["Goto Frame..." image-goto-frame :active image-multi-frame
-        :help "Show a specific frame of this image"]
        ))
     map)
   "Mode keymap for `image-mode'.")
 
 (defvar image-minor-mode-map
   (let ((map (make-sparse-keymap)))
-    (define-key map "\C-c\C-c" 'image-toggle-display)
+    (define-key map "\C-c\C-c" 'image-mode-toggle-display)
     map)
   "Mode keymap for `image-minor-mode'.")
 
@@ -482,7 +475,7 @@ call."
 ;;;###autoload
 (defun image-mode ()
   "Major mode for image files.
-You can use \\<image-mode-map>\\[image-toggle-display]
+You can use \\<image-mode-map>\\[image-mode-toggle-display]
 to toggle between display as an image and display as text.
 
 Key bindings:
@@ -498,7 +491,7 @@ Key bindings:
 
        (if (not (image-get-display-property))
            (progn
-             (image-toggle-display-image)
+             (image-mode-toggle-display-image)
              ;; If attempt to display the image fails.
              (if (not (image-get-display-property))
                  (error "Invalid image")))
@@ -512,24 +505,25 @@ Key bindings:
 
        ;; Use our own bookmarking function for images.
        (setq-local bookmark-make-record-function
-                    #'image-bookmark-make-record)
+                   #'image-bookmark-make-record)
 
        ;; Keep track of [vh]scroll when switching buffers
        (image-mode-setup-winprops)
 
-       (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
-       (add-hook 'after-revert-hook 'image-after-revert-hook nil t)
+       (setq-local revert-buffer-function 'image-mode-revert-buffer)
+
+       (add-hook 'change-major-mode-hook 'image-mode-toggle-display-text nil t)
+       (add-hook 'after-revert-hook 'image-mode-after-revert nil t)
        (run-mode-hooks 'image-mode-hook)
        (let ((image (image-get-display-property))
              (msg1 (substitute-command-keys
-                    "Type \\[image-toggle-display] to view the image as "))
+                    "Type \\[image-mode-toggle-display] to view the image as 
"))
              animated)
          (cond
           ((null image)
            (message "%s" (concat msg1 "an image.")))
           ((setq animated (image-multi-frame-p image))
-           (setq image-multi-frame t
-                 mode-line-process
+           (setq mode-line-process
                  `(:eval
                    (concat " "
                            (propertize
@@ -559,6 +553,12 @@ mouse-3: Previous frame"
       (if (called-interactively-p 'any) 'error 'message)
       "Cannot display image: %s" (cdr err)))))
 
+(defun image-mode-revert-buffer (ignore noconfirm)
+  ;; fixme: revert without re-installing the mode; deriving modes is difficult
+  ;; don't ask on reversion
+  (let ((revert-buffer-function nil))
+    (revert-buffer ignore t)))
+
 ;;;###autoload
 (define-minor-mode image-minor-mode
   "Toggle Image minor mode in this buffer.
@@ -566,7 +566,7 @@ With a prefix argument ARG, enable Image minor mode if ARG 
is
 positive, and disable it otherwise.  If called from Lisp, enable
 the mode if ARG is omitted or nil.
 
-Image minor mode provides the key \\<image-mode-map>\\[image-toggle-display],
+Image minor mode provides the key 
\\<image-mode-map>\\[image-mode-toggle-display],
 to switch back to `image-mode' and display an image file as the
 actual image."
   nil (:eval (if image-type (format " Image[%s]" image-type) " Image"))
@@ -581,7 +581,7 @@ actual image."
   "Set a non-image mode as major mode in combination with image minor mode.
 A non-image major mode found from `auto-mode-alist' or Fundamental mode
 displays an image file as text.  `image-minor-mode' provides the key
-\\<image-mode-map>\\[image-toggle-display] to switch back to `image-mode'
+\\<image-mode-map>\\[image-mode-toggle-display] to switch back to `image-mode'
 to display an image file as the actual image.
 
 You can use `image-mode-as-text' in `auto-mode-alist' when you want
@@ -617,16 +617,16 @@ on these modes."
     ;; Enable image minor mode with `C-c C-c'.
     (image-minor-mode 1)
     ;; Show the image file as text.
-    (image-toggle-display-text)
+    (image-mode-toggle-display-text)
     (message "%s" (concat
                   (substitute-command-keys
-                   "Type \\[image-toggle-display] to view the image as ")
+                   "Type \\[image-mode-toggle-display] to view the image as ")
                   (if (image-get-display-property)
                       "text" "an image") "."))))
 
 (define-obsolete-function-alias 'image-mode-maybe 'image-mode "23.2")
 
-(defun image-toggle-display-text ()
+(defun image-mode-toggle-display-text ()
   "Show the image file as text.
 Remove text properties that display the image."
   (let ((inhibit-read-only t)
@@ -639,11 +639,19 @@ Remove text properties that display the image."
     (if (called-interactively-p 'any)
        (message "Repeat this command to go back to displaying the image"))))
 
+(define-obsolete-function-alias 'image-toggle-display-text 
'image-mode-toggle-display-text "25.1")
+
+(defun image-mode-show-thumbnails ()
+  "Show thumbnails alongside dired buffer.
+Based on `image-dired'"
+  (interactive)
+  (image-dired default-directory))
+
 (defvar archive-superior-buffer)
 (defvar tar-superior-buffer)
 (declare-function image-flush "image.c" (spec &optional frame))
 
-(defun image-toggle-display-image ()
+(defun image-mode-toggle-display-image ()
   "Show the image of the image file.
 Turn the image data into a real image, but only if the whole file
 was inserted."
@@ -662,19 +670,9 @@ was inserted."
                           (string-make-unibyte
                            (buffer-substring-no-properties (point-min) 
(point-max)))
                         filename))
-        ;; If we have a `fit-width' or a `fit-height', don't limit
-        ;; the size of the image to the window size.
-        (edges (and (null image-transform-resize)
-                    (window-inside-pixel-edges
-                     (get-buffer-window (current-buffer)))))
-        (type (if (fboundp 'imagemagick-types)
-                  'imagemagick
-                (image-type file-or-data nil data-p)))
-        (image (if (not edges)
-                   (create-image file-or-data type data-p)
-                 (create-image file-or-data type data-p
-                               :max-width (- (nth 2 edges) (nth 0 edges))
-                               :max-height (- (nth 3 edges) (nth 1 edges)))))
+        (image (create-image file-or-data nil data-p))
+        (type (plist-get (cdr image) :type))
+        ;; (type (image-type file-or-data nil data-p))
         (inhibit-read-only t)
         (buffer-undo-list t)
         (modified (buffer-modified-p))
@@ -682,19 +680,23 @@ was inserted."
 
     ;; Discard any stale image data before looking it up again.
     (image-flush image)
-    (setq image (append image (image-transform-properties image)))
+    (image-transform-interactive image :resize image-mode-auto-resize)
+    
     (setq props
          `(display ,image
                    ;; intangible ,image
                    rear-nonsticky (display) ;; intangible
-                   read-only t front-sticky (read-only)))
+                   read-only t front-sticky (read-only)
+                   keymap ,image-manipulation-map))
 
     (let ((buffer-file-truename nil)) ; avoid changing dir mtime by lock_file
       (add-text-properties (point-min) (point-max) props)
       (restore-buffer-modified-p modified))
-    ;; Inhibit the cursor when the buffer contains only an image,
-    ;; because cursors look very strange on top of images.
-    (setq cursor-type nil)
+
+    ;; It's important to distinguish active buffer/image.
+    (unless image-mode-show-cursor
+      (setq cursor-type nil))
+
     ;; This just makes the arrow displayed in the right fringe
     ;; area look correct when the image is wider than the window.
     (setq truncate-lines t)
@@ -708,11 +710,12 @@ was inserted."
     (setq image-type type)
     (if (eq major-mode 'image-mode)
        (setq mode-name (format "Image[%s]" type)))
-    (image-transform-check-size)
     (if (called-interactively-p 'any)
        (message "Repeat this command to go back to displaying the file as 
text"))))
 
-(defun image-toggle-display ()
+(define-obsolete-function-alias 'image-toggle-display-image  
'image-mode-toggle-display-image "25.1")
+
+(defun image-mode-toggle-display ()
   "Toggle between image and text display.
 If the current buffer is displaying an image file as an image,
 call `image-mode-as-text' to switch to text.  Otherwise, display
@@ -722,13 +725,17 @@ the image by calling `image-mode'."
       (image-mode-as-text)
     (image-mode)))
 
-(defun image-after-revert-hook ()
+(define-obsolete-function-alias 'image-toggle-display 
'image-mode-toggle-display "25.1")
+
+(defun image-mode-after-revert ()
   (when (image-get-display-property)
-    (image-toggle-display-text)
+    (image-mode-toggle-display-text)
     ;; Update image display.
     (mapc (lambda (window) (redraw-frame (window-frame window)))
-          (get-buffer-window-list (current-buffer) 'nomini 'visible))
-    (image-toggle-display-image)))
+         (get-buffer-window-list (current-buffer) 'nomini 'visible))
+    (image-mode-toggle-display-image)))
+
+(define-obsolete-function-alias 'image-after-revert-hook 
'image-mode-after-revert "25.1")
 
 
 ;;; Animated images
@@ -739,12 +746,13 @@ the image by calling `image-mode'."
   :version "24.1"
   :group 'image)
 
-(defun image-toggle-animation ()
-  "Start or stop animating the current image.
-If `image-animate-loop' is non-nil, animation loops forever.
-Otherwise it plays once, then stops."
+(defun image-toggle-animation (&optional image)
+  "Start or stop animating IMAGE.
+If `image-animate-loop' is non-nil, animation loops
+forever.  Otherwise it plays once, then stops.  IMAGE defaults to
+the image at point."
   (interactive)
-  (let ((image (image-get-display-property))
+  (let ((image (or image (image-at-point)))
        animation)
     (cond
      ((null image)
@@ -763,15 +771,16 @@ Otherwise it plays once, then stops."
            (image-animate image index
                           (if image-animate-loop t)))))))))
 
-(defun image--set-speed (speed &optional multiply)
-  "Set speed of an animated image to SPEED.
+(defun image--set-speed (image speed &optional multiply)
+  "Set speed of an animated IMAGE to SPEED.
 If MULTIPLY is non-nil, treat SPEED as a multiplication factor.
-If SPEED is `reset', reset the magnitude of the speed to 1."
-  (let ((image (image-get-display-property)))
+If SPEED is `reset', reset the magnitude of the speed to 1.
+IMAGE defaults to `image-at-point'."
+  (let ((image (or image (image-at-point))))
     (cond
      ((null image)
       (error "No image is present"))
-     ((null image-multi-frame)
+     ((null (image-multi-frame-p image))
       (message "No image animation."))
      (t
       (if (eq speed 'reset)
@@ -785,38 +794,46 @@ If SPEED is `reset', reset the magnitude of the speed to 
1."
        (image-toggle-animation))
       (message "Image speed is now %s" (image-animate-get-speed image))))))
 
-(defun image-increase-speed ()
-  "Increase the speed of current animated image by a factor of 2."
+(defun image-increase-speed (&optional image)
+  "Increase the speed of animated IMAGE by a factor of 2.
+IMAGE defaults to `image-at-point'."
   (interactive)
-  (image--set-speed 2 t))
+  (image--set-speed image 2 t))
 
-(defun image-decrease-speed ()
-  "Decrease the speed of current animated image by a factor of 2."
+(defun image-decrease-speed (&optional image)
+  "Decrease the speed of animated IMAGE by a factor of 2.
+IMAGE defaults to `image-at-point'"
   (interactive)
-  (image--set-speed 0.5 t))
+  (image--set-speed image 0.5 t))
 
-(defun image-reverse-speed ()
-  "Reverse the animation of the current image."
+(defun image-reverse-speed (&optional image)
+  "Reverse the animation of the IMAGE.
+IMAGE defaults to `image-at-point'."
   (interactive)
-  (image--set-speed -1 t))
+  (image--set-speed image -1 t))
 
-(defun image-reset-speed ()
-  "Reset the animation speed of the current image."
+(defun image-reset-speed (&optional image)
+  "Reset the animation speed of the IMAGE.
+IMAGE defaults to `image-at-point'."
   (interactive)
   (image--set-speed 'reset))
 
-(defun image-goto-frame (n &optional relative)
+
+;;; Multiframe Images
+
+(defun image-goto-frame (n &optional relative image)
   "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."
+Optional argument RELATIVE non-nil means interpret N as relative
+to the current frame.  Frames are indexed from 1. IMAGE defaults
+to `image-at-point'."
   (interactive
    (list (or current-prefix-arg
             (read-number "Show frame number: "))))
-  (let ((image (image-get-display-property)))
+  (let ((image (or image (image-at-point))))
     (cond
      ((null image)
       (error "No image is present"))
-     ((null image-multi-frame)
+     ((null (image-multi-frame-p image))
       (message "No image animation."))
      (t
       (image-show-frame image
@@ -824,24 +841,26 @@ current frame.  Frames are indexed from 1."
                            (+ n (image-current-frame image))
                          (1- n)))))))
 
-(defun image-next-frame (&optional n)
+(defun image-next-frame (&optional n image)
   "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."
+If N is negative, switch to the Nth frame before the current one.
+IMAGE defaults to `image-at-point'."
   (interactive "p")
   (image-goto-frame n t))
 
-(defun image-previous-frame (&optional n)
+(defun image-previous-frame (&optional n image)
   "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."
+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.  IMAGE defaults to `image-at-point'."
   (interactive "p")
   (image-next-frame (- n)))
 
 
 ;;; Switching to the next/previous image
 
-(defun image-next-file (&optional n)
+(defun image-mode-next-file (&optional n)
   "Visit the next image in the same directory as the current image file.
 With optional argument N, visit the Nth image file after the
 current one, in cyclic alphabetical order.
@@ -864,7 +883,9 @@ replacing the current Image mode buffer."
     (setq idx (mod (+ idx (or n 1)) (length images)))
     (find-alternate-file (nth idx images))))
 
-(defun image-previous-file (&optional n)
+(define-obsolete-function-alias 'image-next-file 'image-mode-next-file "25.1")
+
+(defun image-mode-previous-file (&optional n)
   "Visit the preceding image in the same directory as the current file.
 With optional argument N, visit the Nth image file preceding the
 current one, in cyclic alphabetical order.
@@ -872,7 +893,7 @@ current one, in cyclic alphabetical order.
 This command visits the specified file via `find-alternate-file',
 replacing the current Image mode buffer."
   (interactive "p")
-  (image-next-file (- n)))
+  (image-mode-next-file (- n)))
 
 (defun image-mode--images-in-directory (file)
   (let* ((dir (file-name-directory buffer-file-name))
@@ -884,6 +905,8 @@ replacing the current Image mode buffer."
       (push file files))
     (sort files 'string-lessp)))
 
+(define-obsolete-function-alias 'image-previous-file 'image-mode-previous-file 
"25.1")
+
 
 ;;; Support for bookmark.el
 (declare-function bookmark-make-record-default
@@ -902,219 +925,236 @@ replacing the current Image mode buffer."
   ;; returned by `bookmark-make-record-function', which see.
   (prog1 (bookmark-default-handler bmk)
     (when (not (string= image-type (bookmark-prop-get bmk 'image-type)))
-      (image-toggle-display))))
+      (image-mode-toggle-display))))
+
 
+;;; Image Local Manipulation Map
 
-;; Not yet implemented.
-;; (defvar image-transform-minor-mode-map
-;;   (let ((map (make-sparse-keymap)))
-;;     ;; (define-key map  [(control ?+)] 'image-scale-in)
-;;     ;; (define-key map  [(control ?-)] 'image-scale-out)
-;;     ;; (define-key map  [(control ?=)] 'image-scale-none)
-;;     ;; (define-key map "c f h" 'image-scale-fit-height)
-;;     ;; (define-key map "c ]" 'image-rotate-right)
-;;     map)
-;;   "Minor mode keymap `image-transform-mode'.")
-;;
-;; (define-minor-mode image-transform-mode
-;;   "Minor mode for scaling and rotating images.
-;; With a prefix argument ARG, enable the mode if ARG is positive,
-;; and disable it otherwise.  If called from Lisp, enable the mode
-;; if ARG is omitted or nil.  This minor mode requires Emacs to have
-;; been compiled with ImageMagick support."
-;;   nil "image-transform" image-transform-minor-mode-map)
-
-
-(defsubst image-transform-width (width height)
-  "Return the bounding box width of a rotated WIDTH x HEIGHT rectangle.
-The rotation angle is the value of `image-transform-rotation' in degrees."
-  (let ((angle (degrees-to-radians image-transform-rotation)))
-    ;; Assume, w.l.o.g., that the vertices of the rectangle have the
-    ;; coordinates (+-w/2, +-h/2) and that (0, 0) is the center of the
-    ;; rotation by the angle A.  The projections onto the first axis
-    ;; of the vertices of the rotated rectangle are +- (w/2) cos A +-
-    ;; (h/2) sin A, and the difference between the largest and the
-    ;; smallest of the four values is the expression below.
-    (+ (* width (abs (cos angle))) (* height (abs (sin angle))))))
-
-;; The following comment and code snippet are from
-;; ImageMagick-6.7.4-4/magick/distort.c
-
-;;    /* Set the output image geometry to calculated 'best fit'.
-;;       Yes this tends to 'over do' the file image size, ON PURPOSE!
-;;       Do not do this for DePolar which needs to be exact for virtual tiling.
-;;    */
-;;    if ( fix_bounds ) {
-;;      geometry.x = (ssize_t) floor(min.x-0.5);
-;;      geometry.y = (ssize_t) floor(min.y-0.5);
-;;      geometry.width=(size_t) ceil(max.x-geometry.x+0.5);
-;;      geometry.height=(size_t) ceil(max.y-geometry.y+0.5);
-;;    }
-
-;; Other parts of the same file show that here the origin is in the
-;; left lower corner of the image rectangle, the center of the
-;; rotation is the center of the rectangle and min.x and max.x
-;; (resp. min.y and max.y) are the smallest and the largest of the
-;; projections of the vertices onto the first (resp. second) axis.
-
-(defun image-transform-fit-width (width height length)
-  "Return (w . h) so that a rotated w x h image has exactly width LENGTH.
-The rotation angle is the value of `image-transform-rotation'.
-Write W for WIDTH and H for HEIGHT.  Then the w x h rectangle is
-an \"approximately uniformly\" scaled W x H rectangle, which
-currently means that w is one of floor(s W) + {0, 1, -1} and h is
-floor(s H), where s can be recovered as the value of `image-transform-scale'.
-The value of `image-transform-rotation' may be replaced by
-a slightly different angle.  Currently this is done for values
-close to a multiple of 90, see `image-transform-right-angle-fudge'."
-  (cond ((< (abs (- (mod (+ image-transform-rotation 90) 180) 90))
-           image-transform-right-angle-fudge)
-        (cl-assert (not (zerop width)) t)
-        (setq image-transform-rotation
-              (float (round image-transform-rotation))
-              image-transform-scale (/ (float length) width))
-        (cons length nil))
-       ((< (abs (- (mod (+ image-transform-rotation 45) 90) 45))
-           image-transform-right-angle-fudge)
-        (cl-assert (not (zerop height)) t)
-        (setq image-transform-rotation
-              (float (round image-transform-rotation))
-              image-transform-scale (/ (float length) height))
-        (cons nil length))
-       (t
-        (cl-assert (not (and (zerop width) (zerop height))) t)
-        (setq image-transform-scale
-              (/ (float (1- length)) (image-transform-width width height)))
-        ;; Assume we have a w x h image and an angle A, and let l =
-        ;; l(w, h) = w |cos A| + h |sin A|, which is the actual width
-        ;; of the bounding box of the rotated image, as calculated by
-        ;; `image-transform-width'.  The code snippet quoted above
-        ;; means that ImageMagick puts the rotated image in
-        ;; a bounding box of width L = 2 ceil((w+l+1)/2) - w.
-        ;; Elementary considerations show that this is equivalent to
-        ;; L - w being even and L-3 < l(w, h) <= L-1.  In our case, L is
-        ;; the given `length' parameter and our job is to determine
-        ;; reasonable values for w and h which satisfy these
-        ;; conditions.
-        (let ((w (floor (* image-transform-scale width)))
-              (h (floor (* image-transform-scale height))))
-          ;; Let w and h as bound above.  Then l(w, h) <= l(s W, s H)
-          ;; = L-1 < l(w+1, h+1) = l(w, h) + l(1, 1) <= l(w, h) + 2,
-          ;; hence l(w, h) > (L-1) - 2 = L-3.
-          (cons
-           (cond ((= (mod w 2) (mod length 2))
-                  w)
-                 ;; l(w+1, h) >= l(w, h) > L-3, but does l(w+1, h) <=
-                 ;; L-1 hold?
-                 ((<= (image-transform-width (1+ w) h) (1- length))
-                  (1+ w))
-                 ;; No, it doesn't, but this implies that l(w-1, h) =
-                 ;; l(w+1, h) - l(2, 0) >= l(w+1, h) - 2 > (L-1) -
-                 ;; 2 = L-3.  Clearly, l(w-1, h) <= l(w, h) <= L-1.
-                 (t
-                  (1- w)))
-           h)))))
-
-(defun image-transform-check-size ()
-  "Check that the image exactly fits the width/height of the window.
-
-Do this for an image of type `imagemagick' to make sure that the
-elisp code matches the way ImageMagick computes the bounding box
-of a rotated image."
-  (when (and (not (numberp image-transform-resize))
-            (boundp 'image-type)
-            (eq image-type 'imagemagick))
-    (let ((size (image-display-size (image-get-display-property) t)))
-      (cond ((eq image-transform-resize 'fit-width)
-            (cl-assert (= (car size)
-                       (- (nth 2 (window-inside-pixel-edges))
-                          (nth 0 (window-inside-pixel-edges))))
-                    t))
-           ((eq image-transform-resize 'fit-height)
-            (cl-assert (= (cdr size)
-                       (- (nth 3 (window-inside-pixel-edges))
-                          (nth 1 (window-inside-pixel-edges))))
-                    t))))))
-
-(defun image-transform-properties (spec)
-  "Return rescaling/rotation properties for image SPEC.
-These properties are determined by the Image mode variables
-`image-transform-resize' and `image-transform-rotation'.  The
-return value is suitable for appending to an image spec.
-
-Rescaling and rotation properties only take effect if Emacs is
-compiled with ImageMagick support."
-  (setq image-transform-scale 1.0)
-  (when (or image-transform-resize
-           (/= image-transform-rotation 0.0))
-    ;; Note: `image-size' looks up and thus caches the untransformed
-    ;; image.  There's no easy way to prevent that.
-    (let* ((size (image-size spec t))
-          (resized
-           (cond
-            ((numberp image-transform-resize)
-             (unless (= image-transform-resize 1)
-               (setq image-transform-scale image-transform-resize)
-               (cons nil (floor (* image-transform-resize (cdr size))))))
-            ((eq image-transform-resize 'fit-width)
-             (image-transform-fit-width
-              (car size) (cdr size)
-              (- (nth 2 (window-inside-pixel-edges))
-                 (nth 0 (window-inside-pixel-edges)))))
-            ((eq image-transform-resize 'fit-height)
-             (let ((res (image-transform-fit-width
-                         (cdr size) (car size)
-                         (- (nth 3 (window-inside-pixel-edges))
-                            (nth 1 (window-inside-pixel-edges))))))
-               (cons (cdr res) (car res)))))))
-      `(,@(when (car resized)
-           (list :width (car resized)))
-       ,@(when (cdr resized)
-           (list :height (cdr resized)))
-       ,@(unless (= 0.0 image-transform-rotation)
-           (list :rotation image-transform-rotation))))))
-
-(defun image-transform-set-scale (scale)
-  "Prompt for a number, and resize the current image by that amount.
-This command has no effect unless Emacs is compiled with
-ImageMagick support."
-  (interactive "nScale: ")
-  (setq image-transform-resize scale)
-  (image-toggle-display-image))
-
-(defun image-transform-fit-to-height ()
-  "Fit the current image to the height of the current window.
-This command has no effect unless Emacs is compiled with
-ImageMagick support."
+(defcustom image-scale-step 1.1
+  "Each step scales the image by this amount."
+  :type 'number
+  :group 'image)
+
+(defun image-scale-adjust (&optional N)
+  "Adjust the scale of the image by N steps.
+
+N may be passed as a numeric prefix argument.  Each step scales
+the image by the value of `image-scale-step' (a negative number
+of steps decreases the height by the same amount).  As a special
+case, an argument of 0 will remove any scaling currently active.
+
+The actual adjustment depends on the final element of the
+key binding used to invoke this command:
+
+   +, =   Increase the size of the image by one step
+   -      Decrease the size of the image by one step
+   0      Reset to the original image size
+
+When adjusting with `+' or `-', continue to read input events and
+further adjust the scale as long as the input event read \(with
+all modifiers removed) is `+' or `-'.
+
+This command is a special-purpose wrapper around the
+`image-scale-increase'."
+  ;; fixme: doesn't work with universal arg
+  (interactive "p")
+  (let ((ev last-command-event)
+        (echo-keystrokes nil))
+    (let* ((base (event-basic-type ev))
+           (step
+            (pcase base
+              ((or ?+ ?=) N)
+              (?- (- N))
+              (?0 0)
+              (t N))))
+      (image-scale-increase step)
+      (message "Use +,-,0 for further adjustment")
+      (set-temporary-overlay-map
+       (let ((map (make-sparse-keymap)))
+         (dolist (mods '(() (control)))
+           (dolist (key '(?- ?+ ?= ?0)) ;; = is often unshifted +.
+             (define-key map (vector (append mods (list key)))
+               `(lambda () (interactive) (image-scale-adjust (floor (abs 
,N)))))))
+         map)))))
+
+(defun image-scale-increase (&optional inc image)
+  "Scale the the IMAGE by INC steps.
+Each step scales up the size of the IMAGE the value of
+`text-scale-mode-step' (a negative number of steps decreases the
+size by the same amount).  As a special case, an argument of 0
+will remove any scaling currently active. IMAGE defaults to
+`image-at-point'."
+  (interactive "p")
+  (let  ((image (or image
+                   (image-at-point)
+                   (error "No image at point"))))
+    (if (/= inc 0)
+       (image-transform image :scale (* 100 (expt image-scale-step inc)))
+      (image-tr--delete-properties image '(:width :height :resize))
+      ;; don't touch :resize, It might have been set by initial 'fit-xxx 
operation
+      (image-tr--delete-transforms image '(:scale))
+      (image-transform image))
+    (force-window-update (selected-window))))
+
+(defun image-scale-decrease (&optional inc image)
+  "Scale the IMAGE by INC steps.
+Each step scales down the size of the IMAGE the value of
+`text-scale-mode-step' (a negative number of steps increases the
+size by the same amount).  As a special case, an argument of 0
+will remove any scaling currently active. IMAGE defaults to
+`image-at-point'."
+  (interactive "p")
+  (image-scale-increase (- inc) image))
+
+(defun image-scale-to-fit-height (&optional image)
+  "Fit IMAGE to the height of the current window.
+IMAGE defaults to `image-at-point'."
   (interactive)
-  (setq image-transform-resize 'fit-height)
-  (image-toggle-display-image))
+  (image-transform-interactive image :resize 'fit-height))
 
-(defun image-transform-fit-to-width ()
-  "Fit the current image to the width of the current window.
-This command has no effect unless Emacs is compiled with
-ImageMagick support."
+(defun image-scale-to-fit-width (&optional image)
+  "Fit IMAGE to the width of the current window.
+IMAGE defaults to `image-at-point'."
   (interactive)
-  (setq image-transform-resize 'fit-width)
-  (image-toggle-display-image))
+  (image-transform-interactive image :resize 'fit-width))
 
-(defun image-transform-set-rotation (rotation)
-  "Prompt for an angle ROTATION, and rotate the image by that amount.
-ROTATION should be in degrees.  This command has no effect unless
-Emacs is compiled with ImageMagick support."
+(defun image-scale-to-fit-window (&optional image)
+  "Maximally fit IMAGE into current window.
+IMAGE defaults to `image-at-point'."
+  (interactive)
+  (image-transform-interactive image :resize 'fit))
+
+(defun image-stretch-to-fit-window (&optional image)
+  "Stretch IMAGE into current window.
+IMAGE defaults to `image-at-point'."
+  (interactive)
+  (image-transform-interactive image :resize 'fit-stretch))
+
+(defun image-rotate (rotation &optional image)
+  "Prompt for an angle ROTATION, and rotate the IMAGE by that amount.
+ROTATION should be in degrees.  IMAGE defaults to `image-at-point'."
   (interactive "nRotation angle (in degrees): ")
-  (setq image-transform-rotation (float (mod rotation 360)))
-  (image-toggle-display-image))
+  (image-transform-interactive image :rotate rotation))
 
-(defun image-transform-reset ()
-  "Display the current image with the default size and rotation.
-This command has no effect unless Emacs is compiled with
-ImageMagick support."
+(defun image-rotate-right (&optional image)
+  "Rotate the IMAGE clockwise by 90 degrees.
+IMAGE defaults to `image-at-point'."
   (interactive)
-  (setq image-transform-resize nil
-       image-transform-rotation 0.0
-       image-transform-scale 1)
-  (image-toggle-display-image))
+  (image-transform-interactive image :rotate 90))
+
+(defun image-rotate-left (&optional image)
+  "Rotate the IMAGE counter-clockwise by 90 degrees.
+IMAGE defaults to `image-at-point'."
+  (interactive)
+  (image-transform-interactive image :rotate -90))
+
+(defun image-change-background (&optional background image)
+  "Set the BACKGROUND of the IMAGE.
+For this to work, image must have a transparent background.  IMAGE
+defaults to `image-at-point'."
+  (interactive)
+  (let ((bg (or background (read-color "Background: " t))))
+    (unless image
+      (unless (setq image (image-at-point))
+        (error "No image at point")))
+    (image-transform-interactive image :background bg)))
+
+(defvar image-manipulation-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "F" 'image-goto-frame)
+    (define-key map "f" 'image-next-frame)
+    (define-key map "b" 'image-previous-frame)
+    (define-key map "a+" 'image-increase-speed)
+    (define-key map "a-" 'image-decrease-speed)
+    (define-key map "a0" 'image-reset-speed)
+    (define-key map "ar" 'image-reverse-speed)
+    (define-key map "+" 'image-scale-adjust)
+    (define-key map "-" 'image-scale-adjust)
+    (define-key map "=" 'image-scale-adjust)
+    (define-key map "0" 'image-scale-adjust)
+    (define-key map "r" 'image-rotate)
+    (define-key map "]" 'image-rotate-right)
+    (define-key map "[" 'image-rotate-left)
+    (define-key map "ss" 'image-scale-to-fit-window)
+    (define-key map "sh" 'image-scale-to-fit-height)
+    (define-key map "sw" 'image-scale-to-fit-width)
+    (define-key map "sS" 'image-stretch-to-fit-window)
+    (define-key map "sf" 'image-scale-frame-to-fit-image)
+    (define-key map "ta" 'image-add-transform)
+    (define-key map "tk" 'image-delete-transform)
+    (define-key map "td" 'image-delete-transform)
+    (define-key map "tl" 'image-list-transforms)
+    (define-key map "B" 'image-change-background)
+    (easy-menu-define image-mode-menu map "Local Image Menu."
+      '("Manipulate"
+       ["Scale to Window" image-scale-to-fit-window
+        :help "Maximally resize image to fit into window"]
+       ["Scale to Window Height" image-scale-to-fit-height
+        :help "Resize image to match the window height"]
+       ["Scale to Window Width" image-scale-to-fit-width
+        :help "Resize image to match the window width"]
+       ["Scale Frame to Image" image-scale-frame-to-fit-image :active t
+        :help "Resize frame to match image"]
+       "--"
+       ["Rotate Image..." image-rotate]
+       ["Rotate Image Right" image-rotate-right]
+       ["Rotate Image Left" image-rotate-left]
+       "--"
+       ["Change Image Background..." image-change-background]
+       "--"
+       ["Add Transform" image-add-transform]
+       ["Delete Transform" image-delete-transform]
+       ["List Transforms" image-list-transforms]
+       "--"
+       ["Animate Image" image-toggle-animation :style toggle
+        :selected (let ((image (image-at-point)))
+                    (and image (image-animate-timer image)))
+        :active (image-multi-frame-p (image-at-point))
+         :help "Toggle image animation"]
+       ["Loop Animation"
+        (lambda () (interactive)
+          (setq image-animate-loop (not image-animate-loop))
+          ;; FIXME this is a hacky way to make it affect a currently
+          ;; animating image.
+          (when (let ((image (image-get-display-property)))
+                  (and image (image-animate-timer image)))
+            (image-toggle-animation)
+            (image-toggle-animation)))
+        :style toggle :selected image-animate-loop
+        :active (image-multi-frame-p (image-at-point))
+        :help "Animate images once, or forever?"]
+       ["Reverse Animation" image-reverse-speed
+        :style toggle :selected (let ((image (image-get-display-property)))
+                                  (and image (<
+                                              (image-animate-get-speed image)
+                                              0)))
+        :active (image-multi-frame-p (image-at-point))
+        :help "Reverse direction of this image's animation?"]
+       ["Speed Up Animation" image-increase-speed
+        :active (image-multi-frame-p (image-at-point))
+        :help "Speed up this image's animation"]
+       ["Slow Down Animation" image-decrease-speed
+        :active (image-multi-frame-p (image-at-point))
+        :help "Slow down this image's animation"]
+       ["Reset Animation Speed" image-reset-speed
+        :active (image-multi-frame-p (image-at-point))
+        :help "Reset the speed of this image's animation"]
+       ["Next Frame" image-next-frame
+        :active (image-multi-frame-p (image-at-point))
+        :help "Show the next frame of this image"]
+       ["Previous Frame" image-previous-frame
+        :active (image-multi-frame-p (image-at-point))
+        :help "Show the previous frame of this image"]
+       ["Goto Frame..." image-goto-frame
+        :active (image-multi-frame-p (image-at-point))
+        :help "Show a specific frame of this image"]
+       ))
+    map)
+  "Image local manipulation keymap.
+Usually used as keymap text property for images.
+
+\\{image-manipulation-map}")
+
 
 (provide 'image-mode)

        Modified   image.el
diff --git a/image.el b/image.el
index 8430d36..1535567 100644
--- a/image.el
+++ b/image.el
@@ -441,7 +441,7 @@ means display it in the right marginal area."
 
 
 ;;;###autoload
-(defun insert-image (image &optional string area slice)
+(defun insert-image (image &optional string area slice map)
   "Insert IMAGE into current buffer at point.
 IMAGE is displayed by inserting STRING into the current buffer
 with a `display' property whose value is the image.  STRING
@@ -454,7 +454,10 @@ SLICE specifies slice of IMAGE to insert.  SLICE nil or 
omitted
 means insert whole image.  SLICE is a list (X Y WIDTH HEIGHT)
 specifying the X and Y positions and WIDTH and HEIGHT of image area
 to insert.  A float value 0.0 - 1.0 means relative to the width or
-height of the image; integer values are taken as pixel values."
+height of the image; integer values are taken as pixel values.
+If MAP is provided, it must be a keymap what will be used as
+text property keymap. A special value of t means to use
+`image-manipulation-map'"
   ;; Use a space as least likely to cause trouble when it's a hidden
   ;; character in the buffer.
   (unless string (setq string " "))
@@ -471,12 +474,16 @@ height of the image; integer values are taken as pixel 
values."
     ;; cut-and-paste.  (Yanking killed image text next to another copy
     ;; of it loses anyway.)
     (setq image (cons 'image (cdr image))))
+  (when (eq map t)
+    (setq map image-manipulation-map))
   (let ((start (point)))
     (insert string)
     (add-text-properties start (point)
                         `(display ,(if slice
                                        (list (cons 'slice slice) image)
-                                     image) rear-nonsticky (display)))))
+                                     image)
+                                   rear-nonsticky (display)
+                                   keymap ,map))))
 
 
 ;;;###autoload
@@ -519,7 +526,6 @@ The image is automatically split into ROWS x COLS slices."
       (insert (propertize "\n" 'line-height t)))))
 
 
-
 ;;;###autoload
 (defun remove-images (start end &optional buffer)
   "Remove images between START and END in BUFFER.
@@ -558,6 +564,7 @@ BUFFER nil or omitted means use the current buffer."
       (setq path (cdr path)))
     (if found filename)))
 
+
 ;;;###autoload
 (defun find-image (specs)
   "Find an image, choosing one of a list of image specifications.

Attachment: image-transform.el
Description: application/emacs-lisp


reply via email to

[Prev in Thread] Current Thread [Next in Thread]