Subject: bug#5980: closed (Re: bug#5980: iimage.el and modification hooks)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 07 Jun 2010 21:07:02 +0000

Your bug report

#5980: iimage.el and modification hooks

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
5980: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=5980
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#5980: iimage.el and modification hooks
From: Stefan Monnier <[email-masked]>
To: Martin Pohlack <[email-masked]>
Date: Mon, 07 Jun 2010 17:03:40 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

> I started to use iimage.el yesterday and like it.  However, it still
> seems possible to *blindly* modify contents inside the display blocks
> which is confusing.  Furthermore, if the regexp defining the block is
> destroyed that way, disabling iimage-mode does not remove the display
> block --- it will be stuck forever.

Installed, thank you,

        Stefan

Subject: iimage.el and modification hooks
From: Martin Pohlack <[email-masked]>
To: [email-masked]
Date: Tue, 20 Apr 2010 09:41:51 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

I started to use iimage.el yesterday and like it.  However, it still
seems possible to *blindly* modify contents inside the display blocks
which is confusing.  Furthermore, if the regexp defining the block is 
destroyed that way, disabling iimage-mode does not remove the display 
block --- it will be stuck forever.

I therefore use a modification hook for removing the display block in
case the underlying text is modified.  Please find the patch attached, 
in case you like it.

Cheers,
Martin Pohlack
--- /home/mp26/src/emacs/lisp/iimage.el	2009-11-21 12:03:13.000000000 +0100
+++ iimage.el	2010-04-18 23:24:10.000000000 +0200
@@ -109,6 +109,19 @@
 
 (defalias 'iimage-locate-file 'locate-file)
 
+(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)))))
+
 (defun iimage-mode-buffer (arg)
 "Display/undisplay images.
 With numeric ARG, display the images if and only if ARG is positive."
@@ -128,9 +141,12 @@
 					 iimage-mode-image-search-path))))
 	      (if ing
 		  (add-text-properties (match-beginning 0) (match-end 0)
-				       (list 'display (create-image file)))
-		(remove-text-properties (match-beginning 0) (match-end 0)
-					'(display)))))))
+				       (list 'display (create-image file)
+                                             'modification-hooks
+                                             (list 'iimage-modification-hook)))
+		(remove-list-of-text-properties
+                 (match-beginning 0) (match-end 0)
+                 '(display modification-hooks)))))))
     (set-buffer-modified-p modp)))
 
 ;;;###autoload