]> git.eshelyaron.com Git - dict.git/commitdiff
FIXED: top-level buffer to thread synchronization
authorEshel Yaron <me@eshelyaron.com>
Tue, 4 Oct 2022 09:42:48 +0000 (12:42 +0300)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Oct 2022 19:56:19 +0000 (22:56 +0300)
sweep.pl
sweeprolog.el

index 4a1d376101726708bee0d7f9f1e9bb0b2ef30382..fd2dc0200ac3c7b6f2eba6e51ca427d5e77fbedb 100644 (file)
--- a/sweep.pl
+++ b/sweep.pl
@@ -829,12 +829,12 @@ sweep_top_level_client(InStream, OutStream, ip(127,0,0,1)) :-
     set_stream(user_input, newline(detect)),
     set_stream(user_output, newline(dos)),
     set_stream(user_error, newline(dos)),
+    thread_self(Self),
+    thread_property(Self, id(Id)),
+    thread_at_exit(retractall(sweep_top_level_thread_buffer(Id, _))),
     call_cleanup(prolog,
                  ( close(InStream, [force(true)]),
-                   close(OutStream, [force(true)]),
-                   thread_self(Self),
-                   thread_property(Self, id(Id)),
-                   retractall(sweep_top_level_thread_buffer(Id, _))
+                   close(OutStream, [force(true)])
                  )).
 sweep_top_level_client(InStream, OutStream, _) :-
     close(InStream),
index bd9a9b78fc213dc7437489b9c05c5c98b4990fb7..51e75221003e66c9643a2ba0e184c3ea7ffcb8f1 100644 (file)
@@ -1521,10 +1521,14 @@ Interactively, a prefix arg means to prompt for BUFFER."
       (sweeprolog-close-query)
       (unless (sweeprolog-true-p sol)
         (error "Failed to create new top-level!")))
-    (make-comint-in-buffer "sweeprolog-top-level"
-                           buf
-                           (cons "localhost"
-                                 sweeprolog-prolog-server-port))
+    (with-current-buffer 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 (current-buffer)) 1))
+      (sweeprolog-top-level--populate-thread-id))
     (pop-to-buffer buf sweeprolog-top-level-display-action)))
 
 (defun sweeprolog-top-level--post-self-insert-function ()
@@ -1578,7 +1582,7 @@ Interactively, a prefix arg means to prompt for BUFFER."
                             (buffer-local-value 'major-mode b))))
          (read-string "Signal goal: ?- ")))
   (sweeprolog-signal-thread (buffer-local-value 'sweeprolog-top-level-thread-id
-                                                buffer)
+                                                (get-buffer buffer))
                             goal))
 
 ;;;###autoload
@@ -1593,7 +1597,6 @@ Interactively, a prefix arg means to prompt for BUFFER."
                                                   (length s)))
               comint-delimiter-argument-list '(?,)
               comment-start "%")
-  (add-hook 'comint-exec-hook #'sweeprolog-top-level--populate-thread-id nil t)
   (add-hook 'post-self-insert-hook #'sweeprolog-top-level--post-self-insert-function nil t)
   (setq sweeprolog-buffer-module "user")
   (add-hook 'completion-at-point-functions #'sweeprolog-completion-at-point-function nil t)