emacs-devel
[Top][All Lists]
Advanced

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

Re: [elpa] master cf9edfa 3/5: [gnugo slog] Clear ‘inhibit-point-motion-


From: Stefan Monnier
Subject: Re: [elpa] master cf9edfa 3/5: [gnugo slog] Clear ‘inhibit-point-motion-hooks’.
Date: Sun, 15 Jan 2017 21:32:19 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)

> +  ;; GNU Emacs 25.1 looks askance at ‘intangible’, sigh.
> +  (setq-local inhibit-point-motion-hooks nil)

How 'bout the patch below (which additionally gets you rid of the place
where you modify a string in-place, which I find very untoward).

>From the bit of testing I've done, the intangibility on your board is
a bit flimsy (C-f/C-b can move off the board), but I haven't tried to
change that.


        Stefan


diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index a9e03aaa4..6a3eb0b65 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -636,6 +636,9 @@ when you are sure the command cannot fail."
               :nogrid)
      (save-excursion (gnugo-refresh)))))
 
+(defconst gnugo--intangible
+  (if (fboundp 'cursor-intangible-mode) 'cursor-intangible 'intangible))
+
 (defun gnugo-propertize-board-buffer ()
   (erase-buffer)
   (insert (substring (gnugo--q "showboard") 3))
@@ -703,7 +706,7 @@ when you are sure the command cannot fail."
                                    (gnugo-position gnugo-yin))))
           (unless (= (1- other-edge) p)
             (add-text-properties (1+ p) (+ 2 p) ispc-props)
-            (put-text-property p (+ 2 p) 'intangible ival)))
+            (put-text-property p (+ 2 p) gnugo--intangible ival)))
         (add-text-properties (1+ other-edge) right-empty grid-props)
         (goto-char right-empty)
         (when (looking-at "\\s-+\\(WH\\|BL\\).*capt.* \\([0-9]+\\).*$")
@@ -725,7 +728,7 @@ when you are sure the command cannot fail."
 
 (defun gnugo-merge-showboard-results ()
   (let ((aft (substring (gnugo--q "showboard") 3))
-        (adj 1)                         ; string to buffer position adjustment
+        (adj (point-min))       ; String to buffer position adjustment.
 
         (sync "[0-9]* stones$")
         ;; Note: `sync' used to start w/ "[0-9]+", but that is too
@@ -797,8 +800,9 @@ when you are sure the command cannot fail."
         (delete-char 1)
         ;; do this last to avoid complications w/ font lock
         ;; (this also means we cannot include `intangible' in `front-sticky')
-        (when (setq very-strange (get-text-property (1+ cut) 'intangible))
-          (put-text-property cut (1+ cut) 'intangible very-strange))))))
+        ;; FIXME: This care is probably not needed for cursor-intangible.
+        (when (setq very-strange (get-text-property (1+ cut) 
gnugo--intangible))
+          (put-text-property cut (1+ cut) gnugo--intangible very-strange))))))
 
 (defsubst gnugo--move-prop (node)
   (or (assq :B node)
@@ -1249,34 +1253,36 @@ its move."
         (setq cur gnugo-mode-line)
         (gnugo-put :mode-line cur)
         (gnugo-put :mode-line-form
-          (cond ((stringp cur)
-                 (setq cur (copy-sequence cur))
-                 (let (acc cut c)
-                   (while (setq cut (string-match "~[bwpmtu]" cur))
-                     (aset cur cut ?%)
-                     (setq c (aref cur (cl-incf cut)))
-                     (aset cur cut ?s)
-                     (push
-                      `(,(intern (format "squig-%c" c))
-                        ,(cl-case c
-                           (?b '(or (gnugo-get :black-captures) 0))
-                           (?w '(or (gnugo-get :white-captures) 0))
-                           (?p '(gnugo-current-player))
-                           (?t '(let ((ws (gnugo-get :waiting-start)))
-                                  (if ws
-                                      (cadr (time-since ws))
-                                    "-")))
-                           (?u '(or (gnugo-get :last-waiting) "-"))
-                           (?m '(let ((tree (gnugo-get :sgf-gametree))
-                                      (monkey (gnugo-get :monkey)))
-                                  (gethash (car (aref monkey 0))
-                                           (gnugo--tree-mnum tree)
-                                           ;; should be unnecessary
-                                           "?")))))
-                      acc))
-                   `(let ,(delete-dups (copy-sequence acc))
-                      (format ,cur ,@(reverse (mapcar 'car acc))))))
-                (t cur))))
+          (if (not (stringp cur))
+              cur
+            (let* ((acc ())
+                   (fmt
+                    (replace-regexp-in-string
+                     "~[bwpmtu]"
+                     (lambda (match)
+                       (prog1 "%s"
+                         (let ((c (aref match 1)))
+                           (push
+                            `(,(intern (format "squig-%c" c))
+                              ,(cl-case c
+                                 (?b '(or (gnugo-get :black-captures) 0))
+                                 (?w '(or (gnugo-get :white-captures) 0))
+                                 (?p '(gnugo-current-player))
+                                 (?t '(let ((ws (gnugo-get :waiting-start)))
+                                        (if ws
+                                            (cadr (time-since ws))
+                                          "-")))
+                                 (?u '(or (gnugo-get :last-waiting) "-"))
+                                 (?m '(let ((tree (gnugo-get :sgf-gametree))
+                                            (monkey (gnugo-get :monkey)))
+                                        (gethash (car (aref monkey 0))
+                                                 (gnugo--tree-mnum tree)
+                                                 ;; should be unnecessary
+                                                 "?")))))
+                            acc))))
+                     cur t t)))
+              `(let ,(delete-dups (copy-sequence acc))
+                 (format ,fmt ,@(reverse (mapcar #'car acc))))))))
       (let ((form (gnugo-get :mode-line-form)))
         (setq mode-line-process
               (and form
@@ -2145,8 +2151,8 @@ In this mode, keys do not self insert."
   (setq font-lock-defaults '(gnugo-font-lock-keywords t)
         truncate-lines t)
   (add-hook 'kill-buffer-hook 'gnugo-cleanup nil t)
-  ;; GNU Emacs 25.1 looks askance at ‘intangible’, sigh.
-  (setq-local inhibit-point-motion-hooks nil)
+  (if (eq gnugo--intangible 'cursor-intangible)
+      (cursor-intangible-mode 1))
   (setq-local gnugo-state (gnugo--mkht :size (1- 42)))
   (setq-local gnugo-btw nil)
   (add-to-list 'minor-mode-alist '(gnugo-btw gnugo-btw))
@@ -2404,10 +2410,10 @@ See `gnugo-board-mode' for a full list of commands."
 

 ;;;---------------------------------------------------------------------------
-;;; The remainder of this file defines a simplified SGF-handling library.
-;;; When/if it should start to attain generality, it should be split off into
-;;; a separate file (probably named sgf.el) w/ funcs and vars renamed sans the
-;;; "gnugo/" prefix.
+;; The remainder of this file defines a simplified SGF-handling library.
+;; When/if it should start to attain generality, it should be split off into
+;; a separate file (probably named sgf.el) w/ funcs and vars renamed sans the
+;; "gnugo/" prefix.
 
 (defconst gnugo/sgf-*r4-properties*
   '((AB "Add Black"       setup list stone)



reply via email to

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