[slime-devel] wishlist feature: swank:make-emacs-buffer-stream

It would be pretty cool to do something like this: (with-open-stream (str (swank:make-emacs-buffer-stream "*app-logger*")) (princ "Woot!")) I'm thinking things like test-report streams, log streams etc. Does swank already have something like this? -- Nathan Bird nathan@acceleration.net http://www.acceleration.net/ Custom Programming, Design, Hosting, and Broadband.

On Feb 3, 2010, at 16:42 , Nathan Bird wrote:
It would be pretty cool to do something like this: (with-open-stream (str (swank:make-emacs-buffer-stream "*app-logger*")) (princ "Woot!"))
I'm thinking things like test-report streams, log streams etc.
Does swank already have something like this?
Quite some time ago, I toyed around with an implementation of buffer streams (actually, with two implementations, but the files matching *2.* seem very incomplete, that's likely where I got distracted). AFAICT, the code implements input-streams, and you want output-streams, but that should not be that much of a problem anymore to add. I have no idea about the status of the code (attached), but perhaps it gives you some ideas. To be put in contrib/, I guess. Feel free to do whatever with the code. -- Cheers, Michael

* Nathan Bird <4B699950.6080504@acceleration.net> : Wrote on Wed, 03 Feb 2010 10:42:08 -0500: | It would be pretty cool to do something like this: | (with-open-stream (str (swank:make-emacs-buffer-stream "*app-logger*")) | (princ "Woot!")) | | I'm thinking things like test-report streams, log streams etc. | | Does swank already have something like this? [Michael Weber gave you a better "correct" answer, but you should be aware of what slime already provides:] First, ;; In Emacs if you: (setq slime-enable-evaluate-in-emacs t) ;; Then in lisp you can define: (defun append-to-buffer (string buffer-name) (swank::eval-in-emacs `(progn (with-current-buffer (get-buffer-create ,buffer-name) (insert ,string))))) ;; so (append-to-buffer "foo\n" "*app-logger*") will write `foo' to a ;; buffer called *app-logger*. Next, If this is not sufficient, and you want a "REAL output stream, you can use the SWANK portablitly layer to open a socket connection to lisp, and have lisp write to the associated emacs buffer. Wrapped up in one function, it may look like this: (defun swank-make-emacs-output-stream (port buffer-name) (let (socket) (unwind-protect (progn (setq socket (swank-backend:create-socket swank::*loopback-interface* port)) (swank::eval-in-emacs `(progn (open-network-stream "Lisp output buffer" ,buffer-name ,swank::*loopback-interface* ,port) nil)) ; SLIME BUG: else invalid protocol message ;; return a stream (swank-backend:accept-connection socket :external-format (swank-backend::find-external-format "iso-latin-1"))) (when socket (swank-backend:close-socket socket))))) ;; Then your example would look like (with-open-stream (stream (swank-make-emacs-output-stream 7008 "*foo*")) (write-line "Woot!" stream )) ;; And this would print "Woot" in a buffer called "*foo*" in emacs ;; This is a rough sketch, and could be cleaned up. -- Madhu

On Wed, Feb 3, 2010 at 7:42 AM, Nathan Bird <nathan@acceleration.net> wrote:
It would be pretty cool to do something like this: (with-open-stream (str (swank:make-emacs-buffer-stream "*app-logger*")) (princ "Woot!"))
I'm thinking things like test-report streams, log streams etc.
Does swank already have something like this?
Yes, see the implementation of slime-redirect-trace-output and swank:redirect-trace-output. (However, the Emacs side needs to set up the connection between a buffer (actually a marker) and a :write-string target.) We should probably export the function swank::make-output-stream-for-target. Matthias -- Matthias Koeppe -- http://www.math.ucdavis.edu/~mkoeppe
participants (4)
-
Madhu
-
Matthias Koeppe
-
Michael Weber
-
Nathan Bird