summaryrefslogtreecommitdiff
path: root/elisp/geiser-image.el
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2012-09-02 20:19:36 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2012-09-02 20:19:36 +0200
commit8f2e4ba17b704965f3a35d1d0a312dec31800862 (patch)
treef77861b30ff1a031292eed0104d195559fcc99cd /elisp/geiser-image.el
parentb05120e5872382528c73416046d4e19cdb1bc88f (diff)
downloadgeiser-chez-8f2e4ba17b704965f3a35d1d0a312dec31800862.tar.gz
geiser-chez-8f2e4ba17b704965f3a35d1d0a312dec31800862.tar.bz2
racket: displaying images also during evaluations
Diffstat (limited to 'elisp/geiser-image.el')
-rw-r--r--elisp/geiser-image.el46
1 files changed, 25 insertions, 21 deletions
diff --git a/elisp/geiser-image.el b/elisp/geiser-image.el
index 6b77ff3..f194e04 100644
--- a/elisp/geiser-image.el
+++ b/elisp/geiser-image.el
@@ -77,29 +77,33 @@ images in `geiser-image-cache-dir'."
'action 'geiser-image--button-action
'follow-link t)
+(defun geiser-image--insert-button (file)
+ (insert-text-button "[image]"
+ :type 'geiser-image--button
+ 'face 'geiser-font-lock-image-button
+ 'geiser-image-file file
+ 'help-echo "Click to display image"))
+
(defun geiser-image--replace-images (inline-images-p auto-p)
"Replace all image patterns with actual images"
- (with-silent-modifications
- (save-excursion
- (goto-char (point-min))
- (while (re-search-forward "#<Image: \\([-+./_0-9a-zA-Z]+\\)>" nil t)
- ;; can't pass a filename to create-image because emacs might
- ;; not display it before it gets deleted (race condition)
- (let* ((file (match-string 1))
- (begin (match-beginning 0))
- (end (match-end 0)))
- (delete-region begin end)
- (if (and inline-images-p (display-images-p))
- (put-image (create-image file) begin "[image]")
- (goto-char begin)
- (insert-text-button "[image]"
- :type 'geiser-image--button
- 'face 'geiser-font-lock-image-button
- 'geiser-image-file file
- 'help-echo "Click to display image")
- (when auto-p (geiser-image--display file)))
- (setq geiser-image-cache-dir (file-name-directory file))
- (geiser-image--clean-cache))))))
+ (let ((seen 0))
+ (with-silent-modifications
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "\"?#<Image: \\([-+./_0-9a-zA-Z]+\\)>\"?" nil t)
+ (setq seen (+ 1 seen))
+ (let* ((file (match-string 1))
+ (begin (match-beginning 0))
+ (end (match-end 0)))
+ (delete-region begin end)
+ (if (and inline-images-p (display-images-p))
+ (put-image (create-image file) begin "[image]")
+ (goto-char begin)
+ (geiser-image--insert-button file)
+ (when auto-p (geiser-image--display file)))
+ (setq geiser-image-cache-dir (file-name-directory file))
+ (geiser-image--clean-cache)))))
+ seen))
(defun geiser-view-last-image (n)
"Open the last displayed image in the system's image viewer.