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

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

[elpa] externals/gnugo bc4abdc 238/357: [gnugo int] Centralize some "No


From: Stefan Monnier
Subject: [elpa] externals/gnugo bc4abdc 238/357: [gnugo int] Centralize some "No stone at POS" errors.
Date: Sun, 29 Nov 2020 14:51:30 -0500 (EST)

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

    [gnugo int] Centralize some "No stone at POS" errors.
    
    * packages/gnugo/gnugo.el (gnugo--mem-with-played-stone):
    Take optional arg NOERROR; if clear, when no ‘color’
    found, signal "No stone at POS" error.
    (gnugo--climb-towards-root): Drop "POS already clear" error
    handling; use ‘gnugo--mem-with-played-stone’ rv directly.
    (gnugo--node-with-played-stone): Take optional arg NOERROR;
    pass it to ‘gnugo--mem-with-played-stone’.
    (gnugo-describe-position): Specify
    NOERROR to ‘gnugo--node-with-played-stone’.
    (gnugo-comment): Drop "No stone at POS" error handling;
    use ‘gnugo--node-with-played-stone’ rv directly.
---
 gnugo.el | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/gnugo.el b/gnugo.el
index 8cf2a7c..d926725 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -1929,11 +1929,13 @@ If FILENAME already exists, Emacs confirms that you 
wish to overwrite it."
     (set-buffer-modified-p nil)
     (gnugo--who-is-who wait play samep)))
 
-(defun gnugo--mem-with-played-stone (pos)
+(defun gnugo--mem-with-played-stone (pos &optional noerror)
   (let ((color (case (following-char)
                  (?X :B)
                  (?O :W))))
-    (when color
+    (if (not color)
+        (unless noerror
+          (user-error "No stone at %s" pos))
       (loop with fruit = (cons color (funcall (gnugo--as-cc-func) pos))
             for mem on (aref (gnugo-get :monkey) 0)
             when (equal fruit (caar mem))
@@ -1956,8 +1958,7 @@ If FILENAME already exists, Emacs confirms that you wish 
to overwrite it."
                              spec)
                            (aref monkey 0))
                  (let* ((pos spec)
-                        (hmm (or (gnugo--mem-with-played-stone pos)
-                                 (user-error "%s already clear" pos))))
+                        (hmm (gnugo--mem-with-played-stone pos)))
                    ;; todo: relax ‘gnugo--user-play’ then lift restriction
                    (unless (eq (gnugo--prop<-color user-color)
                                (car (gnugo--move-prop (car hmm))))
@@ -2226,15 +2227,15 @@ which placed the stone at point."
   (gnugo-toggle-image-display)
   (save-excursion (gnugo-refresh)))
 
-(defsubst gnugo--node-with-played-stone (pos)
-  (car (gnugo--mem-with-played-stone pos)))
+(defsubst gnugo--node-with-played-stone (pos &optional noerror)
+  (car (gnugo--mem-with-played-stone pos noerror)))
 
 (defun gnugo-describe-position ()
   "Display the board position under cursor in the echo area.
 If there a stone at that position, also display its move number."
   (interactive)
   (let* ((pos (gnugo-position))         ; do first (can throw)
-         (node (gnugo--node-with-played-stone pos)))
+         (node (gnugo--node-with-played-stone pos t)))
     (message
      "%s%s" pos
      (or (when node
@@ -2263,8 +2264,7 @@ initial-input (see `read-string').
 If COMMENT is nil or the empty string, remove the property entirely."
   (interactive
    (let* ((pos (gnugo-position))
-          (node (or (gnugo--node-with-played-stone pos)
-                    (user-error "No stone at %s" pos))))
+          (node (gnugo--node-with-played-stone pos)))
      (list node
            (read-string (format "Comment for %s: "
                                 (gnugo-describe-position))



reply via email to

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