Prolog talks to GNU Emacs by writing a sequence of one or more Emacs-Lisp function calls (including the parentheses) to the standard output stream, where this sequence is delimited by two special character codes. When GNU Emacs detects one of these delimited "packets" (as they are referred to in the Emacs-Lisp code) being written, it executes the function calls that occur between the delimiters. The packet start character is ASCII 30 and the packet end character is ASCII 29.
As an example, define and call the predicate
to_emacs :- put(30), write('(message "hello") (sit-for 50)'), put(29).
WARNING: Attempting to debug or interrupt (with ^c ^c) this predicate, thus submitting only a partial packet to GNU Emacs, will cause subsequent output to be considered as a continuation of the current packet and disaster will ensue. If such a situation occurs, try typing the command
put(29).to terminate the packet. You may want to consider using a critical region to prevent this problem, see
library(critical)
.
You will notice that after the message (hello
) is printed out in the
message buffer (also called the minibuffer in GNU Emacs literature)
and the "sit-for" period expires, it then disappears. This is a
side-effect of the design of the GNU Emacs interface. Any Emacs-Lisp
function that is called by Prolog should display messages using the
function
(&qp-message message-string)
where message-string must be a single string (this is unlike
message
, which can take multiple strings; use the Emacs-Lisp
function concat
to make a single string out of multiple strings).
This string will be displayed in the message buffer after GNU Emacs
has processed the current "packet" from Prolog. Therefore, if you
redefine the predicate as
to_emacs :- put(30), write('(&qp-message "hello")'), put(29).
and reinvoke it, you will find that the message remains in the message buffer.