diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-14 23:07:06 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-14 23:07:06 +0000 |
| commit | db5b94f367aebaeb019b46b2e2feb9f366d5d964 (patch) | |
| tree | 51fcd68cc026f631a7a50efa8795be46d340469d | |
| parent | 4aa1c73a2e77af7bcf1bd24837c9f07488068cdd (diff) | |
*** no comment ***
| -rw-r--r-- | TODO | 3 | ||||
| -rw-r--r-- | chess-database.el | 2 | ||||
| -rw-r--r-- | chess-display.el | 5 | ||||
| -rw-r--r-- | chess-engine.el | 3 | ||||
| -rw-r--r-- | chess-file.el | 6 | ||||
| -rw-r--r-- | chess-none.el | 3 | ||||
| -rw-r--r-- | chess-pgn.el | 71 | ||||
| -rw-r--r-- | chess.el | 6 |
8 files changed, 84 insertions, 15 deletions
@@ -34,6 +34,9 @@ configuration! - in chess-engine-filter and chess-ics-filter, if an error is encountered, skip that line so the same error isn't triggered again +- SPACE to pass, then try to move (against an engine) fails saying + it's not our turn to move + ---------------------------------------------------------------------- - Add support for adjournments; also, implement this is such a way diff --git a/chess-database.el b/chess-database.el index b3aefc0..c7a27c4 100644 --- a/chess-database.el +++ b/chess-database.el @@ -16,7 +16,7 @@ ,@body))) (chess-message-catalog 'english - '((no-such-style . "There is no such chess database module '%s'"))) + '((no-such-database . "There is no such chess database module '%s'"))) (defun chess-database-open (module file) "Returns the opened database object, or nil." diff --git a/chess-display.el b/chess-display.el index 432f959..768ed72 100644 --- a/chess-display.el +++ b/chess-display.el @@ -81,7 +81,8 @@ makes moves, or any other changes to the underlying game." (with-current-buffer (generate-new-buffer "*Chessboard*") (setq buffer (current-buffer)) (chess-display-mode read-only) - (when (setq buffer (funcall handler 'initialize)) + (if (null (setq buffer (funcall handler 'initialize))) + (kill-buffer buffer) (add-hook 'kill-buffer-hook 'chess-display-quit nil t) (setq chess-display-style style chess-display-perspective perspective @@ -221,7 +222,7 @@ modeline." (defun chess-display-set-index (display index) (chess-with-current-buffer display (chess-display-set-index* nil index) - (chess-display-update nil))) + (chess-display-update nil t))) (defsubst chess-display-index (display) (chess-with-current-buffer display diff --git a/chess-engine.el b/chess-engine.el index be48270..ed80570 100644 --- a/chess-engine.el +++ b/chess-engine.el @@ -266,7 +266,8 @@ (with-current-buffer (generate-new-buffer " *chess-engine*") (setq buffer (current-buffer)) (let ((proc (apply handler 'initialize handler-ctor-args))) - (when proc ;must be a process or t + (if (null proc) ; must be a process or t + (kill-buffer buffer) (add-hook 'kill-buffer-hook 'chess-engine-on-kill nil t) (setq chess-engine-regexp-alist (symbol-value regexp-alist) chess-engine-event-handler handler diff --git a/chess-file.el b/chess-file.el index 9667c06..dacf6b3 100644 --- a/chess-file.el +++ b/chess-file.el @@ -22,7 +22,8 @@ (setq chess-file-locations nil) (while (search-forward "[Event" nil t) (goto-char (match-beginning 0)) - (push (point) chess-file-locations)) + (push (point) chess-file-locations) + (forward-char 1)) (setq chess-file-locations (nreverse chess-file-locations))) ((eq event 'save) @@ -40,7 +41,8 @@ (chess-game-set-data game 'database (current-buffer)) (chess-game-set-data game 'database-index index) (chess-game-set-data game 'database-count - (chess-file-handler 'count)))))) + (chess-file-handler 'count)) + game)))) ((eq event 'write) (goto-char (point-max)) diff --git a/chess-none.el b/chess-none.el index edd2a29..5494cf1 100644 --- a/chess-none.el +++ b/chess-none.el @@ -13,7 +13,8 @@ case this engine will do the job of accepting undos, handling resignations, etc." (cond ((memq event '(resign abort)) - (chess-engine-set-position nil)) + (chess-engine-set-position nil) + t) ((eq event 'undo) (chess-game-undo chess-engine-game (car args))))) diff --git a/chess-pgn.el b/chess-pgn.el index f9fc5c3..874e467 100644 --- a/chess-pgn.el +++ b/chess-pgn.el @@ -167,9 +167,16 @@ If INDENTED is non-nil, indent the move texts." ;; chess-pgn-mode for editing and browsing PGN files. ;; +(require 'chess-database) +(require 'chess-file) + (defvar chess-pgn-database) +(defvar chess-pgn-display) +(defvar chess-pgn-current-game) (make-variable-buffer-local 'chess-pgn-database) +(make-variable-buffer-local 'chess-pgn-display) +(make-variable-buffer-local 'chess-pgn-current-game) ;;;###autoload (define-derived-mode chess-pgn-mode text-mode "PGN" @@ -179,6 +186,8 @@ If INDENTED is non-nil, indent the move texts." (modify-syntax-entry ?\{ "<") (modify-syntax-entry ?\} ">") (modify-syntax-entry ?\" "\"") + (if (fboundp 'font-lock-mode) + (font-lock-mode 1)) (let ((map (current-local-map))) (define-key map [??] 'describe-mode) (define-key map [?T] 'text-mode) @@ -190,13 +199,14 @@ If INDENTED is non-nil, indent the move texts." (defvar chess-pgn-bold-face 'bold) +(defconst chess-pgn-move-regexp + (concat "[^0-9]\\(\\([1-9][0-9]*\\)\\.\\s-+" + "\\(\\.\\.\\.\\|" chess-algebraic-regexp "\\)" + "\\(\\s-+\\(" chess-algebraic-regexp "\\)\\)?\\)")) + (font-lock-add-keywords 'chess-pgn-mode (list (list "\\[\\(\\S-+\\)\\s-+\".*\"\\]" 1 'font-lock-keyword-face) - (cons (concat "\\([1-9][0-9]*\\.\\s-+\\(\\.\\.\\.\\s-+\\)?" - chess-algebraic-regexp - "\\(\\s-+" - chess-algebraic-regexp - "\\)?\\)") + (cons chess-pgn-move-regexp 'chess-pgn-bold-face) (cons "\\(1-0\\|0-1\\|\\*\\)$" 'font-lock-warning-face))) @@ -214,10 +224,55 @@ If INDENTED is non-nil, indent the move texts." (defun chess-pgn-show-position () (interactive) + ;; load a database to represent this file if not already up (unless chess-pgn-database - (save-excursion - (when (re-search-backward "\\[Event \"\\([^\"]+\\)\"\\]" nil t) - )))) + (setq chess-pgn-database + (chess-database-open 'chess-file buffer-file-name))) + + ;; a hack for speed's sake to read the current game text + (save-excursion + (let ((locations chess-file-locations) + (here (point)) + last-location index) + (while locations + (if (> (car locations) here) + (setq locations nil) + (setq last-location locations + locations (cdr locations)))) + (setq index (if last-location + (1- (length last-location)) + 0)) + (when (or (null chess-pgn-current-game) + (/= index (chess-game-data chess-pgn-current-game + 'database-index))) + (setq chess-pgn-current-game + (chess-database-read chess-pgn-database index))))) + + ;; now find what position we're at in the game + (save-excursion + (when (and chess-pgn-current-game + (re-search-backward chess-pgn-move-regexp nil t)) + (let* ((index (string-to-int (match-string 2))) + (first-move (match-string 3)) + (second-move (match-string 14)) + (ply (1+ (* 2 (1- index))))) + (if (and second-move (> (length second-move) 0)) + (setq ply (1+ ply))) + (if (or (and (or (null chess-pgn-display) + (not (buffer-live-p chess-pgn-display))) + (setq chess-pgn-display (chess-create-display))) + (/= (chess-game-data chess-pgn-current-game 'database-index) + (chess-game-data (chess-display-game chess-pgn-display) + 'database-index))) + (progn + (chess-display-disable-popup chess-pgn-display) + (chess-display-set-game chess-pgn-display + chess-pgn-current-game ply) + (chess-game-set-tag (chess-display-game chess-pgn-display) + 'database-index + (chess-game-data chess-pgn-current-game + 'database-index))) + (chess-display-set-index chess-pgn-display ply)))))) (defun chess-pgn-mouse-show-position (event) (interactive "e") @@ -171,6 +171,8 @@ available." (push display objects))) (setq first nil)) + (setq objects (nreverse objects)) + (let ((module (or engine chess-default-engine))) (if (symbolp module) (push (chess--create-engine module game @@ -194,6 +196,10 @@ available." (defalias 'chess-session 'chess) +(defun chess-create-display () + "Just make a display to use, letting chess.el decide the style." + (cadr (chess-session 'chess-none))) + ;;;###autoload (defun chess-read-pgn (&optional file) "Read and display a PGN game after point." |
