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

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

[elpa] externals/gnugo 806a2f2 133/357: [gnugo] Add some navigation comm


From: Stefan Monnier
Subject: [elpa] externals/gnugo 806a2f2 133/357: [gnugo] Add some navigation commands for GNUGO Frolic mode.
Date: Sun, 29 Nov 2020 14:51:06 -0500 (EST)

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

    [gnugo] Add some navigation commands for GNUGO Frolic mode.
    
    * packages/gnugo/gnugo.el (gnugo-frolic-parent-buffer)
    (gnugo-frolic-origin): New defvars.
    (gnugo-frolic-mode): Don't invoke ‘view-mode’.
    (gnugo-frolic-quit, gnugo-frolic-return-to-origin): New commands.
    (gnugo-frolic-in-the-leaves): Set as local vars
    ‘gnugo-frolic-in-the-leaves’, ‘gnugo-frolic-origin’;
    use ‘gnugo-frolic-return-to-origin’.
    (gnugo-frolic-mode-map): Add bindings for ‘q’, ‘C’, ‘o’.
---
 gnugo.el | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/gnugo.el b/gnugo.el
index 0c7e682..4706b83 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -172,6 +172,9 @@ For ~t, the value is a snapshot, use `gnugo-refresh' to 
update it.")
 (eval-when-compile
   (defvar gnugo-xpms nil))
 
+(defvar gnugo-frolic-parent-buffer nil)
+(defvar gnugo-frolic-origin nil)
+
 ;;;---------------------------------------------------------------------------
 ;;; Support functions
 
@@ -716,9 +719,24 @@ For all other values of RSEL, do nothing and return nil."
 Initially View minor mode is active.
 
 \\{gnugo-frolic-mode-map}"
-  (buffer-disable-undo)
-  ;; Is this idio{ma}tic?
-  (view-mode 1))
+  (buffer-disable-undo))
+
+(defun gnugo-frolic-quit ()
+  "Kill GNUGO Frolic buffer and switch to its parent buffer."
+  (interactive)
+  (let ((bye (current-buffer)))
+    (switch-to-buffer (when (buffer-live-p gnugo-frolic-parent-buffer)
+                        gnugo-frolic-parent-buffer))
+    (kill-buffer bye)))
+
+(defun gnugo-frolic-return-to-origin ()
+  "Move point to the board's current position."
+  (interactive)
+  (if (not gnugo-frolic-origin)
+      (message "No origin")
+    (goto-char gnugo-frolic-origin)
+    (recenter (- (count-lines (line-beginning-position)
+                              (point-max))))))
 
 (defun gnugo-frolic-in-the-leaves ()
   "Display the game tree in a *GNUGO Frolic* buffer.
@@ -752,6 +770,7 @@ are dimmed.  Type \\[describe-mode] in that buffer for 
details."
   (interactive)
   (let* ((buf (get-buffer-create (concat (gnugo-get :diamond)
                                          "*GNUGO Frolic*")))
+         (from (current-buffer))
          ;; todo: use defface once we finally succumb to ‘customize’
          (dimmed-node-face (list :inherit 'default
                                  :foreground "gray50"))
@@ -808,6 +827,7 @@ are dimmed.  Type \\[describe-mode] in that buffer for 
details."
                                  (format "%-5s" n))
                                lanes
                                " ")))
+      (set (make-local-variable 'gnugo-frolic-parent-buffer) from)
       (loop
        for n                            ; move number
        from max-move-num downto 1
@@ -902,9 +922,8 @@ are dimmed.  Type \\[describe-mode] in that buffer for 
details."
                      (- (1+ (length forks))))
                     (point))))))))
     (when finish
-      (goto-char finish)
-      (recenter (- (count-lines (line-beginning-position)
-                                (point-max)))))))
+      (set (make-local-variable 'gnugo-frolic-origin) finish)
+      (gnugo-frolic-return-to-origin))))
 
 (defun gnugo-boss-is-near ()
   "Do `bury-buffer' until the current one is not a GNU Board."
@@ -2158,6 +2177,12 @@ starting a new one.  See `gnugo-board-mode' 
documentation for more info."
 ;;;---------------------------------------------------------------------------
 ;;; Load-time actions
 
+(mapc (lambda (pair)
+        (define-key gnugo-frolic-mode-map (car pair) (cdr pair)))
+      '(("q"          . gnugo-frolic-quit)
+        ("C"          . gnugo-frolic-quit) ; like ‘View-kill-and-leave’
+        ("o"          . gnugo-frolic-return-to-origin)))
+
 (unless gnugo-board-mode-map
   (setq gnugo-board-mode-map (make-sparse-keymap))
   (suppress-keymap gnugo-board-mode-map)



reply via email to

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