[slime-devel] Re: Pictures in the REPL -- Big Dirty hack
Ariel Badichi
abadichi at bezeqint.net
Wed May 7 13:29:25 UTC 2008
"Patrick Collison" <patrick at collison.ie> writes:
> I wanted to be able to display images in my SLIME repl, so that I
> could do stuff like http://collison.ie/img/google-charts.png. I played
> around with swank.lisp and slime.el for an hour, and hacked together
> something that mostly works. The code is ugly as sin, but I'm posting
> it here in case anyone wants to similarly subvert their SLIME
> installation. If there's any interest in having this be a part of the
> SLIME distribution, I'm happy to look at cleaning it up...
>
I, too, hacked something like that not long ago:
http://common-lisp.net/pipermail/slime-devel/2008-April/007264.html
A few days later I mutilated it to be a slime contrib (but still
requiring the SLIME-REPL-EMIT change), which follows (don't ask about
the license :). Because it receives a filename to display, it is more
low-level than your interface. It's easy then to write a simple CL
function to fetch and display and image (say, using Drakma).
(It's a git diff, I use the git://github.com/nablaone/slime mirror.)
Ariel
---
commit eaeac5d2067f561ec478d3946b6fcdea8018bebc
Author: Ariel Badichi <abadichi at bezeqint.net>
Date: Fri Apr 18 04:17:22 2008 +0300
Added slime-image contrib.
diff --git a/contrib/slime-image.el b/contrib/slime-image.el
new file mode 100644
index 0000000..83f1f46
--- /dev/null
+++ b/contrib/slime-image.el
@@ -0,0 +1,17 @@
+;;; slime-image.el --- Insert images into the REPL
+;;
+;; Author: Ariel Badichi <abadichi at bezeqint.net>
+;;
+;; License: fuck-knows
+;;
+;;; Installation
+;;
+;; Add slime-image to your slime-setup call.
+
+(defun slime-image-init ()
+ (add-hook 'slime-connected-hook 'slime-image-install))
+
+(defun slime-image-install ()
+ (slime-eval-async '(swank:swank-require :swank-image)))
+
+(provide 'slime-image)
diff --git a/contrib/swank-image.lisp b/contrib/swank-image.lisp
new file mode 100644
index 0000000..6b58c32
--- /dev/null
+++ b/contrib/swank-image.lisp
@@ -0,0 +1,18 @@
+(in-package #:swank)
+
+(defslimefun insert-image-into-repl (filename &optional (error t))
+ "Insert the image in the file denoted by FILENAME into the REPL
+buffer and return true. If the file does not exist, then either error
+if ERROR is true, or return false otherwise."
+ (let ((probe (probe-file filename)))
+ (cond (probe
+ (eval-in-emacs
+ `(progn
+ (slime-repl-emit
+ (lambda ()
+ (insert-image (create-image ,(namestring probe)))
+ (insert #\Newline)))
+ :ok))
+ t)
+ (error (error "A file named ~S does not exist." filename))
+ (t nil))))
diff --git a/slime.el b/slime.el
index ceba26a..de1cd3c 100644
--- a/slime.el
+++ b/slime.el
@@ -2555,13 +2555,17 @@ hashtable `slime-output-target-to-marker'; output is inserted at this marker."
(:repl-result (slime-repl-emit-result string))
(t (slime-emit-string string target))))
-(defun slime-repl-emit (string)
- ;; insert the string STRING in the output buffer
+(defun slime-repl-emit (thing)
+ "Insert THING into the output buffer if it is a string or, if
+it is a function, call it in the right context for insertion."
(with-current-buffer (slime-output-buffer)
(slime-with-output-end-mark
- (slime-insert-propertized '(face slime-repl-output-face
- rear-nonsticky (face))
- string)
+ (etypecase thing
+ (string
+ (slime-insert-propertized '(face slime-repl-output-face
+ rear-nonsticky (face))
+ thing))
+ (function (funcall thing)))
(set-marker slime-output-end (point))
(when (and (= (point) slime-repl-prompt-start-mark)
(not (bolp)))
diff --git a/swank-loader.lisp b/swank-loader.lisp
index 490d149..0431442 100644
--- a/swank-loader.lisp
+++ b/swank-loader.lisp
@@ -185,6 +185,7 @@ If LOAD is true, load the fasl file."
swank-fancy-inspector
swank-presentations swank-presentation-streams
#+(or asdf sbcl) swank-asdf
+ swank-image
)
"List of names for contrib modules.")
More information about the slime-devel
mailing list