swank

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	VerboseWire     bool
	VerboseDispatch bool
	VerboseEval     bool
	LogOutput       io.Writer = os.Stdout
)

Verbose flags for debugging output

View Source
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

func LogDispatch(handler string, args slip.List)

LogDispatch logs handler dispatch if VerboseDispatch is enabled.

func LogError

func LogError(format string, args ...any)

LogError logs errors.

func LogEval

func LogEval(expr slip.Object, result slip.Object)

LogEval logs evaluation if VerboseEval is enabled.

func LogWire

func LogWire(direction string, msg slip.Object)

LogWire logs wire protocol messages if VerboseWire is enabled. direction should be "<-" for incoming or "->" for outgoing.

func ReadWireMessage

func ReadWireMessage(r io.Reader, scope *slip.Scope) (obj slip.Object, err error)

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

func RegisterHandler(name string, h Handler)

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.

func WriteWireMessage

func WriteWireMessage(w io.Writer, msg slip.Object) error

WriteWireMessage writes a length-prefixed S-expression to the writer.

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) Close

func (c *Connection) Close()

Close closes the connection.

func (*Connection) NewPackage

func (c *Connection) NewPackage(name, prompt string)

NewPackage sends a :new-package message to SLIME.

func (*Connection) Run

func (c *Connection) Run()

Run starts the connection read loop.

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

type CreateServer struct {
	slip.Function
}

CreateServer represents the create-server function.

func (*CreateServer) Call

func (f *CreateServer) Call(s *slip.Scope, args slip.List, depth int) slip.Object

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

func GetHandler(name string) Handler

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.

func NewInspector

func NewInspector() *Inspector

NewInspector creates a new inspector instance.

type RestartServer

type RestartServer struct {
	slip.Function
}

RestartServer represents the restart-server function.

func (*RestartServer) Call

func (f *RestartServer) Call(s *slip.Scope, args slip.List, depth int) slip.Object

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server manages Swank connections for SLIME integration.

func NewServer

func NewServer(scope *slip.Scope) *Server

NewServer creates a new Swank server with the given base scope. Each connection will get a child scope of this base scope.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the address the server is listening on.

func (*Server) Running

func (s *Server) Running() bool

Running returns true if the server is accepting connections.

func (*Server) Start

func (s *Server) Start(address string) error

Start begins listening for connections on the specified address. The address should be in the form "host:port" or ":port".

func (*Server) Stop

func (s *Server) Stop() error

Stop shuts down the server and closes all connections.

type SetupServer

type SetupServer struct {
	slip.Function
}

SetupServer represents the setup-server function.

func (*SetupServer) Call

func (f *SetupServer) Call(s *slip.Scope, args slip.List, depth int) slip.Object

type StartServer

type StartServer struct {
	slip.Function
}

StartServer represents the start-server function.

func (*StartServer) Call

func (f *StartServer) Call(s *slip.Scope, args slip.List, depth int) slip.Object

type StopServer

type StopServer struct {
	slip.Function
}

StopServer represents the stop-server function.

func (*StopServer) Call

func (f *StopServer) Call(s *slip.Scope, args slip.List, depth int) slip.Object

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) Eval

func (s *SwankOutputStream) Eval(scope *slip.Scope, depth int) slip.Object

Eval 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.

func (*SwankOutputStream) Write

func (s *SwankOutputStream) Write(p []byte) (n int, err error)

Write implements io.Writer. It buffers the output.

type SwankServer

type SwankServer struct {
	slip.Function
}

SwankServer represents the swank-server function.

func (*SwankServer) Call

func (f *SwankServer) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call starts the Swank server.

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) Equal

func (s *SwankServerInstance) Equal(other slip.Object) bool

func (*SwankServerInstance) Eval

func (s *SwankServerInstance) Eval(scope *slip.Scope, depth int) slip.Object

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

type SwankStop

type SwankStop struct {
	slip.Function
}

SwankStop represents the swank-stop function.

func (*SwankStop) Call

func (f *SwankStop) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call stops the default Swank server.

type SwankVerbose

type SwankVerbose struct {
	slip.Function
}

SwankVerbose represents the swank-verbose function.

func (*SwankVerbose) Call

func (f *SwankVerbose) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call implements the swank-verbose function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL