#lang scheme/base ;; This is a redesign of the emacs<->mzscheme communication in snot, ;; using a simpler architecture where mzscheme does most of the logic. ;; Previous design had the following problems: ;; * repl not intelligent enough to understand the different languages used. ;; * differences in elisp <-> scheme syntax ;; * problematic multiplexing of data over a single channel ;; The core idea now is: keep the emacs side dumb. All significant ;; processing should be done in the scheme side, possibly also ;; providing the emacs side with code initializations. (require scheme/system (planet "socket.ss" ("vyzo" "socket.plt" 1 2))) ;; Use emacsclient: it provides message atomicity. (define (elisp str) (system* "/usr/bin/emacsclient" "-e" (format "~s" str))) ;; Scheme message handler. (define (handle in) (display in)) ;; I get errno 71 EPROTO ;; Start server. (define (message-server addr [handler handle]) (let ((sock (socket PF_UNIX SOCK_STREAM 0))) (socket-bind sock addr) (socket-listen sock 5) (let next () (let-values (((clisock cliaddr) (socket-accept sock))) (thread (lambda () (let ((out (open-output-string))) (with-handlers ((void (lambda (ex) (printf "errr: ~a\n" (exn:socket-errno ex))))) (socket-recv/port sock out)) (socket-close sock) (handle (get-output-string out)))))) (next))))