unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#5980: iimage.el and modification hooks
@ 2010-04-20  7:41 Martin Pohlack
  2010-06-07 21:03 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Pohlack @ 2010-04-20  7:41 UTC (permalink / raw)
  To: 5980

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

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

[-- Attachment #2: iimage_modification-hooks.diff --]
[-- Type: text/x-patch, Size: 1700 bytes --]

--- /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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#5980: iimage.el and modification hooks
  2010-04-20  7:41 bug#5980: iimage.el and modification hooks Martin Pohlack
@ 2010-06-07 21:03 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2010-06-07 21:03 UTC (permalink / raw)
  To: Martin Pohlack

> 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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-06-07 21:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-20  7:41 bug#5980: iimage.el and modification hooks Martin Pohlack
2010-06-07 21:03 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).