-"Display/undisplay images.
-With numeric ARG, display the images if and only if ARG is positive."
- (interactive)
- (let ((ing (if (numberp arg)
- (> arg 0)
- iimage-mode))
- (modp (buffer-modified-p (current-buffer)))
- file buffer-read-only)
- (save-excursion
- (goto-char (point-min))
- (dolist (pair iimage-mode-image-regex-alist)
- (while (re-search-forward (car pair) nil t)
- (if (and (setq file (match-string (cdr pair)))
- (setq file (iimage-locate-file file
- (cons default-directory
- 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)))))))
- (set-buffer-modified-p modp)))
+ "Display images if ARG is non-nil, undisplay them otherwise."
+ (let ((image-path (cons default-directory iimage-mode-image-search-path))
+ file)
+ (with-silent-modifications
+ (save-excursion
+ (goto-char (point-min))
+ (dolist (pair iimage-mode-image-regex-alist)
+ (while (re-search-forward (car pair) nil t)
+ (when (and (setq file (match-string (cdr pair)))
+ (setq file (locate-file file image-path)))
+ ;; FIXME: we don't mark our images, so we can't reliably
+ ;; remove them either (we may leave some of ours, and we
+ ;; may remove other packages's display properties).
+ (if arg
+ (add-text-properties (match-beginning 0) (match-end 0)
+ `(display ,(create-image file)
+ modification-hooks
+ (iimage-modification-hook)))
+ (remove-text-properties (match-beginning 0) (match-end 0)
+ '(display modification-hooks))))))))))