More tweaks of skeleton documentation wrt \n behavior at bol/eol.
[bpt/emacs.git] / lisp / play / gametree.el
index d0ba9b0..a2a9373 100644 (file)
@@ -1,6 +1,6 @@
 ;;; gametree.el --- manage game analysis trees in Emacs
 
-;; Copyright (C) 1997, 1999, 2001-201 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1999, 2001-2014 Free Software Foundation, Inc.
 
 ;; Author: Ian T Zimmerman <itz@rahul.net>
 ;; Created: Wed Dec 10 07:41:46 PST 1997
@@ -258,23 +258,20 @@ This value is simply the outline heading level of the current line."
 
 (defun gametree-children-shown-p ()
   (save-excursion
-    (condition-case nil
+    (ignore-errors
         (let ((depth (gametree-current-branch-depth)))
           (outline-next-visible-heading 1)
-          (< depth (gametree-current-branch-depth)))
-      (error nil))))
+          (< depth (gametree-current-branch-depth))))))
 
-(defun gametree-current-layout (depth &optional top-level)
+(defun gametree-current-layout (depth &optional from-top-level)
   (let ((layout nil) (first-time t))
     (while (save-excursion
-             (condition-case nil
-                 (progn
-                   (or (and first-time top-level
-                            (bolp) (looking-at outline-regexp))
-                       (setq first-time nil)
-                       (outline-next-visible-heading 1))
-                   (< depth (gametree-current-branch-depth)))
-               (error nil)))
+             (ignore-errors
+               (or (and first-time from-top-level
+                        (bolp) (looking-at outline-regexp))
+                   (setq first-time nil)
+                   (outline-next-visible-heading 1))
+               (< depth (gametree-current-branch-depth))))
       (if (not first-time)
           (outline-next-visible-heading 1))
       (setq first-time nil)
@@ -297,18 +294,16 @@ This value is simply the outline heading level of the current line."
     (goto-char (point-min))
     (setq gametree-local-layout (gametree-current-layout 0 t))))
 
-(defun gametree-apply-layout (layout depth &optional top-level)
+(defun gametree-apply-layout (layout depth &optional from-top-level)
   (let ((first-time t))
     (while (and layout
                 (save-excursion
-                  (condition-case nil
-                      (progn
-                        (or (and first-time top-level
-                                 (bolp) (looking-at outline-regexp))
-                            (setq first-time nil)
-                            (outline-next-visible-heading 1))
-                        (< depth (gametree-current-branch-depth)))
-                    (error nil))))
+                  (ignore-errors
+                    (or (and first-time from-top-level
+                             (bolp) (looking-at outline-regexp))
+                        (setq first-time nil)
+                        (outline-next-visible-heading 1))
+                    (< depth (gametree-current-branch-depth)))))
       (if (not first-time)
           (outline-next-visible-heading 1))
       (setq first-time nil)
@@ -375,9 +370,7 @@ Subnodes which have been manually scored are honored."
             (while (not done)           ;handle subheadings
               (setq running (funcall minmax running
                                      (gametree-compute-reduced-score)))
-              (setq done (condition-case nil
-                             (outline-forward-same-level 1)
-                           (error nil)))))
+              (setq done (ignore-errors (outline-forward-same-level 1)))))
           running)))))
 \f
 ;;;; Commands
@@ -406,23 +399,23 @@ depth AT-DEPTH or smaller is found."
       (error
        (goto-char (point-max))
        (if (not (bolp)) (insert "\n"))))
-    (let ((starting-plys
+    (let ((starting-plies
            (if (> (gametree-current-branch-depth) parent-depth)
                (gametree-current-branch-ply)
              (save-excursion (forward-line -1)
                              (gametree-current-branch-ply)))))
       (goto-char (1- (point)))
       (insert "\n")
-      (insert (format (if (= 0 (mod starting-plys 2))
+      (insert (format (if (= 0 (mod starting-plies 2))
                           gametree-full-ply-format
                         gametree-half-ply-format)
-                      (/ starting-plys 2))))))
+                      (/ starting-plies 2))))))
 
 (defun gametree-break-line-here (&optional at-move)
   "Split the variation node at the point position.
 This command works whether the current variation node is a leaf, or is
 already branching at its end.  The new node is created at a level that
-reflects the number of game plys between the beginning of the current
+reflects the number of game plies between the beginning of the current
 variation and the breaking point.
 
 With a numerical argument AT-MOVE, split the variation before
@@ -442,8 +435,8 @@ only work of Black's moves are explicitly numbered, for instance
                 gametree-half-ply-regexp)) limit))
           (goto-char (match-beginning 0))))
   (gametree-transpose-following-leaves)
