From cc15e31fb57e32d5498681a1d97d6c74bcdaf0bc Mon Sep 17 00:00:00 2001 From: Michael W Date: Sun, 12 Aug 2012 15:12:56 -0600 Subject: [PATCH] [WIP] Emacs cleans up temp. images, and a parameter controls whether or not they are displayed in the REPL. --- elisp/geiser-repl.el | 29 +++++++++++++++++++++++++---- 1 file 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 "#" 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))) -- 2.11.4.GIT