emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/gnugo 6e26e76 061/357: [gnugo int] Add abstraction: gnu


From: Stefan Monnier
Subject: [elpa] externals/gnugo 6e26e76 061/357: [gnugo int] Add abstraction: gnugo--begin-exchange
Date: Sun, 29 Nov 2020 14:50:48 -0500 (EST)

branch: externals/gnugo
commit 6e26e76950360cdee67fad260edc76062992b704
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>

    [gnugo int] Add abstraction: gnugo--begin-exchange
    
    * gnugo.el (gnugo-send-line): Delete func.
    (gnugo--begin-exchange): New func.
    (gnugo--q, gnugo-get-move): Use it.
---
 gnugo.el | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/gnugo.el b/gnugo.el
index 1ece2ec..f9bac18 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -323,10 +323,12 @@ Handle the big, slow-to-render, and/or uninteresting ones 
specially."
             (when (eq proc (gnugo-get :proc))
               (gnugo-put :proc nil))))))))
 
-(defun gnugo-send-line (line)
-  (let ((proc (gnugo-get :proc)))
-    (process-send-string proc line)
-    (process-send-string proc "\n")))
+(defun gnugo--begin-exchange (proc filter line)
+  (declare (indent 2))                  ; good time, for a rime
+                                        ; nice style, for a wile...
+  (set-process-filter proc filter)
+  (process-send-string proc line)
+  (process-send-string proc "\n"))
 
 (defun gnugo--q (fmt &rest args)
   "Send formatted command \"FMT ARGS...\"; wait for / return response.
@@ -338,20 +340,20 @@ status of the command.  See also `gnugo-query'."
   (let ((proc (gnugo-get :proc)))
     (process-put proc :incomplete t)
     (process-put proc :srs "")          ; synchronous return stash
-    (set-process-filter
-     proc (lambda (proc string)
-            (let ((full (concat (process-get proc :srs)
-                                string)))
-              (process-put proc :srs full)
-              (unless (numberp (compare-strings
-                                full (max 0 (- (length full)
-                                               2))
-                                nil
-                                "\n\n" nil nil))
-                (process-put proc :incomplete nil)))))
-    (gnugo-send-line (if (null args)
-                         fmt
-                       (apply #'format fmt args)))
+    (gnugo--begin-exchange
+        proc (lambda (proc string)
+               (let ((full (concat (process-get proc :srs)
+                                   string)))
+                 (process-put proc :srs full)
+                 (unless (numberp (compare-strings
+                                   full (max 0 (- (length full)
+                                                  2))
+                                   nil
+                                   "\n\n" nil nil))
+                   (process-put proc :incomplete nil))))
+      (if (null args)
+          fmt
+        (apply #'format fmt args)))
     (while (process-get proc :incomplete)
       (accept-process-output proc 30))
     (prog1 (substring (process-get proc :srs) 0 -2)
@@ -1010,8 +1012,9 @@ its move."
 
 (defun gnugo-get-move (color)
   (gnugo-put :waitingp t)
-  (set-process-filter (gnugo-get :proc) 'gnugo-get-move-insertion-filter)
-  (gnugo-send-line (concat "genmove " color))
+  (gnugo--begin-exchange
+      (gnugo-get :proc) 'gnugo-get-move-insertion-filter
+    (concat "genmove " color))
   (accept-process-output))
 
 (defun gnugo-cleanup ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]