Subject: Re: bug#9178: 23.1; iimage mode copy and paste file corruption

From: Lars Ingebrigtsen <[email-masked]>
Date: Tue, 20 Aug 2019 14:14:14 -0700

Jason Baietto <[email-masked]> writes:

> I am using the iimage mode to display in-lined images in text files.
> When images are displayed, an image may be double-clicked to select
> it and then pasted at point within the same buffer using the middle
> mouse button.  I can do this using emacs on both Linux and Windows.
>
> The image will appear to be inserted at point and will be displayed as
> as expected (i.e. as a picture).

(I'm going through old bug reports that have unfortunately gotten no
attention yet.)

> However, the the copy and paste was
> a lie.  Although the image is displayed at the new location, only the
> first selectable "word" of the image path has been selected and
> pasted.

I'm unable to reproduce this error in Emacs 27 -- the image is not
copied over at all by double-clicking it.  Instead I get the first
"word" of the image selected, so it works as if the image wasn't there
at all.

Even killing and yanking text with images won't copy over the image,
which seems pretty odd, but was introduced by the patch below.

I can understand removing the image when the text changes, but removing
it when yanking the text seems odd...

Anyway, I agree that double-clicking the image should probably copy the
entire text under the image, which requires changing what the
double-mouse-1 action is in iimage-mode buffers, I guess?
`C-h k double-mouse-1' didn't say what the command is, though.

commit 277e67418184c2e7d75ac317da095880c981ccd9
Author: Martin Pohlack <[email-masked]>
Date:   Mon Jun 7 17:01:23 2010 -0400

    * lisp/iimage.el: Remove images as soon as the underlying text is modified.
    (iimage-modification-hook): New function.
    (iimage-mode-buffer): Use it.

(defun iimage-modification-hook (beg end)
  "Remove display property if a display region is modified."
  ;;(debug-print "ii1 begin %d, end %d\n" beg end)
  (let ((inhibit-modification-hooks t)
        (beg (previous-single-property-change end 'display
                                              nil (line-beginning-position)))
        (end (next-single-property-change     beg 'display
                                              nil (line-end-position))))
    (when (and beg end (plist-get (text-properties-at beg) 'display))
      ;;(debug-print "ii2 begin %d, end %d\n" beg end)
      (remove-text-properties beg end
                              '(display nil modification-hooks nil)))))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no