-  (let* ((pt (set-marker (make-marker) (point)))
-         (plys (gametree-current-branch-ply))
+  (let* ((pt (point-marker))
+         (plies (gametree-current-branch-ply))
          (depth (gametree-current-branch-depth))
          (old-depth depth))
     (if (= depth 0)
@@ -458,7 +451,7 @@ only work of Black's moves are explicitly numbered, for instance
                     (if (zerop old-branch-ply)
                         (1+ (gametree-current-branch-depth))
                       (+ (gametree-current-branch-depth)
-                         (- plys old-branch-ply))))))
+                         (- plies old-branch-ply))))))
           (save-excursion
             (beginning-of-line 1)
             (funcall gametree-make-heading-function depth)
@@ -478,7 +471,7 @@ only work of Black's moves are explicitly numbered, for instance
       (insert "\n")
       (if (not (= 0 old-depth))
           (funcall gametree-make-heading-function
-                   (+ depth (- (gametree-current-branch-ply) plys))))
+                   (+ depth (- (gametree-current-branch-ply) plies))))
       (gametree-prettify-heading))))
 
 (defun gametree-merge-line ()
@@ -538,8 +531,10 @@ Subnodes which have been manually scored are honored."
 (defun gametree-layout-to-register (register)
   "Store current tree layout in register REGISTER.
 Use \\[gametree-apply-register-layout] to restore that configuration.
-Argument is a character, naming the register."
-  (interactive "cLayout to register: ")
+Argument is a character, naming the register.
+
+Interactively, reads the register using `register-read-with-preview'."
+  (interactive (list (register-read-with-preview "Layout to register: ")))
   (save-excursion
     (goto-char (point-min))
     (set-register register
@@ -547,8 +542,13 @@ Argument is a character, naming the register."
 
 (defun gametree-apply-register-layout (char)
   "Return to a tree layout stored in a register.
-Argument is a character, naming the register."
-  (interactive "*cApply layout from register: ")
+Argument is a character, naming the register.
+
+Interactively, reads the register using `register-read-with-preview'."
+  (interactive
+   (progn
+     (barf-if-buffer-read-only)
+     (list (register-read-with-preview "Apply layout from register: "))))
   (save-excursion
     (goto-char (point-min))
     (gametree-apply-layout (get-register char) 0 t)))
@@ -556,7 +556,7 @@ Argument is a character, naming the register."
 (defun gametree-save-and-hack-layout ()
   "Save the current tree layout and hack the file local variable spec.
 This function saves the current layout in `gametree-local-layout' and,
-if a local file varible specification for this variable exists in the
+if a local file variable specification for this variable exists in the
 buffer, it is replaced by the new value.  See the documentation for
 `gametree-local-layout' for more information."
   (interactive)
@@ -565,6 +565,20 @@ buffer, it is replaced by the new value.  See the documentation for
     (gametree-hack-file-layout))
   nil)
 
+;;;; Key bindings
+(defvar gametree-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c\C-j" 'gametree-break-line-here)
+    (define-key map "\C-c\C-v" 'gametree-insert-new-leaf)
+    (define-key map "\C-c\C-m" 'gametree-merge-line)
+    (define-key map "\C-c\C-r " 'gametree-layout-to-register)
+    (define-key map "\C-c\C-r/" 'gametree-layout-to-register)
+    (define-key map "\C-c\C-rj" 'gametree-apply-register-layout)
+    (define-key map "\C-c\C-y" 'gametree-save-and-hack-layout)
+    (define-key map "\C-c;" 'gametree-insert-score)
+    (define-key map "\C-c^" 'gametree-compute-and-insert-score)
+    map))
+
 (define-derived-mode gametree-mode outline-mode "GameTree"
   "Major mode for managing game analysis trees.
 Useful to postal and email chess (and, it is hoped, also checkers, go,
@@ -575,18 +589,6 @@ shogi, etc.) players, it is a slightly modified version of Outline mode.
   (make-local-variable 'write-contents-hooks)
   (add-hook 'write-contents-hooks 'gametree-save-and-hack-layout))
 
-;;;; Key bindings
-
-(define-key gametree-mode-map "\C-c\C-j" 'gametree-break-line-here)
-(define-key gametree-mode-map "\C-c\C-v" 'gametree-insert-new-leaf)
-(define-key gametree-mode-map "\C-c\C-m" 'gametree-merge-line)
-(define-key gametree-mode-map "\C-c\C-r " 'gametree-layout-to-register)
-(define-key gametree-mode-map "\C-c\C-r/" 'gametree-layout-to-register)
-(define-key gametree-mode-map "\C-c\C-rj" 'gametree-apply-register-layout)
-(define-key gametree-mode-map "\C-c\C-y" 'gametree-save-and-hack-layout)
-(define-key gametree-mode-map "\C-c;" 'gametree-insert-score)
-(define-key gametree-mode-map "\C-c^" 'gametree-compute-and-insert-score)
-
 ;;;; Goodies for mousing users
 (and (fboundp 'track-mouse)
      (defun gametree-mouse-break-line-here (event)