Sweep provides a classic Prolog top-level interface for interacting with the embedded Prolog runtime. To start the top-level, use M-x sweeprolog-top-level RET. This command opens a buffer with an interactive Prolog top-level.
Run an interactive Prolog top-level in a buffer.
sweeprolog-top-level
creates a buffer named
*sweeprolog-top-level*, and connects it to a Prolog top-level.
If the *sweeprolog-top-level* buffer already exists, this
command simply displays the existing buffer. See Multiple Top-levels to learn about using multiple top-level buffers at the
same time.
The top-level buffer uses the Sweep Top-level major mode
(sweeprolog-top-level-mode
). This mode derives from
comint-mode
, which is the common mode used in Emacs
REPL (Read Evaluate Print Loop) interfaces. As a result, the
top-level buffer inherits the features present in other
comint-mode
derivatives, most of which are described in
(emacs)Shell Mode.
Top-level buffers are backed by Prolog threads that run in the same
process as Emacs and the main Prolog runtime. On Unix systems,
top-levels communicate with their corresponding threads via a
pseudo-terminal device (pty). Alternatively, Sweep top-level
buffers can communicate with their threads via a local TCP connection.
You can force Sweep to use TCP instead of a pty on Unix systems by
customizing the user option sweeprolog-top-level-use-pty
to
nil
.
Whether to use pty for top-level communication. If this is
non-nil
, Sweep top-level buffers communicate with their
top-level threads via a pty, otherwise they use a local TCP
connection.
sweeprolog-top-level-use-pty
is on by default on systems where
Emacs can use a pty. On other systems, such as MS Windows, or when
otherwise sweeprolog-top-level-use-pty
is set to nil
,
Sweep creates a TCP server socket bound to a random port to accept
incoming connections from top-level buffers. Sweep only starts this
TCP server socket when you first invoke of
sweeprolog-top-level
, so there are no listening sockets before
you actually use the top-level. The TCP server only accepts
connections from the local machine, but note that other users on the
same host might be able to connect to the TCP server socket and get a
Prolog top-level. This may be a security concern if you are sharing a
host with untrusted users, so you should be careful about using
sweeprolog-top-level
with sweeprolog-top-level-use-pty
set to nil
on shared machines.
When Emacs connects to a top-level via a pty, the top-level uses
ANSI escape sequences to add colored output and other features.
Emacs interprets these escape sequences by default and turns them into
text properties for the top-level output. If you want Emacs to filter
out ANSI escape sequences and disable output coloring, set the user
option ansi-color-for-comint-mode
to the symbol filter
.