From d70195ede30df33098f58cc6ba5fd19c26495055 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 20 Oct 2023 17:51:15 +0300 Subject: [PATCH] Set Prolog flag 'tty_control' to 'true' when using pty When 'sweeprolog-top-level-use-pty' is non-nil, let the Prolog top-level thread know that it controls the tty. This affects some aspects of the top-level interaction, namely in the presence of choice points. A significant benefit is that Prolog ensures that the tty does not echo input, so we can stop setting 'comint-process-echoes' which had the adverse effect of blocking Emacs when output stalls on non-echoing terminals. * sweep.pl (sweep_top_level_client/3): Become 'sweep_top_level_client/4'. New argument says whether the top-level controls the tty. (sweep_top_level_pty_client/1,sweep_top_level_server_loop_/2): Adjust. * sweeprolog.el (sweeprolog-top-level-buffer): Stop setting 'comint-process-echoes'. (sweeprolog-top-level--post-self-insert-function): When using a tty, send single character responses directly and assume that the top-level echoes them back. --- sweep.pl | 10 +++++----- sweeprolog.el | 9 ++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sweep.pl b/sweep.pl index 6215151..220c187 100644 --- a/sweep.pl +++ b/sweep.pl @@ -781,7 +781,7 @@ sweep_top_level_start_pty(Name, Id) :- 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_client(InStream, OutStream, ip(127, 0, 0, 1), true). sweep_top_level_server(_, Port) :- tcp_socket(ServerSocket), @@ -808,17 +808,17 @@ sweep_top_level_server_loop_(accept(From), ServerSocket) :- tcp_open_socket(Slave, InStream, OutStream), set_stream(InStream, close_on_abort(false)), set_stream(OutStream, close_on_abort(false)), - sweep_create_thread(sweep_top_level_client(InStream, OutStream, Peer), T), + sweep_create_thread(sweep_top_level_client(InStream, OutStream, Peer, false), T), thread_property(T, id(Id)), thread_send_message(From, client(Id)), sweep_top_level_server_loop(ServerSocket). sweep_top_level_server_loop_(_, _). -sweep_top_level_client(InStream, OutStream, ip(127,0,0,1)) :- +sweep_top_level_client(InStream, OutStream, ip(127, 0, 0, 1), TC) :- !, set_prolog_IO(InStream, OutStream, OutStream), set_stream(InStream, tty(true)), - set_prolog_flag(tty_control, false), + set_prolog_flag(tty_control, TC), current_prolog_flag(encoding, Enc), set_stream(user_input, encoding(Enc)), set_stream(user_output, encoding(Enc)), @@ -832,7 +832,7 @@ sweep_top_level_client(InStream, OutStream, ip(127,0,0,1)) :- close(OutStream, [force(true)]) )), prolog. -sweep_top_level_client(InStream, OutStream, _) :- +sweep_top_level_client(InStream, OutStream, _, _) :- close(InStream), close(OutStream). diff --git a/sweeprolog.el b/sweeprolog.el index a90baeb..68e66a3 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -3241,7 +3241,6 @@ top-level." (if sweeprolog-top-level-use-pty (progn (make-comint-in-buffer "sweeprolog-top-level" buf nil) - (setq-local comint-process-echoes t) (process-send-eof (get-buffer-process buf)) (sweeprolog--query-once "sweep" "sweep_top_level_start_pty" (process-tty-name (get-buffer-process buf)))) @@ -3251,7 +3250,6 @@ top-level." buf (cons "localhost" sweeprolog-prolog-server-port)) - (setq-local comint-process-echoes nil) (sweeprolog--query-once "sweep" "sweep_accept_top_level_client" nil))) (let ((proc (get-buffer-process buf))) (set-process-filter proc @@ -3335,7 +3333,12 @@ appropriate buffer." (- pend pstart)))) (not (string= "|: " prompt)) (not (string= "| " prompt))) - (comint-send-input))))) + (let ((proc (get-buffer-process (current-buffer)))) + (if (eq (process-type proc) 'network) + (comint-send-input) + (delete-char -1) + (process-send-string (get-buffer-process (current-buffer)) + (char-to-string last-command-event)))))))) (defun sweeprolog-signal-thread (tid goal) (sweeprolog--query-once "sweep" "sweep_thread_signal" -- 2.39.2