;;; gametree.el --- manage game analysis trees in Emacs
-;; Copyright (C) 1997, 1999, 2001-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1999, 2001-2013 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
gametree-half-ply-regexp)) limit))
(goto-char (match-beginning 0))))
(gametree-transpose-following-leaves)
- (let* ((pt (set-marker (make-marker) (point)))
+ (let* ((pt (point-marker))
(plys (gametree-current-branch-ply))
(depth (gametree-current-branch-depth))
(old-depth depth))
(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)