annotate lisp/play/gametree.el @ 34731:25147a856fd9

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Wed, 20 Dec 2000 11:06:36 +0000
parents b7d8faf8cca0
children 0d8b17d428b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; gametree.el --- manage game analysis trees in Emacs
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1997 Free Software Foundation, Inc
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Ian T Zimmerman <itz@rahul.net>
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Created: Wed Dec 10 07:41:46 PST 1997
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: games
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; This little hack has enabled me to keep track of my email chess
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; games in Emacs. For a long time I dreamt about writing a real,
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; graphical tree editor; but, then the idea struck me, why do it
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; graphically, when it can be done in Emacs? :-) And in fact Emacs
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; almost had what I needed out of the box, namely the powerful
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; Outline mode. This code is built entirely on Outline mode, it
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; only adds two commands that I found indispensable when dealing
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; with the special kind of trees that analysis trees comprise.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; The built-in documentation should be enough to explain the use,
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; along with the following example (yes, this is a real game).
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; *** 23. f4 ef 24. Nf3 Rf3 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; 25. Rf3 Qh2 26. Kh1 Qh1 27. Ke2 Qg2 -+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; ******* 25. gf3 Nce3 26. Qe2 Nf1 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; 27. Qe5 Ne5 28. Kf1 Nf3 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; 27. Kf1 Nh2 28. Kf2 Ng4 29. fg4 Rf8 30. Ke1 Qg3 31. Kd1 Rf2 -+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; Place the preceding in a scratch buffer, load this code, and do
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; M-x gametree-mode. Now place the cursor just after the `Nf3' and
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; before the `Rf3' on the first line, and do C-c C-j. The result is
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; *** 23. f4 ef 24. Nf3
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; ****** 24: Rf3 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; 25. Rf3 Qh2 26. Kh1 Qh1 27. Ke2 Qg2 -+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; ******* 25. gf3 Nce3 26. Qe2 Nf1 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; 27. Qe5 Ne5 28. Kf1 Nf3 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; 27. Kf1 Nh2 28. Kf2 Ng4 29. fg4 Rf8 30. Ke1 Qg3 31. Kd1 Rf2 -+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; Now you can add another subvariation on Black's 24th move: with
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; the cursor still on the first line, do C-c C-v, and voila
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; *** 23. f4 ef 24. Nf3
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; 24:
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; ****** 24: Rf3 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; 25. Rf3 Qh2 26. Kh1 Qh1 27. Ke2 Qg2 -+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; ******* 25. gf3 Nce3 26. Qe2 Nf1 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; 27. Qe5 Ne5 28. Kf1 Nf3 -/+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; 27. Kf1 Nh2 28. Kf2 Ng4 29. fg4 Rf8 30. Ke1 Qg3 31. Kd1 Rf2 -+
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; and the cursor is positioned on the new line just after the move
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; number, so you can start typing the new analysis. That's it,
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
70 ;; quite simple.
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
72 ;; As of version 1.1, a simple score reducer has been implemented.
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
73 ;; As you type in leaf variations, you can add a numerical score tag
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
74 ;; to them with C-c ; . Then, with the cursor on a variation higher
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
75 ;; up in the tree, you can do C-c ^ and the program will compute the
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
76 ;; reduced score of the internal variation based on the scores of its
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
77 ;; children (which are recursively computed). You can use any range
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
78 ;; of numbers you wish as scores, maybe -1000 to 1000 or 0 to 100,
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
79 ;; all that matters to the program is that higher means better for
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
80 ;; White, lower means better for Black.
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;;; Code:
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (require 'derived)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (require 'outline)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;;; Configuration variables
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
89 (defgroup gametree nil
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
90 "Manage game analysis trees in Emacs."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
91 :prefix "gametree-"
21651
86fcccceba7b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 21363
diff changeset
92 :group 'games
86fcccceba7b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 21363
diff changeset
93 :version "20.3")
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
94
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
95 (defcustom gametree-half-ply-regexp (regexp-quote ":")
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 "*Matches ends of numbers of moves by the \"second\" player.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 For instance, it is an almost universal convention in chess to postfix
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 numbers of moves by Black (if considered in isolation) by the ellipsis
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 \"...\". This is NOT a good choice for this program, though, because it
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 conflicts with the use of ellipsis by Outline mode to denote collapsed
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 subtrees. The author uses \":\" because it agrees nicely with a set of
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
102 LaTeX macros he uses for typesetting annotated games."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
103 :type 'regexp
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
104 :group 'gametree)
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
106 (defcustom gametree-full-ply-regexp (regexp-quote ".")
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 "*Matches ends of numbers of moves by the \"first\" player.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 For instance, it is an almost universal convention in chess to postfix
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
109 numbers of moves by White (if considered in isolation) by the dot \".\"."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
110 :type 'regexp
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
111 :group 'gametree)
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
113 (defcustom gametree-half-ply-format "%d:"
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
114 "*Output format for move numbers of moves by the \"second\" player.
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
115 Has to contain \"%d\" to output the actual number."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
116 :type 'string
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
117 :group 'gametree)
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
118
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
119 (defcustom gametree-full-ply-format "%d."
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 "*Output format for move numbers of moves by the \"first\" player.
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
121 Has to contain \"%d\" to output the actual number."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
122 :type 'string
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
123 :group 'gametree)
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
125 (defcustom gametree-make-heading-function
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (function (lambda (level)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (insert (make-string level ?*))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 "A function of one numeric argument, LEVEL, to insert a heading at point.
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
129 You should change this if you change `outline-regexp'."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
130 :type 'function
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20782
diff changeset
131 :group 'gametree)
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (defvar gametree-local-layout nil
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 "A list encoding the layout (i.e. the show or hide state) of the file.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 If Emacs notices a local variable specification of this variable in
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 the first line of the buffer while saving the buffer to the visited
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 file, the local value will be saved there and restored the next time
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 the file is visited (subject to the usual restriction via
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 `enable-local-variables'), and the layout will be set accordingly.")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
24226
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
141 (defcustom gametree-score-opener "{score="
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
142 "*The string which opens a score tag, and precedes the actual score."
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
143 :type 'string
24227
b7d8faf8cca0 Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 24226
diff changeset
144 :group 'gametree)
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
145
24226
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
146 (defcustom gametree-score-manual-flag "!"
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
147 "*String marking the line as manually (as opposed to automatically) scored."
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
148 :type 'string
24227
b7d8faf8cca0 Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 24226
diff changeset
149 :group 'gametree)
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
150
24226
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
151 (defcustom gametree-score-closer "}"
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
152 "*The string which closes a score tag, and follows the actual score."
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
153 :type 'string
24227
b7d8faf8cca0 Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 24226
diff changeset
154 :group 'gametree)
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
155
24226
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
156 (defcustom gametree-score-regexp
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
157 (concat "[^\n\^M]*\\("
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
158 (regexp-quote gametree-score-opener)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
159 "[ ]*\\("
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
160 (regexp-quote gametree-score-manual-flag)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
161 "[ ]*\\)?\\([-+]?[0-9]+\\)"
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
162 (regexp-quote gametree-score-closer)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
163 "[ ]*\\)[\n\^M]")
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
164 "*Regular expression matching lines that guide the program in scoring.
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
165 Its third parenthetical group should match the actual score. Its
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
166 first parenthetical group should match the entire score tag. Its
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
167 second parenthetical group should be an optional flag that marks the
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
168 line as *manually* (as opposed to automatically) scored, which
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
169 prevents the program from recursively applying the scoring algorithm
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
170 on the subtree headed by the marked line, and makes it use the manual
24226
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
171 score instead."
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
172 :type 'regexp
24227
b7d8faf8cca0 Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 24226
diff changeset
173 :group 'gametree)
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
174
24226
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
175 (defcustom gametree-default-score 0
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
176 "*Score to assume for branches lacking score tags."
8328255eab2a (gametree-default-score): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 24225
diff changeset
177 :type 'integer
24227
b7d8faf8cca0 Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 24226
diff changeset
178 :group 'gametree)
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
179
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;;;; Helper functions
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (defun gametree-prettify-heading ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 "Insert/delete space between leading asterisks and heading text.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 If the current variation is an internal node (i.e. starts with one or
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 more asterisks), ensure there's at least one space between the
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 asterisks and the text. If on the other hand this is a leaf, there
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 should be no leading white space."
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (beginning-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (if (re-search-forward (concat "\\=" outline-regexp) nil t)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (if (not (looking-at "[ \t]+")) (insert " "))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (delete-char (save-excursion (skip-chars-forward " \t"))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (if (re-search-forward (concat "\\=[ \t]*[1-9][0-9]*\\("
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 gametree-full-ply-regexp "\\|"
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 gametree-half-ply-regexp "\\)") nil t)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (if (not (looking-at "[ \t]+")) (insert " ")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (delete-char (1- (save-excursion (skip-chars-forward " \t"))))))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (defun gametree-looking-at-ply ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 "Read and return the number of the ply under point."
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (if (eobp) 0
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (let ((boundary (concat "[ \t]*\\([1-9][0-9]*\\)\\("
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 gametree-full-ply-regexp "\\|"
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 gametree-half-ply-regexp "\\)"))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (limit (save-excursion (beginning-of-line 1) (point))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (if (looking-at boundary)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (+ (* 2 (string-to-int (match-string 1)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (if (string-match gametree-half-ply-regexp (match-string 2)) 1 0))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (re-search-backward boundary limit)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (skip-chars-backward "0123456789")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (1+ (* 2 (string-to-int
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (buffer-substring (point) (match-end 1))))))))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (defun gametree-current-branch-ply ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 "Return the ply number of the first move of the current variation."
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (beginning-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (re-search-forward (concat "\\=" outline-regexp) nil t)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (gametree-looking-at-ply)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
222 (defsubst gametree-forward-line ()
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
223 (re-search-forward "[\n\^M]" nil 'move))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
224
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (defun gametree-current-branch-depth ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 "Return the depth of the current variation in the analysis tree.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 This value is simply the outline heading level of the current line."
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (beginning-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (if (looking-at outline-regexp)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (outline-level) 0)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
233 (defun gametree-transpose-following-leaves ()
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
234 "Move the current leaf variation behind all others on the same level."
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
235 (let ((following-leaves
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
236 (save-excursion
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
237 (gametree-forward-line)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
238 (let ((p (point)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
239 (while (and (not (eobp))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
240 (= 0 (gametree-current-branch-depth)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
241 (gametree-forward-line))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
242 (prog1 (buffer-substring p (point))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
243 (delete-region p (point)))))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
244 (save-excursion
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
245 (beginning-of-line 1)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
246 (insert following-leaves))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
247
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
248
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 ;;;; Functions related to the task of saving and restoring current
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ;;;; outline layout
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
252 (defsubst gametree-show-children-and-entry ()
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (show-children)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (show-entry))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (defun gametree-entry-shown-p ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (forward-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (and (bolp) (not (eobp)) (not (looking-at outline-regexp)))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (defun gametree-children-shown-p ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (condition-case nil
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (let ((depth (gametree-current-branch-depth)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (outline-next-visible-heading 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (< depth (gametree-current-branch-depth)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (error nil))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (defun gametree-current-layout (depth &optional top-level)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (let ((layout nil) (first-time t))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (while (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (condition-case nil
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (progn
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (or (and first-time top-level
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (bolp) (looking-at outline-regexp))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (setq first-time nil)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (outline-next-visible-heading 1))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (< depth (gametree-current-branch-depth)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (error nil)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (if (not first-time)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (outline-next-visible-heading 1))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (setq first-time nil)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (if (not (gametree-children-shown-p))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (setq layout
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (nconc layout
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (if (gametree-entry-shown-p)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (list 'show-entry)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (list nil))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (setq layout (nconc layout (if (gametree-entry-shown-p)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (list 'gametree-show-children-and-entry)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (list 'show-children))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (let ((sub-layout
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (gametree-current-layout (gametree-current-branch-depth))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (setq layout (nconc layout (list sub-layout))))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 layout))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (defun gametree-save-layout ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (goto-char (point-min))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (setq gametree-local-layout (gametree-current-layout 0 t))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (defun gametree-apply-layout (layout depth &optional top-level)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (let ((first-time t))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (while (and layout
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (condition-case nil
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (progn
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (or (and first-time top-level
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (bolp) (looking-at outline-regexp))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (setq first-time nil)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (outline-next-visible-heading 1))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (< depth (gametree-current-branch-depth)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (error nil))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (if (not first-time)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (outline-next-visible-heading 1))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (setq first-time nil)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (hide-subtree)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (if (nth 0 layout)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (funcall (nth 0 layout)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (if (not (and (nth 1 layout) (listp (nth 1 layout))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (setq layout (cdr layout))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (gametree-apply-layout (nth 1 layout)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (gametree-current-branch-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (setq layout (cdr (cdr layout)))))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (defun gametree-restore-layout ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (goto-char (point-min))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (gametree-apply-layout gametree-local-layout 0 t)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (defun gametree-hack-file-layout ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (goto-char (point-min))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (if (looking-at "[^\n]*-\*-[^\n]*gametree-local-layout: \\([^;\n]*\\);")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (progn
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (goto-char (match-beginning 1))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (delete-region (point) (match-end 1))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (let ((standard-output (current-buffer)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (princ gametree-local-layout))))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
341
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
342 ;;;; Scoring functions
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
343
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
344 (defun gametree-current-branch-score ()
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
345 "Return score of current variation according to its score tag.
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
346 When no score tag is present, use the value of `gametree-default-score'."
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
347 (if (looking-at gametree-score-regexp)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
348 (string-to-int (match-string 3))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
349 gametree-default-score))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
350
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
351 (defun gametree-compute-reduced-score ()
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
352 "Return current internal node score computed recursively from subnodes.
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
353 Subnodes which have been manually scored are honored."
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
354 (if (or
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
355 (= 0 (gametree-current-branch-depth))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
356 (save-excursion (gametree-forward-line) (eobp))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
357 (and (looking-at gametree-score-regexp)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
358 (not (null (match-string 2)))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
359 (gametree-current-branch-score)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
360 (let ((depth (gametree-current-branch-depth)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
361 (save-excursion
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
362 (gametree-forward-line)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
363 ;; the case of a leaf node has already been handled, so here I
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
364 ;; know I am on the 1st line of the current subtree. This can
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
365 ;; be either a leaf child, or a subheading.
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
366 (let ((running gametree-default-score)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
367 (minmax
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
368 (if (= 0 (mod (gametree-current-branch-ply) 2))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
369 'max 'min)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
370 (while (and (not (eobp))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
371 (= 0 (gametree-current-branch-depth))) ;handle leaves
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
372 (setq running (funcall minmax running
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
373 (gametree-current-branch-score)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
374 (gametree-forward-line))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
375 (let ((done (and (not (eobp))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
376 (< depth (gametree-current-branch-depth)))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
377 (while (not done) ;handle subheadings
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
378 (setq running (funcall minmax running
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
379 (gametree-compute-reduced-score)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
380 (setq done (condition-case nil
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
381 (outline-forward-same-level 1)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
382 (error nil)))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
383 running)))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
384
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 ;;;; Commands
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (defun gametree-insert-new-leaf (&optional at-depth)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 "Start a new leaf variation under the current branching point.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 The new variation can later be split to be a branching point itself,
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 with \\[gametree-break-line-here]. If the point is currently on a
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 leaf variation, this command won't work; use \\[gametree-break-line-here]
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 on the current line first.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 With a numeric arg AT-DEPTH, first go up the tree until a node of
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 depth AT-DEPTH or smaller is found."
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
396 (interactive "*P")
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (if (zerop (gametree-current-branch-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (outline-up-heading 0))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (if at-depth
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (while (> (gametree-current-branch-depth)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (prefix-numeric-value at-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (outline-up-heading 1)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (beginning-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (let ((parent-depth (gametree-current-branch-depth)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (show-entry)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (condition-case nil
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (outline-next-visible-heading 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (error
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (goto-char (point-max))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (if (not (bolp)) (insert "\n"))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (let ((starting-plys
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (if (> (gametree-current-branch-depth) parent-depth)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (gametree-current-branch-ply)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (save-excursion (forward-line -1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (gametree-current-branch-ply)))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (goto-char (1- (point)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (insert "\n")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (insert (format (if (= 0 (mod starting-plys 2))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 gametree-full-ply-format
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 gametree-half-ply-format)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (/ starting-plys 2))))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (defun gametree-break-line-here (&optional at-move)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 "Split the variation node at the point position.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 This command works whether the current variation node is a leaf, or is
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 already branching at its end. The new node is created at a level that
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 reflects the number of game plys between the beginning of the current
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 variation and the breaking point.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 With a numerical argument AT-MOVE, split the variation before
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 White's AT-MOVEth move, or Black's if negative. The last option will
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 only work of Black's moves are explicitly numbered, for instance
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 `1. e4 1: e5'."
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
434 (interactive "*P")
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (if at-move (progn
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (end-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (let ((limit (point)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (beginning-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (re-search-forward
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (concat
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (regexp-quote
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (int-to-string (abs (prefix-numeric-value at-move))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (if (> at-move 0) gametree-full-ply-regexp
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 gametree-half-ply-regexp)) limit))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (goto-char (match-beginning 0))))
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
446 (gametree-transpose-following-leaves)
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (let* ((pt (set-marker (make-marker) (point)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (plys (gametree-current-branch-ply))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (depth (gametree-current-branch-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (old-depth depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (if (= depth 0)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (progn
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (outline-previous-visible-heading 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (setq depth
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (let ((old-branch-ply
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (condition-case nil
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (gametree-current-branch-ply)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (error 0))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (if (zerop old-branch-ply)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (1+ (gametree-current-branch-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (+ (gametree-current-branch-depth)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (- plys old-branch-ply))))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (beginning-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (funcall gametree-make-heading-function depth)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (gametree-prettify-heading))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (if (not (looking-at (concat "[ \t]*[1-9][0-9]*\\("
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 gametree-full-ply-regexp "\\|"
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 gametree-half-ply-regexp "\\)")))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (progn
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (insert (format (if (= 0 (mod (gametree-looking-at-ply) 2))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 gametree-full-ply-format
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 gametree-half-ply-format)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (/ (gametree-looking-at-ply) 2)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (gametree-prettify-heading)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (beginning-of-line 1)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (goto-char pt)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (insert "\n")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (if (not (= 0 old-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (funcall gametree-make-heading-function
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (+ depth (- (gametree-current-branch-ply) plys))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (gametree-prettify-heading))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (defun gametree-merge-line ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 "Merges a variation with its only child.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 Does *not* check if the variation has in fact a unique child; users beware."
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
489 (interactive "*")
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (if (zerop (gametree-current-branch-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (outline-up-heading 0))
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
492 (if (looking-at gametree-score-regexp)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
493 (delete-region (match-beginning 1) (match-end 1)))
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (end-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (let ((prev-depth (save-excursion (forward-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (gametree-current-branch-depth))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (delete-char (1+ prev-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (if (zerop prev-depth)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (beginning-of-line 1)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (delete-char (gametree-current-branch-depth))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (gametree-prettify-heading)))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
504 (defun gametree-insert-score (score &optional auto)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
505 "Insert a score tag with value SCORE at the end of the current line.
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
506 If this line already has a score tag, just jump to it and alter it.
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
507 When called from a program, optional AUTO flag tells if the score is
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
508 being entered automatically (and thus should lack the manual mark)."
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
509 (interactive "*P")
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
510 (beginning-of-line 1)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
511 (if (looking-at gametree-score-regexp)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
512 (progn
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
513 (goto-char (match-beginning 3))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
514 (if (and auto (not (null (match-string 2))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
515 (delete-region (match-beginning 2) (match-end 2)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
516 (if (not (null score))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
517 (delete-region (match-beginning 3) (match-end 3)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
518 (if (and (not auto) (null (match-string 2)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
519 (insert gametree-score-manual-flag)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
520 (end-of-line 1)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
521 (if (= 0 (save-excursion (skip-chars-backward " \t")))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
522 (insert " "))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
523 (insert gametree-score-opener)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
524 (if (not auto) (insert gametree-score-manual-flag))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
525 (save-excursion (insert gametree-score-closer)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
526 (if (not (null score))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
527 (save-excursion
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
528 (insert (int-to-string (prefix-numeric-value score))))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
529
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
530 (defun gametree-compute-and-insert-score ()
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
531 "Compute current node score, maybe recursively from subnodes. Insert it.
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
532 Subnodes which have been manually scored are honored."
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
533 (interactive "*")
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
534 (let ((auto (not (and (looking-at gametree-score-regexp)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
535 (not (null (match-string 2))))))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
536 (score (gametree-compute-reduced-score)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
537 (gametree-insert-score score auto)))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
538
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
539
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (defun gametree-layout-to-register (register)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 "Store current tree layout in register REGISTER.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 Use \\[gametree-apply-register-layout] to restore that configuration.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 Argument is a character, naming the register."
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (interactive "cLayout to register: ")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (goto-char (point-min))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (set-register register
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (gametree-current-layout 0 t))))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (defun gametree-apply-register-layout (char)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 "Return to a tree layout stored in a register.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 Argument is a character, naming the register."
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
553 (interactive "*cApply layout from register: ")
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (save-excursion
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (goto-char (point-min))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (gametree-apply-layout (get-register char) 0 t)))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (defun gametree-save-and-hack-layout ()
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 "Save the current tree layout and hack the file local variable spec.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 This function saves the current layout in `gametree-local-layout' and,
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 if a local file varible specification for this variable exists in the
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 buffer, it is replaced by the new value. See the documentation for
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 `gametree-local-layout' for more information."
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (interactive)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (gametree-save-layout)
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
566 (let ((inhibit-read-only t))
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
567 (gametree-hack-file-layout))
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 nil)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (define-derived-mode gametree-mode outline-mode "GameTree"
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 "Major mode for managing game analysis trees.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 Useful to postal and email chess (and, it is hoped, also checkers, go,
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 shogi, etc.) players, it is a slightly modified version of Outline mode.
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 \\{gametree-mode-map}"
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (auto-fill-mode 0)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 (make-variable-buffer-local 'write-contents-hooks)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (add-hook 'write-contents-hooks 'gametree-save-and-hack-layout))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 ;;;; Key bindings
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (define-key gametree-mode-map "\C-c\C-j" 'gametree-break-line-here)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 (define-key gametree-mode-map "\C-c\C-v" 'gametree-insert-new-leaf)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (define-key gametree-mode-map "\C-c\C-m" 'gametree-merge-line)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 (define-key gametree-mode-map "\C-c\C-r " 'gametree-layout-to-register)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (define-key gametree-mode-map "\C-c\C-r/" 'gametree-layout-to-register)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (define-key gametree-mode-map "\C-c\C-rj" 'gametree-apply-register-layout)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (define-key gametree-mode-map "\C-c\C-y" 'gametree-save-and-hack-layout)
24225
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
589 (define-key gametree-mode-map "\C-c;" 'gametree-insert-score)
985eb547550f Document scoring functionality.
Richard M. Stallman <rms@gnu.org>
parents: 21651
diff changeset
590 (define-key gametree-mode-map "\C-c^" 'gametree-compute-and-insert-score)
20782
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 ;;;; Goodies for mousing users
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 (and (fboundp 'track-mouse)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (defun gametree-mouse-break-line-here (event)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (interactive "e")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (mouse-set-point event)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 (gametree-break-line-here))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (defun gametree-mouse-show-children-and-entry (event)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (interactive "e")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (mouse-set-point event)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (gametree-show-children-and-entry))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (defun gametree-mouse-show-subtree (event)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (interactive "e")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (mouse-set-point event)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (show-subtree))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (defun gametree-mouse-hide-subtree (event)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 (interactive "e")
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (mouse-set-point event)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 (hide-subtree))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (define-key gametree-mode-map [M-down-mouse-2 M-mouse-2]
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 'gametree-mouse-break-line-here)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (define-key gametree-mode-map [S-down-mouse-1 S-mouse-1]
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 'gametree-mouse-show-children-and-entry)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (define-key gametree-mode-map [S-down-mouse-2 S-mouse-2]
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 'gametree-mouse-show-subtree)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 (define-key gametree-mode-map [S-down-mouse-3 S-mouse-3]
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 'gametree-mouse-hide-subtree))
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (provide 'gametree)
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620
8a36e43748c0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 ;;; gametree.el ends here