Documentation
¶
Overview ¶
Package swank implements a Swank server for SLIME integration.
Swank is the protocol used by SLIME (Superior Lisp Interaction Mode for Emacs) to communicate with Lisp implementations. This package provides a server that allows SLIP to be used interactively from Emacs.
Starting the Server ¶
From SLIP:
(swank-server :port 4005)
Or from Go:
server := swank.NewServer(scope)
server.Start(":4005")
Connecting from Emacs ¶
Once the server is running, connect from Emacs with:
M-x slime-connect RET localhost RET 4005 RET
Protocol ¶
The Swank wire protocol uses length-prefixed S-expressions:
- 6 ASCII hex characters encoding the payload length
- UTF-8 encoded S-expression payload
Messages are either RPC requests (:emacs-rex) from SLIME or responses/events from the server (:return, :write-string, :new-package, etc.).
Index ¶
- Variables
- func ListHandlers() []string
- func LogDispatch(handler string, args slip.List)
- func LogError(format string, args ...any)
- func LogEval(expr slip.Object, result slip.Object)
- func LogWire(direction string, msg slip.Object)
- func ReadWireMessage(r io.Reader, scope *slip.Scope) (obj slip.Object, err error)
- func RegisterHandler(name string, h Handler)
- func WriteWireMessage(w io.Writer, msg slip.Object) error
- type Connection
- func (c *Connection) Close()
- func (c *Connection) NewPackage(name, prompt string)
- func (c *Connection) Run()
- func (c *Connection) Send(msg slip.Object) error
- func (c *Connection) UpdateHistory(value, form slip.Object)
- func (c *Connection) WriteResult(text string)
- func (c *Connection) WriteString(text string)
- type CreateServer
- type Handler
- type Inspector
- type RestartServer
- type Server
- type SetupServer
- type StartServer
- type StopServer
- type SwankOutputStream
- func (s *SwankOutputStream) Append(b []byte) []byte
- func (s *SwankOutputStream) Close() error
- func (s *SwankOutputStream) Equal(other slip.Object) bool
- func (s *SwankOutputStream) Eval(scope *slip.Scope, depth int) slip.Object
- func (s *SwankOutputStream) Flush() string
- func (s *SwankOutputStream) FlushToSlime()
- func (s *SwankOutputStream) Hierarchy() []slip.Symbol
- func (s *SwankOutputStream) IsOpen() bool
- func (s *SwankOutputStream) LastByte() byte
- func (s *SwankOutputStream) Simplify() any
- func (s *SwankOutputStream) String() string
- func (s *SwankOutputStream) Write(p []byte) (n int, err error)
- type SwankServer
- type SwankServerInstance
- func (s *SwankServerInstance) Addr() string
- func (s *SwankServerInstance) Append(b []byte) []byte
- func (s *SwankServerInstance) Equal(other slip.Object) bool
- func (s *SwankServerInstance) Eval(scope *slip.Scope, depth int) slip.Object
- func (s *SwankServerInstance) Hierarchy() []slip.Symbol
- func (s *SwankServerInstance) Simplify() any
- func (s *SwankServerInstance) String() string
- type SwankStop
- type SwankVerbose
Constants ¶
This section is empty.
Variables ¶
var ( VerboseWire bool VerboseDispatch bool VerboseEval bool LogOutput io.Writer = os.Stdout )
Verbose flags for debugging output
var ( // Pkg is the swank package. Pkg = slip.Package{ Name: "swank", Nicknames: []string{}, Doc: `Home of symbols defined for the swank package. This package implements a Swank server for SLIME (Superior Lisp Interaction Mode for Emacs) integration, enabling interactive Lisp development from Emacs.`, PreSet: slip.DefaultPreSet, } )
Functions ¶
func ListHandlers ¶
func ListHandlers() []string
ListHandlers returns a list of all registered handler names.
func LogDispatch ¶
LogDispatch logs handler dispatch if VerboseDispatch is enabled.
func LogWire ¶
LogWire logs wire protocol messages if VerboseWire is enabled. direction should be "<-" for incoming or "->" for outgoing.
func ReadWireMessage ¶
ReadWireMessage reads a length-prefixed S-expression from the reader. The Swank wire format is: 6 ASCII hex characters (length) + UTF-8 payload.
func RegisterHandler ¶
RegisterHandler registers an RPC handler for the given name. Handler names are case-insensitive and can be in either "swank:function-name" or "function-name" format.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents a single SLIME connection.
func NewConnection ¶
func NewConnection(id int64, conn net.Conn, server *Server) *Connection
NewConnection creates a connection for an accepted socket.
func (*Connection) NewPackage ¶
func (c *Connection) NewPackage(name, prompt string)
NewPackage sends a :new-package message to SLIME.
func (*Connection) Send ¶
func (c *Connection) Send(msg slip.Object) error
Send writes a message to the connection.
func (*Connection) UpdateHistory ¶
func (c *Connection) UpdateHistory(value, form slip.Object)
UpdateHistory updates the REPL history variables.
func (*Connection) WriteResult ¶
func (c *Connection) WriteResult(text string)
WriteResult sends a :write-string message with :repl-result flag.
func (*Connection) WriteString ¶
func (c *Connection) WriteString(text string)
WriteString sends a :write-string message to SLIME.
type CreateServer ¶
CreateServer represents the create-server function.
type Handler ¶
type Handler func(c *Connection, args slip.List) slip.Object
Handler is a function that handles an RPC call from SLIME. It receives the connection and the arguments from the RPC form.
func GetHandler ¶
GetHandler returns the handler for the given name, or nil if not found.
type Inspector ¶
type Inspector struct {
// contains filtered or unexported fields
}
Inspector holds the state for object inspection.
type RestartServer ¶
RestartServer represents the restart-server function.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server manages Swank connections for SLIME integration.
func NewServer ¶
NewServer creates a new Swank server with the given base scope. Each connection will get a child scope of this base scope.
type SetupServer ¶
SetupServer represents the setup-server function.
type StartServer ¶
StartServer represents the start-server function.
type StopServer ¶
StopServer represents the stop-server function.
type SwankOutputStream ¶
type SwankOutputStream struct {
// contains filtered or unexported fields
}
SwankOutputStream captures output and forwards it to SLIME via :write-string. It implements io.Writer and slip.Object so it can be bound to *standard-output*.
func NewSwankOutputStream ¶
func NewSwankOutputStream(conn *Connection) *SwankOutputStream
NewSwankOutputStream creates a new output stream for the connection.
func (*SwankOutputStream) Append ¶
func (s *SwankOutputStream) Append(b []byte) []byte
Append implements slip.Object.
func (*SwankOutputStream) Close ¶
func (s *SwankOutputStream) Close() error
Close implements io.Closer.
func (*SwankOutputStream) Equal ¶
func (s *SwankOutputStream) Equal(other slip.Object) bool
Equal implements slip.Object.
func (*SwankOutputStream) Flush ¶
func (s *SwankOutputStream) Flush() string
Flush sends buffered output to SLIME and clears the buffer.
func (*SwankOutputStream) FlushToSlime ¶
func (s *SwankOutputStream) FlushToSlime()
FlushToSlime sends buffered output directly to SLIME.
func (*SwankOutputStream) Hierarchy ¶
func (s *SwankOutputStream) Hierarchy() []slip.Symbol
Hierarchy implements slip.Object.
func (*SwankOutputStream) IsOpen ¶
func (s *SwankOutputStream) IsOpen() bool
IsOpen returns true if the stream is open (connection is active).
func (*SwankOutputStream) LastByte ¶
func (s *SwankOutputStream) LastByte() byte
LastByte returns the last byte written, or 0 if the buffer is empty.
func (*SwankOutputStream) Simplify ¶
func (s *SwankOutputStream) Simplify() any
Simplify implements slip.Object.
func (*SwankOutputStream) String ¶
func (s *SwankOutputStream) String() string
String implements slip.Object.
type SwankServer ¶
SwankServer represents the swank-server function.
type SwankServerInstance ¶
type SwankServerInstance struct {
// contains filtered or unexported fields
}
SwankServerInstance represents a running Swank server.
func (*SwankServerInstance) Addr ¶
func (s *SwankServerInstance) Addr() string
Addr returns the address the underlying server is listening on.
func (*SwankServerInstance) Append ¶
func (s *SwankServerInstance) Append(b []byte) []byte
func (*SwankServerInstance) Hierarchy ¶
func (s *SwankServerInstance) Hierarchy() []slip.Symbol
func (*SwankServerInstance) Simplify ¶
func (s *SwankServerInstance) Simplify() any
func (*SwankServerInstance) String ¶
func (s *SwankServerInstance) String() string