Mercurial > emacs
comparison lisp/play/gametree.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 0d8b17d428b5 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; gametree.el --- manage game analysis trees in Emacs | 1 ;;; gametree.el --- manage game analysis trees in Emacs |
2 | 2 |
3 ;; Copyright (C) 1997 Free Software Foundation, Inc | 3 ;; Copyright (C) 1997, 1999, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: Ian T Zimmerman <itz@rahul.net> | 6 ;; Author: Ian T Zimmerman <itz@rahul.net> |
6 ;; Created: Wed Dec 10 07:41:46 PST 1997 | 7 ;; Created: Wed Dec 10 07:41:46 PST 1997 |
7 ;; Keywords: games | 8 ;; Keywords: games |
8 | 9 |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 ;; GNU General Public License for more details. | 20 ;; GNU General Public License for more details. |
20 | 21 |
21 ;; You should have received a copy of the GNU General Public License | 22 ;; You should have received a copy of the GNU General Public License |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02110-1301, USA. |
25 | 26 |
26 ;;; Commentary: | 27 ;;; Commentary: |
27 | 28 |
28 ;; This little hack has enabled me to keep track of my email chess | 29 ;; This little hack has enabled me to keep track of my email chess |
29 ;; games in Emacs. For a long time I dreamt about writing a real, | 30 ;; games in Emacs. For a long time I dreamt about writing a real, |
202 (let ((boundary (concat "[ \t]*\\([1-9][0-9]*\\)\\(" | 203 (let ((boundary (concat "[ \t]*\\([1-9][0-9]*\\)\\(" |
203 gametree-full-ply-regexp "\\|" | 204 gametree-full-ply-regexp "\\|" |
204 gametree-half-ply-regexp "\\)")) | 205 gametree-half-ply-regexp "\\)")) |
205 (limit (save-excursion (beginning-of-line 1) (point)))) | 206 (limit (save-excursion (beginning-of-line 1) (point)))) |
206 (if (looking-at boundary) | 207 (if (looking-at boundary) |
207 (+ (* 2 (string-to-int (match-string 1))) | 208 (+ (* 2 (string-to-number (match-string 1))) |
208 (if (string-match gametree-half-ply-regexp (match-string 2)) 1 0)) | 209 (if (string-match gametree-half-ply-regexp (match-string 2)) 1 0)) |
209 (save-excursion | 210 (save-excursion |
210 (re-search-backward boundary limit) | 211 (re-search-backward boundary limit) |
211 (skip-chars-backward "0123456789") | 212 (skip-chars-backward "0123456789") |
212 (1+ (* 2 (string-to-int | 213 (1+ (* 2 (string-to-number |
213 (buffer-substring (point) (match-end 1)))))))))) | 214 (buffer-substring (point) (match-end 1)))))))))) |
214 | 215 |
215 (defun gametree-current-branch-ply () | 216 (defun gametree-current-branch-ply () |
216 "Return the ply number of the first move of the current variation." | 217 "Return the ply number of the first move of the current variation." |
217 (save-excursion | 218 (save-excursion |
343 | 344 |
344 (defun gametree-current-branch-score () | 345 (defun gametree-current-branch-score () |
345 "Return score of current variation according to its score tag. | 346 "Return score of current variation according to its score tag. |
346 When no score tag is present, use the value of `gametree-default-score'." | 347 When no score tag is present, use the value of `gametree-default-score'." |
347 (if (looking-at gametree-score-regexp) | 348 (if (looking-at gametree-score-regexp) |
348 (string-to-int (match-string 3)) | 349 (string-to-number (match-string 3)) |
349 gametree-default-score)) | 350 gametree-default-score)) |
350 | 351 |
351 (defun gametree-compute-reduced-score () | 352 (defun gametree-compute-reduced-score () |
352 "Return current internal node score computed recursively from subnodes. | 353 "Return current internal node score computed recursively from subnodes. |
353 Subnodes which have been manually scored are honored." | 354 Subnodes which have been manually scored are honored." |
571 "Major mode for managing game analysis trees. | 572 "Major mode for managing game analysis trees. |
572 Useful to postal and email chess (and, it is hoped, also checkers, go, | 573 Useful to postal and email chess (and, it is hoped, also checkers, go, |
573 shogi, etc.) players, it is a slightly modified version of Outline mode. | 574 shogi, etc.) players, it is a slightly modified version of Outline mode. |
574 | 575 |
575 \\{gametree-mode-map}" | 576 \\{gametree-mode-map}" |
576 (auto-fill-mode 0) | 577 (auto-fill-mode 0) |
577 (make-variable-buffer-local 'write-contents-hooks) | 578 (make-local-variable 'write-contents-hooks) |
578 (add-hook 'write-contents-hooks 'gametree-save-and-hack-layout)) | 579 (add-hook 'write-contents-hooks 'gametree-save-and-hack-layout)) |
579 | 580 |
580 ;;;; Key bindings | 581 ;;;; Key bindings |
581 | 582 |
582 (define-key gametree-mode-map "\C-c\C-j" 'gametree-break-line-here) | 583 (define-key gametree-mode-map "\C-c\C-j" 'gametree-break-line-here) |
583 (define-key gametree-mode-map "\C-c\C-v" 'gametree-insert-new-leaf) | 584 (define-key gametree-mode-map "\C-c\C-v" 'gametree-insert-new-leaf) |
616 (define-key gametree-mode-map [S-down-mouse-3 S-mouse-3] | 617 (define-key gametree-mode-map [S-down-mouse-3 S-mouse-3] |
617 'gametree-mouse-hide-subtree)) | 618 'gametree-mouse-hide-subtree)) |
618 | 619 |
619 (provide 'gametree) | 620 (provide 'gametree) |
620 | 621 |
622 ;;; arch-tag: aaa30943-9ae4-4cc1-813d-a46f96b7e4f1 | |
621 ;;; gametree.el ends here | 623 ;;; gametree.el ends here |