;;; gametree.el --- manage game analysis trees in Emacs
-;; Copyright (C) 1997, 1999, 2001-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1999, 2001-2014 Free Software Foundation, Inc.
;; Author: Ian T Zimmerman <itz@rahul.net>
;; Created: Wed Dec 10 07:41:46 PST 1997
(defun gametree-children-shown-p ()
(save-excursion
- (condition-case nil
+ (ignore-errors
(let ((depth (gametree-current-branch-depth)))
(outline-next-visible-heading 1)
- (< depth (gametree-current-branch-depth)))
- (error nil))))
+ (< depth (gametree-current-branch-depth))))))
-(defun gametree-current-layout (depth &optional top-level)
+(defun gametree-current-layout (depth &optional from-top-level)
(let ((layout nil) (first-time t))
(while (save-excursion
- (condition-case nil
- (progn
- (or (and first-time top-level
- (bolp) (looking-at outline-regexp))
- (setq first-time nil)
- (outline-next-visible-heading 1))
- (< depth (gametree-current-branch-depth)))
- (error nil)))
+ (ignore-errors
+ (or (and first-time from-top-level
+ (bolp) (looking-at outline-regexp))
+ (setq first-time nil)
+ (outline-next-visible-heading 1))
+ (< depth (gametree-current-branch-depth))))
(if (not first-time)
(outline-next-visible-heading 1))
(setq first-time nil)
(goto-char (point-min))
(setq gametree-local-layout (gametree-current-layout 0 t))))
-(defun gametree-apply-layout (layout depth &optional top-level)
+(defun gametree-apply-layout (layout depth &optional from-top-level)
(let ((first-time t))
(while (and layout
(save-excursion
- (condition-case nil
- (progn
- (or (and first-time top-level
- (bolp) (looking-at outline-regexp))
- (setq first-time nil)
- (outline-next-visible-heading 1))
- (< depth (gametree-current-branch-depth)))
- (error nil))))
+ (ignore-errors
+ (or (and first-time from-top-level
+ (bolp) (looking-at outline-regexp))
+ (setq first-time nil)
+ (outline-next-visible-heading 1))
+ (< depth (gametree-current-branch-depth)))))
(if (not first-time)
(outline-next-visible-heading 1))
(setq first-time nil)
(while (not done) ;handle subheadings
(setq running (funcall minmax running
(gametree-compute-reduced-score)))
- (setq done (condition-case nil
- (outline-forward-same-level 1)
- (error nil)))))
+ (setq done (ignore-errors (outline-forward-same-level 1)))))
running)))))
\f
;;;; Commands
(error
(goto-char (point-max))
(if (not (bolp)) (insert "\n"))))
- (let ((starting-plys
+ (let ((starting-plies
(if (> (gametree-current-branch-depth) parent-depth)
(gametree-current-branch-ply)
(save-excursion (forward-line -1)
(gametree-current-branch-ply)))))
(goto-char (1- (point)))
(insert "\n")
- (insert (format (if (= 0 (mod starting-plys 2))
+ (insert (format (if (= 0 (mod starting-plies 2))
gametree-full-ply-format
gametree-half-ply-format)
- (/ starting-plys 2))))))
+ (/ starting-plies 2))))))
(defun gametree-break-line-here (&optional at-move)
"Split the variation node at the point position.
This command works whether the current variation node is a leaf, or is
already branching at its end. The new node is created at a level that
-reflects the number of game plys between the beginning of the current
+reflects the number of game plies between the beginning of the current
variation and the breaking point.
With a numerical argument AT-MOVE, split the variation before
gametree-half-ply-regexp)) limit))
(goto-char (match-beginning 0))))
(gametree-transpose-following-leaves)
- (let* ((pt (set-marker (make-marker) (point)))
- (plys (gametree-current-branch-ply))
+ (let* ((pt (point-marker))
+ (plies (gametree-current-branch-ply))
(depth (gametree-current-branch-depth))
(old-depth depth))
(if (= depth 0)
(if (zerop old-branch-ply)
(1+ (gametree-current-branch-depth))
(+ (gametree-current-branch-depth)
- (- plys old-branch-ply))))))
+ (- plies old-branch-ply))))))
(save-excursion
(beginning-of-line 1)
(funcall gametree-make-heading-function depth)
(insert "\n")
(if (not (= 0 old-depth))
(funcall gametree-make-heading-function
- (+ depth (- (gametree-current-branch-ply) plys))))
+ (+ depth (- (gametree-current-branch-ply) plies))))
(gametree-prettify-heading))))
(defun gametree-merge-line ()
(defun gametree-layout-to-register (register)
"Store current tree layout in register REGISTER.
Use \\[gametree-apply-register-layout] to restore that configuration.
-Argument is a character, naming the register."
- (interactive "cLayout to register: ")
+Argument is a character, naming the register.
+
+Interactively, reads the register using `register-read-with-preview'."
+ (interactive (list (register-read-with-preview "Layout to register: ")))
(save-excursion
(goto-char (point-min))
(set-register register
(defun gametree-apply-register-layout (char)
"Return to a tree layout stored in a register.
-Argument is a character, naming the register."
- (interactive "*cApply layout from register: ")
+Argument is a character, naming the register.
+
+Interactively, reads the register using `register-read-with-preview'."
+ (interactive
+ (progn
+ (barf-if-buffer-read-only)
+ (list (register-read-with-preview "Apply layout from register: "))))
(save-excursion
(goto-char (point-min))
(gametree-apply-layout (get-register char) 0 t)))
(defun gametree-save-and-hack-layout ()
"Save the current tree layout and hack the file local variable spec.
This function saves the current layout in `gametree-local-layout' and,
-if a local file varible specification for this variable exists in the
+if a local file variable specification for this variable exists in the
buffer, it is replaced by the new value. See the documentation for
`gametree-local-layout' for more information."
(interactive)
(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,
(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)