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

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

[elpa] 04/04: [gnugo] Move most of ‘ gnugo-board-mode’ to ‘gnugo’.


From: Thien-Thi Nguyen
Subject: [elpa] 04/04: [gnugo] Move most of ‘ gnugo-board-mode’ to ‘gnugo’.
Date: Wed, 16 Apr 2014 15:44:36 +0000

ttn pushed a commit to branch master
in repository elpa.

commit 0dd9d1230b5fb25ee443479b8fd3404bc216f858
Author: Thien-Thi Nguyen <address@hidden>
Date:   Wed Apr 16 15:08:46 2014 +0200

    [gnugo] Move most of ‘gnugo-board-mode’ to ‘gnugo’.
    
    Although the buffer-local hash ‘gnugo-state’ is available
    in ‘gnugo-board-mode’, it is empty.  This impacts mostly
    funcs on ‘gnugo-board-mode-hook’ that use gnugo-{get,put}.
    
    * packages/gnugo/gnugo.el (gnugo-board-mode):
    Move buffer switching, options querying, process kicking,
    a raft of ‘gnugo-put’ calls, and buffer refreshing from here...
    (gnugo): ...to here; also, don't bother to ‘gnugo--forget’.
---
 packages/gnugo/NEWS     |    1 +
 packages/gnugo/gnugo.el |  191 ++++++++++++++++++++++-------------------------
 2 files changed, 91 insertions(+), 101 deletions(-)

