Merge from trunk
[bpt/emacs.git] / lisp / play / gametree.el
index 45fa1af..cd353d2 100644 (file)
@@ -1,7 +1,6 @@
 ;;; gametree.el --- manage game analysis trees in Emacs
 
-;; Copyright (C) 1997, 1999, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1999, 2001-2011  Free Software Foundation, Inc.
 
 ;; Author: Ian T Zimmerman <itz@rahul.net>
 ;; Created: Wed Dec 10 07:41:46 PST 1997
@@ -9,10 +8,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -94,7 +91,7 @@
   :version "20.3")
 
 (defcustom gametree-half-ply-regexp (regexp-quote ":")
-  "*Matches ends of numbers of moves by the \"second\" player.
+  "Matches ends of numbers of moves by the \"second\" player.
 For instance, it is an almost universal convention in chess to postfix
 numbers of moves by Black (if considered in isolation) by the ellipsis
 \"...\".  This is NOT a good choice for this program, though, because it
@@ -105,20 +102,20 @@ LaTeX macros he uses for typesetting annotated games."
   :group 'gametree)
 
 (defcustom gametree-full-ply-regexp (regexp-quote ".")
-  "*Matches ends of numbers of moves by the \"first\" player.
+  "Matches ends of numbers of moves by the \"first\" player.
 For instance, it is an almost universal convention in chess to postfix
 numbers of moves by White (if considered in isolation) by the dot \".\"."
   :type 'regexp
   :group 'gametree)
 
 (defcustom gametree-half-ply-format "%d:"
-  "*Output format for move numbers of moves by the \"second\" player.
+  "Output format for move numbers of moves by the \"second\" player.
 Has to contain \"%d\" to output the actual number."
   :type 'string
   :group 'gametree)
 
 (defcustom gametree-full-ply-format "%d."
-  "*Output format for move numbers of moves by the \"first\" player.
+  "Output format for move numbers of moves by the \"first\" player.
 Has to contain \"%d\" to output the actual number."
   :type 'string
   :group 'gametree)
@@ -140,17 +137,17 @@ the file is visited (subject to the usual restriction via
 `enable-local-variables'), and the layout will be set accordingly.")
 
 (defcustom gametree-score-opener "{score="
-  "*The string which opens a score tag, and precedes the actual score."
+  "The string which opens a score tag, and precedes the actual score."
   :type 'string
   :group 'gametree)
 
 (defcustom gametree-score-manual-flag "!"
-  "*String marking the line as manually (as opposed to automatically) scored."
+  "String marking the line as manually (as opposed to automatically) scored."
   :type 'string
   :group 'gametree)
 
 (defcustom gametree-score-closer "}"
-  "*The string which closes a score tag, and follows the actual score."
+  "The string which closes a score tag, and follows the actual score."
   :type 'string
   :group 'gametree)
 
@@ -162,7 +159,7 @@ the file is visited (subject to the usual restriction via
           "[   ]*\\)?\\([-+]?[0-9]+\\)"
           (regexp-quote gametree-score-closer)
           "[   ]*\\)[\n\^M]")
-  "*Regular expression matching lines that guide the program in scoring.
+  "Regular expression matching lines that guide the program in scoring.
 Its third parenthetical group should match the actual score.  Its
 first parenthetical group should match the entire score tag.  Its
 second parenthetical group should be an optional flag that marks the
@@ -174,7 +171,7 @@ score instead."
   :group 'gametree)
 
 (defcustom gametree-default-score 0
-  "*Score to assume for branches lacking score tags."
+  "Score to assume for branches lacking score tags."
   :type 'integer
   :group 'gametree)
 \f
@@ -203,7 +200,7 @@ should be no leading white space."
     (let ((boundary (concat "[ \t]*\\([1-9][0-9]*\\)\\("
                             gametree-full-ply-regexp "\\|"
                             gametree-half-ply-regexp "\\)"))
-          (limit (save-excursion (beginning-of-line 1) (point))))
+          (limit (line-beginning-position 1)))
       (if (looking-at boundary)
           (+ (* 2 (string-to-number (match-string 1)))
              (if (string-match gametree-half-ply-regexp (match-string 2)) 1 0))
@@ -568,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,
@@ -578,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)
@@ -619,5 +618,4 @@ shogi, etc.) players, it is a slightly modified version of Outline mode.
 
 (provide 'gametree)
 
-;;; arch-tag: aaa30943-9ae4-4cc1-813d-a46f96b7e4f1
 ;;; gametree.el ends here