sweep_functors_collection/2,
sweep_compound_functors_collection/2,
sweep_term_variable_names/2,
- sweep_goal_may_cut/2
+ sweep_goal_may_cut/2,
+ sweep_top_level_start_pty/2
]).
:- use_module(library(pldoc)).
format('M ~w~n', Path).
:- endif.
+sweep_top_level_start_pty([Name|Buffer], _) :-
+ thread_create(sweep_top_level_pty_client(Name), T, [detached(true)]),
+ thread_property(T, id(Id)),
+ asserta(sweep_top_level_thread_buffer(Id, Buffer)).
+
+sweep_top_level_pty_client(Name) :-
+ open(Name, read, InStream, [eof_action(reset)]),
+ open(Name, write, OutStream),
+ sweep_top_level_client(InStream, OutStream, ip(127,0,0,1)).
+
sweep_top_level_server(_, Port) :-
tcp_socket(ServerSocket),
tcp_setopt(ServerSocket, reuseaddr),
#'sweeprolog-top-level-sentinel)
(add-hook 'kill-buffer-hook #'comint-write-input-ring nil t)))
+(defcustom sweeprolog-top-level-use-pty
+ (not (memq system-type '(ms-dos windows-nt)))
+ "Whether to communicate with top-levels using pseudo-terminal (\"pty\").
+
+By default, this is t on systems where Emacs can use a pty.")
+
(defun sweeprolog-top-level-buffer (&optional name)
"Return a Prolog top-level buffer named NAME.
If the buffer already exists, ensure it is associated with a live
top-level."
- (unless sweeprolog-prolog-server-port
- (sweeprolog-start-prolog-server))
(let ((buf (get-buffer-create (or name "*sweeprolog-top-level*"))))
(unless (process-live-p (get-buffer-process buf))
(with-current-buffer buf
(unless (derived-mode-p 'sweeprolog-top-level-mode)
(sweeprolog-top-level-mode)))
- (unless (sweeprolog--query-once "sweep" "sweep_accept_top_level_client"
- (buffer-name buf))
- (error "Failed to create new top-level!"))
- (make-comint-in-buffer "sweeprolog-top-level"
- buf
- (cons "localhost"
- sweeprolog-prolog-server-port))
+ (if sweeprolog-top-level-use-pty
+ (progn
+ (make-comint-in-buffer "sweeprolog-top-level" buf nil)
+ (process-send-eof (get-buffer-process buf))
+ (sweeprolog--query-once "sweep" "sweep_top_level_start_pty"
+ (cons (process-tty-name
+ (get-buffer-process buf))
+ (buffer-name buf))))
+ (unless sweeprolog-prolog-server-port
+ (sweeprolog-start-prolog-server))
+ (sweeprolog--query-once "sweep" "sweep_accept_top_level_client"
+ (buffer-name buf))
+ (make-comint-in-buffer "sweeprolog-top-level"
+ buf
+ (cons "localhost"
+ sweeprolog-prolog-server-port)))
(unless comint-last-prompt
(accept-process-output (get-buffer-process buf) 1))
(sweeprolog-top-level-setup-history buf)