jaor/geiser — pull request #1 by gcr (2012-08-12 22:55:23+00:00)
Title: Show images in Racket's REPL

This patch adds support for displaying ([convertible?](http://docs.racket-lang.org/file/convertible.html?q=file/convertible)) values as images right in the Geiser REPL.

This is still pretty rough, so feedback welcome!

![Screenshot](http://i.imgur.com/lxeV8.png)

This works for many types:
- Bitmaps

```scheme
(require racket/draw)
(make-object bitmap% "filename.png")
```
- Picts

```scheme
(require slideshow/pict)
(disk 100)
```

- Plots

```scheme
#lang racket
(require plot)
(plot (function sin 0 pi))
```

- Any `convertible?` object

Implementation
------------------
From the racket side, a custom `current-print` handler determines whether evaluated values are `convertible?` and, if so, prints them like: `#`

From the Geiser side, a comint output hook:

- Scans for lines containing that regexp
- Parses the filename
- Loads the given image into memory
- Deletes the temporary image from disk
- Displays the image in the REPL

For non-TTY emacs users, geiser remembers the previously seen image. You can invoke the system image viewer on a temporary image with M-x `geiser-view-last-image`.

Settings and commands
--------
- `geiser-repl-inline-images`: If t, displays inline images
- `geiser-system-image-viewer`: Which program to invoke (default: "display", from the imagemagick package)
- `M-x geiser-view-last-image`: Writes the last seen image's contents to a temporary file, runs `geiser-system-image-viewer`, and registers a sentinel that deletes the temp file when the user exits the viewer.

Patch shortcomings:
-----------------------------
- My elisp isn't great; beware of bugs!
- There's no documentation
- `geiser-eval` and friends don't display temporary images; this only affects the REPL
- The following should work but doesn't because the "outermost" returned value is not convertible to a picture:

```scheme
#lang racket
(require slideshow/pict)
(list (disk 10) (disk 20) (disk 30))
```

- Right now, emacs keeps the last displayed image data in memory so it can create a new temporary file to invoke external viewers. This may cause problematic memory usage.
- Untested on anything but Linux

Feedback is more than welcome.

Horray for Geiser!