]> git.eshelyaron.com Git - sweep.git/commitdiff
Allow communicating with top-level via tty instead of TCP top-level-pty
authorEshel Yaron <me@eshelyaron.com>
Thu, 14 Sep 2023 16:28:16 +0000 (18:28 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 14 Sep 2023 16:28:16 +0000 (18:28 +0200)
sweep.pl
sweeprolog.el

index d9d10e98987176a4d83fb6eeb1e6588de411a924..efffccb5974727d6ada9ff18cc2c44081cfcb592 100644 (file)
--- a/sweep.pl
+++ b/sweep.pl
@@ -95,7 +95,8 @@
             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)).
@@ -772,6 +773,16 @@ write_sweep_module_location :-
     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),
index 3941d816b97aaaa7491c805410f2ec9c65b9785e..1c6d1723f6214cd30f847475e898cbccf849011d 100644 (file)
@@ -3131,6 +3131,12 @@ function with PROC and MSG."
                           #'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.
 
@@ -3138,20 +3144,27 @@ If NAME is nil, use the default name \"*sweeprolog-top-level*\".
 
 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)