; comminicating with emacs (gnuserv) using unix sockets.. ; see info guile, node: Network Sockets and Communications ; this only works with hacked up gnuserv (use-modules (ice-9 rdelim)) ;; returns port for reading (define (gnuclient object) (let ((s (socket AF_UNIX SOCK_STREAM 0))) (connect s AF_UNIX "/tmp/gsrvdir1000/gsrv") (write object s) ; send object (display #\eot s) ; send ctrl-D s)) ;; slurp whole input.. better to use read if possible (define (gnuclient-slurp object) (read-delimited "" (gnuclient object))) (define (gnuclient-read object) (let ((text (gnuclient-slurp object))) ;; read whole text (catch 'misc-error (lambda () (with-input-from-string text (lambda () (read)))) ;; then read from string (lambda dummy (throw 'gnuclient-read-error text))))) ;; this uses pp-to-string: gnuserv-eval does not quote strings. (define (gnuclient-eval object) (gnuclient-read `(gnuserv-write-eval ',object))) ;; works only with hacked up gnuserv (define (gnuclient-edit string) (catch 'read-error (lambda () (gnuclient-read `(gnuserv-async-edit ,string))) (lambda dummy string))) ;; return orig string if something goes wrong ;; an emacs repl (define (gnuclient-repl) (setvbuf (current-output-port) _IONBF) ;; so we can attach non-tty (let next () (let ((expr (read))) (if (not (eof-object? expr)) (begin (write (gnuclient-eval expr)) (newline) (next)))))) ;; (load "gnuclient.scm") ;; (gnuclient-eval '(+ 1 2)) ;; (gnuclient-edit "shmashma") ;; need this