[slime-devel] Is there an easy way to open an output stream in lisp that goes to a slime buffer?

Helmut Eller e9626484 at stud3.tuwien.ac.at
Fri Sep 17 18:26:35 UTC 2004


Peter Seibel <peter at javamonkey.com> writes:

> Clearly there's some machinery in SLIME for creating streams that are
> actually connected to sockets that communicate with emacs.

The current implementation of the streams with extra sockets is
primarily an efficiency hack and not easily reusable.  Currently the
Emacs side has doesn't know much about streams and just inserts the
output in the REPL buffer.

> My question
> is there an easy way to, on the Common Lisp side, open a stream such
> that a new buffer is created in emacs and all data sent to the stream
> will end up in that buffer? 

No, there's no easy way. A hacky way is this: 

   (in-package :swank)
   
   (defun make-log-stream ()
     (make-fn-streams (lambda () (error "Not implemented"))
                      (lambda (string) 
                        (send-oob-to-emacs
                         `(:%apply "message" ("%s" ,string))))))
   
   
   (setq s (nth-value 1 (make-log-stream)))
   (format s "hello, world!~%")
   (finish-output s)

This calls Emacs' message with the output of the stream (and message
inserts the output in the *Messages* buffer).  If you want to insert
in an other buffer you could write the your own Emacs Lisp code to do
the job.  Note that this stream is fully buffered and finish-output is
necessary if you have short messages.

Helmut.




More information about the slime-devel mailing list