summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael W <gcr@sneakygcr.net>2012-08-12 15:12:56 -0600
committerMichael W <gcr@sneakygcr.net>2012-08-12 15:12:56 -0600
commitcc15e31fb57e32d5498681a1d97d6c74bcdaf0bc (patch)
tree96b8eec8fba20d554e6490f4551285b6156e7898
parent998e709f65a8bd9acfd1917d0ac4aaa47f67030b (diff)
downloadgeiser-chez-cc15e31fb57e32d5498681a1d97d6c74bcdaf0bc.tar.gz
geiser-chez-cc15e31fb57e32d5498681a1d97d6c74bcdaf0bc.tar.bz2
[WIP] Emacs cleans up temp. images, and a parameter controls whether or not they are displayed in the REPL.
-rw-r--r--elisp/geiser-repl.el29
1 files changed, 25 insertions, 4 deletions
diff --git a/elisp/geiser-repl.el b/elisp/geiser-repl.el
index 05d4775..05bb584 100644
--- a/elisp/geiser-repl.el
+++ b/elisp/geiser-repl.el
@@ -113,6 +113,11 @@ If you have a slow system, try to increase this time."
:type 'integer
:group 'geiser-repl)
+(geiser-custom--defcustom geiser-repl-inline-images t
+ "Whether to display inline images in the REPL"
+ :type 'boolean
+ :group 'geiser-repl)
+
(geiser-custom--defface repl-input
'comint-highlight-input geiser-repl "evaluated input highlighting")
@@ -272,13 +277,29 @@ module command as a string")
(save-excursion
(goto-char (point-min))
(while (re-search-forward "#<Image: \\([-+./_0-9a-zA-Z]+\\)>" nil t)
- (let ((file (match-string 1)))
- (replace-match "")
- (insert-image (create-image file) "[image]"))))))
+ ;; 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))
+ (imgdata (save-excursion
+ (with-temp-buffer
+ (set-buffer-multibyte nil)
+ (insert-file-contents-literally file nil)
+ (buffer-string)))))
+ (delete-region begin end)
+ (put-image (create-image imgdata nil t) begin "[image]")
+ (delete-file file)
+ ; XXX need to ensure that the file is in the temporary
+ ; folder before deleting it. Racket will only generate files
+ ; in the system temporary folder (/var/tmp), but we don't
+ ; know what the temp. folder is, especially on Windows
+ )))))
(defun geiser-repl--output-filter (txt)
(geiser-con--connection-update-debugging geiser-repl--connection txt)
- (geiser-repl--replace-images)
+ (when (and geiser-repl-inline-images (display-images-p))
+ (geiser-repl--replace-images))
(when (string-match-p (geiser-con--connection-prompt geiser-repl--connection)
txt)
(geiser-autodoc--disinhibit-autodoc)))