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

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

[elpa] externals/gnugo 3903907 235/357: [gnugo] Validate position arg o


From: Stefan Monnier
Subject: [elpa] externals/gnugo 3903907 235/357: [gnugo] Validate position arg of GTP commands ‘undo’, ‘gg-undo’.
Date: Sun, 29 Nov 2020 14:51:29 -0500 (EST)

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

    [gnugo] Validate position arg of GTP commands ‘undo’, ‘gg-undo’.
    
    * packages/gnugo/gnugo.el
    (:gnugo-gtp-command-spec validpos): New internal func.
    (:gnugo-gtp-command-spec undo)
    (:gnugo-gtp-command-spec gg-undo): Use ‘validpos’.
---
 NEWS     |  1 +
 gnugo.el | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 48b02ac..cebe790 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ NB: "RCS: X..Y " means that the particular release includes
   - new command: ‘C-c C-a’ (gnugo-toggle-abdication)
   - new major mode: GNUGO Frolic (gnugo-frolic-mode)
   - GNUGO Board mode now derived from Special mode
+  - position arg validated for direct GTP commands ‘undo’, ‘gg-undo’
   - performance improvements
   - of interest to hackers (see source, BI => backward incompatible)
     - dropped var: ‘gnugo-inhibit-refresh’ (BI)
diff --git a/gnugo.el b/gnugo.el
index 52aeb84..78c3f4b 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -2642,6 +2642,19 @@ See `gnugo-board-mode' for a full list of commands."
       ((sget (x) (get x :gnugo-gtp-command-spec))
        (jam (cmd prop val) (put cmd :gnugo-gtp-command-spec
                                 (plist-put (sget cmd) prop val)))
+       (validpos (s &optional go)
+                 (let ((pos (upcase s)))
+                   (loop with size = (gnugo-get :SZ)
+                         for c across (funcall (gnugo--as-cc-func)
+                                               pos)
+                         do (let ((norm (- c ?a)))
+                              (unless (and (< -1 norm)
+                                           (> size norm))
+                                (user-error "Invalid position: %s"
+                                            pos))))
+                   (when go
+                     (gnugo-goto-pos pos))
+                   pos))
        (defgtp (x &rest props) (dolist (cmd (if (symbolp x) (list x) x))
                                  (let ((ls props))
                                    (while ls
@@ -2708,7 +2721,7 @@ See `gnugo-board-mode' for a full list of commands."
          (let (n)
            (cond ((not sel) 1)
                  ((cl-plusp (setq n (string-to-number (car sel)))) n)
-                 (t (car sel)))))))))
+                 (t (validpos (car sel) t)))))))))
 
 (provide 'gnugo)
 



reply via email to

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