[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 02/02: [gnugo int] Add abstraction: gnugo--begin-exchange
From: |
Thien-Thi Nguyen |
Subject: |
[elpa] 02/02: [gnugo int] Add abstraction: gnugo--begin-exchange |
Date: |
Sun, 09 Mar 2014 09:37:01 +0000 |
ttn pushed a commit to branch master
in repository elpa.
commit 53f9da3fd4b8286b79209fdd01c4878cc3929449
Author: Thien-Thi Nguyen <address@hidden>
Date: Sun Mar 9 10:38:20 2014 +0100
[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.
---
packages/gnugo/gnugo.el | 43 +++++++++++++++++++++++--------------------
1 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index 1ece2ec..f9bac18 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/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 ()