Slime is an Emacs mode for Common Lisp development. One of its features is to connect to a remote Lisp process, which is very useful for debugging. I often had the problem to mistake one REPL for another, running some code on the wrong Lisp process.
I finally configured the
slime-banner package, which displays a line at the top of the REPL buffer, and made it shows the hostname of the machine the Lisp process is running on.
(eval-after-load 'slime '(progn (slime-setup '(slime-repl 'slime-banner)) (slime-banner-init) (setq slime-repl-banner-function (lambda () (setq header-line-format (format "%s@%s:%d" (slime-lisp-implementation-type) (slime-eval '(cl:machine-instance)) (process-contact (slime-connection) :service))))))
'slime-banner to the list of packages to load with slime, then initialize it with
slime-banner calls a function which sets the
header-line-format variable. We then use
slime-lisp-implementation-type to get the name of the Common Lisp implementation (such as
read the port used by the process associated to the current slime connection. Getting the hostname of the remote machine is a bit more tricky, since we need to evaluate some code on this remote machine. We use
slime-port to get the port number of the swank server we are connected to
slime-eval to execute a Common Lisp form on the remote machine. The standard function
cl:machine-instance returns the hostname of the machine.
2012-03-24: the code has been modified to correctly display the port.
slime-port is the default value used by
slime-connect, not the port used by the current connection. The correct way is to get the emacs process associated with the connection, and read the port (
:service) it uses.