diff options
| author | Mario Lang <mlang@delysid.org> | 2004-02-05 22:05:04 +0000 |
|---|---|---|
| committer | Mario Lang <mlang@delysid.org> | 2004-02-05 22:05:04 +0000 |
| commit | 130c3e15e287192bf3dda8dc8c084bfdcf3c5fd6 (patch) | |
| tree | dd31c726d5c28e695af01cc894da1242cfc40f8f | |
| parent | 7398595b994f0598a91a520cc85e0f52407a60ca (diff) | |
Handle .epd and .pgn files in the chess-file module. Achieved by
setting a buffer-local variable chess-file-type to either 'pgn or 'epd
on 'open, and use this info to dispatch correctly.
This change makes it possible to load .epd files with the
chess-puzzle function for instance.
| -rw-r--r-- | chess-file.el | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/chess-file.el b/chess-file.el index 509f3e6..565a493 100644 --- a/chess-file.el +++ b/chess-file.el @@ -9,13 +9,25 @@ (make-variable-buffer-local 'chess-file-locations) +(defvar chess-file-type nil) +(make-variable-buffer-local 'chess-file-type) + +(defvar chess-file-types + `((pgn "^\\[Event " chess-pgn-to-game chess-game-to-pgn (?\n ?\n)) + (epd ,(concat chess-fen-regexp "\\(\\s-+.+\\);\\s-*$") + chess-epd-to-game chess-game-to-epd (?\n))))) + (defun chess-file-handler (event &rest args) (cond ((eq event 'open) (with-current-buffer (find-file-noselect (car args)) - (when (or (string-match "\\.pgn\\'" (car args)) - (save-excursion - (re-search-forward "^\\[Event" nil t))) + (when (setq chess-file-type + (cond + ((or (string-match "\\.pgn\\'" (car args)) + (save-excursion (re-search-forward "^\\[Event" nil t))) + 'pgn) + ((string-match "\\.epd\\'" (car args)) + 'epd))) (chess-file-handler 'rescan) (current-buffer)))) @@ -23,7 +35,8 @@ (save-excursion (goto-char (point-min)) (setq chess-file-locations nil) - (while (re-search-forward "^\\[Event " nil t) + (while (re-search-forward (nth 1 (assq chess-file-type chess-file-types)) + nil t) (goto-char (match-beginning 0)) (push (point) chess-file-locations) (forward-char 1)) @@ -46,7 +59,8 @@ (when (and (>= index 0) (< index (chess-file-handler 'count))) (goto-char (nth index chess-file-locations)) - (when (setq game (chess-pgn-to-game)) + (when (setq game (funcall (nth 2 (assq chess-file-type + chess-file-types)))) (chess-game-set-data game 'database (current-buffer)) (chess-game-set-data game 'database-index index) (chess-game-set-data game 'database-count @@ -57,9 +71,9 @@ (goto-char (point-max)) (while (memq (char-before) '(? ?\t ?\n ?\r)) (delete-backward-char 1)) - (insert ?\n ?\n) + (apply 'insert (nth 4 (assq chess-file-type chess-file-types))) (push (point) chess-file-locations) - (chess-game-to-pgn (car args)) + (funcall (nth 3 (assq chess-file-type chess-file-types)) (car args)) (1- (chess-file-handler 'count))) ((eq event 'replace) @@ -72,8 +86,8 @@ (delete-region (point) (if (= (1+ index) count) (point-max) (nth (1+ index) chess-file-locations))) - (chess-game-to-pgn (car args)) - (insert ?\n)))))) + (funcall (nth 3 (assq chess-file-type chess-file-types)) (car args)) + (when (eq chess-file-type 'pgn) (insert ?\n))))))) (provide 'chess-file) |