diff --git a/packages/gnugo/NEWS b/packages/gnugo/NEWS
index 99966a1..22c447d 100644
--- a/packages/gnugo/NEWS
+++ b/packages/gnugo/NEWS
@@ -38,6 +38,7 @@ NB: "RCS: X..Y " means that the particular release includes
     - dropped ‘(gnugo-move-history 'count)’ (BI)
     - new func: ‘gnugo-current-player’
     - new hook: ‘gnugo-start-game-hook’
+    - ‘gnugo-board-mode-hook’ now unsuitable for prop munging (BI)
 
 - 2.3.1 | 2014-02-27
   - portability fixes
diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index 199e26b..ad3b335 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -2390,7 +2390,6 @@ Entering this mode runs the normal hook 
`gnugo-board-mode-hook'.
 In this mode, keys do not self insert.
 
 \\{gnugo-board-mode-map}"
-  (switch-to-buffer (generate-new-buffer "(Uninitialized GNUGO Board)"))
   (buffer-disable-undo)                 ; todo: undo undo undoing
   (kill-all-local-variables)
   (use-local-map gnugo-board-mode-map)
@@ -2403,106 +2402,7 @@ In this mode, keys do not self insert.
   (set (make-local-variable 'gnugo-state)
        (gnugo--mkht :size (1- 42)))
   (add-to-invisibility-spec :nogrid)
-  (gnugo--forget :game-over             ; todo: separate display/game aspects;
-                 :waiting               ;       move latter to func `gnugo'
-                 :last-waiting
-                 :black-captures
-                 :white-captures
-                 :mode-line
-                 :mode-line-form
-                 :display-using-images
-                 :xpms
-                 :local-xpms
-                 :all-yy)
-  (let ((name (if (string-match "[ ]" gnugo-program)
-                  (let ((p (substring gnugo-program 0 (match-beginning 0)))
-                        (o (substring gnugo-program (match-end 0)))
-                        (h (or (car gnugo-option-history) "")))
-                    (when (string-match "--mode" o)
-                      (user-error "Found \"--mode\" in `gnugo-program'"))
-                    (when (and o (cl-plusp (length o))
-                               h (cl-plusp (length o))
-                               (or (< (length h) (length o))
-                                   (not (string= (substring h 0 (length o))
-                                                 o))))
-                      (push (concat o " " h) gnugo-option-history))
-                    p)
-                gnugo-program))
-        (args (read-string "GNU Go options: "
-                           (car gnugo-option-history)
-                           'gnugo-option-history))
-        proc
-        board-size user-color handicap komi minus-l infile)
-    (loop for (var default opt rx)
-          in '((board-size      19 "--boardsize")
-               (user-color "black" "--color" "\\(black\\|white\\)")
-               (handicap         0 "--handicap")
-               (komi           0.0 "--komi")
-               (minus-l        nil "\\([^-]\\|^\\)-l[ ]*" "[^ ]+")
-               (infile         nil "--infile" "[ ]*[^ ]+"))
-          do (set var
-                  (or (when (string-match opt args)
-                        (let ((start (match-end 0)) s)
-                          (string-match (or rx "[0-9.]+") args start)
-                          (setq s (match-string 0 args))
-                          (if rx s (string-to-number s))))
-                      default)))
-    (gnugo-put :user-color user-color)
-    (let ((proc-args (split-string args)))
-      (gnugo-put :proc-args proc-args)
-      (gnugo-put :proc (setq proc (apply 'start-process "gnugo"
-                                         (current-buffer) name
-                                         "--mode" "gtp" "--quiet"
-                                         proc-args))))
-    (set-process-sentinel proc 'gnugo-sentinel)
-    ;; Emacs is too protective sometimes, blech.
-    (set-process-query-on-exit-flag proc nil)
-    (when (or minus-l infile)
-      (loop for (prop q)
-            in '((board-size "query_boardsize")
-                 (komi       "get_komi")
-                 (handicap   "get_handicap"))
-            do (set prop (string-to-number (gnugo-query q)))))
-    (gnugo-put :diamond (substring (process-name proc) 5))
-    (gnugo-put :gnugo-color (gnugo-other user-color))
-    (gnugo-put :highlight-last-move-spec
-      (gnugo-put :default-highlight-last-move-spec '("(" -1 nil)))
-    (gnugo-put :lparen-ov (make-overlay 1 1))
-    (gnugo-put :rparen-ov (let ((ov (make-overlay 1 1)))
-                            (overlay-put ov 'display ")")
-                            ov))
-    (gnugo--plant-and-climb
-     (gnugo/sgf-create "(;FF[4]GM[1])" t))
-    (gnugo--SZ! board-size)
-    (let ((root (gnugo--root-node)))
-      (cl-flet
-          ((r! (&rest plist)
-               (gnugo--decorate
-                root (loop              ; hmm, available elsewhere?
-                      while plist
-                      collect (let* ((k (pop plist))
-                                     (v (pop plist)))
-                                (cons k v))))))
-        (r! :SZ board-size
-            :DT (format-time-string "%Y-%m-%d")
-            :RU (if (string-match "--chinese-rules" args)
-                    "Chinese"
-                  "Japanese")
-            :AP (cons "gnugo.el" gnugo-version)
-            :KM komi)
-        (let ((gb (gnugo--blackp (gnugo-other user-color))))
-          (r! (if gb :PW :PB) (user-full-name)
-              (if gb :PB :PW) (concat "GNU Go " (gnugo-query "version"))))
-        (unless (zerop handicap)
-          (r! :HA handicap
-              :AB (mapcar (gnugo--as-cc-func)
-                          (gnugo-lsquery "fixed_handicap %d"
-                                         handicap)))))))
-  (gnugo-put :waiting-start (current-time))
-  (gnugo-put :hmul 1)
-  (gnugo-put :wmul 1)
-  (run-hooks 'gnugo-board-mode-hook)
-  (gnugo-refresh t))
+  (run-hooks 'gnugo-board-mode-hook))
 
 ;;;---------------------------------------------------------------------------
 ;;; Entry point
@@ -2545,7 +2445,96 @@ starting a new one.  See `gnugo-board-mode' 
documentation for more info."
                       (car all)
                     (assoc sel all))))))
       ;; set up a new board
+      (switch-to-buffer (generate-new-buffer "(Uninitialized GNUGO Board)"))
       (gnugo-board-mode)
+      (let ((name (if (string-match "[ ]" gnugo-program)
+                      (let ((p (substring gnugo-program 0 (match-beginning 0)))
+                            (o (substring gnugo-program (match-end 0)))
+                            (h (or (car gnugo-option-history) "")))
+                        (when (string-match "--mode" o)
+                          (user-error "Found \"--mode\" in `gnugo-program'"))
+                        (when (and o (cl-plusp (length o))
+                                   h (cl-plusp (length o))
+                                   (or (< (length h) (length o))
+                                       (not (string= (substring h 0 (length o))
+                                                     o))))
+                          (push (concat o " " h) gnugo-option-history))
+                        p)
+                    gnugo-program))
+            (args (read-string "GNU Go options: "
+                               (car gnugo-option-history)
+                               'gnugo-option-history))
+            proc
+            board-size user-color handicap komi minus-l infile)
+        (loop for (var default opt rx)
+              in '((board-size      19 "--boardsize")
+                   (user-color "black" "--color" "\\(black\\|white\\)")
+                   (handicap         0 "--handicap")
+                   (komi           0.0 "--komi")
+                   (minus-l        nil "\\([^-]\\|^\\)-l[ ]*" "[^ ]+")
+                   (infile         nil "--infile" "[ ]*[^ ]+"))
+              do (set var
+                      (or (when (string-match opt args)
+                            (let ((start (match-end 0)) s)
+                              (string-match (or rx "[0-9.]+") args start)
+                              (setq s (match-string 0 args))
+                              (if rx s (string-to-number s))))
+                          default)))
+        (gnugo-put :user-color user-color)
+        (let ((proc-args (split-string args)))
+          (gnugo-put :proc-args proc-args)
+          (gnugo-put :proc (setq proc (apply 'start-process "gnugo"
+                                             (current-buffer) name
+                                             "--mode" "gtp" "--quiet"
+                                             proc-args))))
+        (set-process-sentinel proc 'gnugo-sentinel)
+        ;; Emacs is too protective sometimes, blech.
+        (set-process-query-on-exit-flag proc nil)
+        (when (or minus-l infile)
+          (loop for (prop q)
+                in '((board-size "query_boardsize")
+                     (komi       "get_komi")
+                     (handicap   "get_handicap"))
+                do (set prop (string-to-number (gnugo-query q)))))
+        (gnugo-put :diamond (substring (process-name proc) 5))
+        (gnugo-put :gnugo-color (gnugo-other user-color))
+        (gnugo-put :highlight-last-move-spec
+          (gnugo-put :default-highlight-last-move-spec '("(" -1 nil)))
+        (gnugo-put :lparen-ov (make-overlay 1 1))
+        (gnugo-put :rparen-ov (let ((ov (make-overlay 1 1)))
+                                (overlay-put ov 'display ")")
+                                ov))
+        (gnugo--plant-and-climb
+         (gnugo/sgf-create "(;FF[4]GM[1])" t))
+        (gnugo--SZ! board-size)
+        (let ((root (gnugo--root-node)))
+          (cl-flet
+              ((r! (&rest plist)
+                   (gnugo--decorate
+                    root (loop          ; hmm, available elsewhere?
+                          while plist
+                          collect (let* ((k (pop plist))
+                                         (v (pop plist)))
+                                    (cons k v))))))
+            (r! :SZ board-size
+                :DT (format-time-string "%Y-%m-%d")
+                :RU (if (string-match "--chinese-rules" args)
+                        "Chinese"
+                      "Japanese")
+                :AP (cons "gnugo.el" gnugo-version)
+                :KM komi)
+            (let ((gb (gnugo--blackp (gnugo-other user-color))))
+              (r! (if gb :PW :PB) (user-full-name)
+                  (if gb :PB :PW) (concat "GNU Go " (gnugo-query "version"))))
+            (unless (zerop handicap)
+              (r! :HA handicap
+                  :AB (mapcar (gnugo--as-cc-func)
+                              (gnugo-lsquery "fixed_handicap %d"
+                                             handicap)))))))
+      (gnugo-put :waiting-start (current-time))
+      (gnugo-put :hmul 1)
+      (gnugo-put :wmul 1)
+      (gnugo-refresh t)
       (let ((half (truncate (1+ (gnugo-get :SZ)) 2)))
         (gnugo-goto-pos (format "A%d" half))
         (forward-char (* 2 (1- half)))



reply via email to

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