diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-03-02 04:12:02 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-03-02 04:12:02 +0000 |
| commit | 0ee4f145daee8ec676edb4fd966a695cf6bb4887 (patch) | |
| tree | f7924088c0594a9091ecdbc42c8b1860ccfc0acd /chess-pgn.el | |
| parent | f4bd5160075b5691f9404aa51abd8cd063dc5e06 (diff) | |
Added chess-pgn-mode code from chess-pgn-mode.el, and deleted that
file.
Diffstat (limited to 'chess-pgn.el')
| -rw-r--r-- | chess-pgn.el | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/chess-pgn.el b/chess-pgn.el index 7c4fe93..7a83ba5 100644 --- a/chess-pgn.el +++ b/chess-pgn.el @@ -5,6 +5,7 @@ ;; $Revision$ (require 'chess-game) +(require 'chess-pos) (require 'chess-algebraic) (require 'chess-fen) @@ -107,6 +108,60 @@ If INDENTED is non-nil, indent the move texts." (insert (or (chess-game-tag game "Result") "*") ?\n) (fill-region begin (point)))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; PGN-mode for editing and browsing PGN files. +;; + +(defvar chess-pgn-mode-map + (let ((map (make-sparse-keymap))) + (define-key map [??] 'describe-mode) + (define-key map [?T] 'text-mode) + (define-key map [return] 'chess-pgn-move) + (define-key map [(control ?m)] 'chess-pgn-move) + map) + "Keymap used by Chess PGN mode.") + +(define-derived-mode chess-pgn-mode text-mode "Chess" + "A mode for editing Chess PGN files.") + +(defun chess-pgn-move () + "Make a move from a PGN buffer." + (interactive) + (let ((end (point)) + coords move) + (save-excursion + (skip-chars-backward "^ ") + (setq move (buffer-substring-no-properties (point) end) + coords (chess-algebraic-to-ply chess-display-position move)) + ;; it will just get reinserted again + (delete-region (point) end)) + (chess-session-event chess-current-session 'move + (chess-algebraic-to-ply chess-display-position)))) + +(defun chess-pgn-insert-move (move &optional color sequence) + "Insert an algebraic move description into a PGN buffer. +If move is the symbol `wait', it means reflect that we are now waiting +for the opponent to make his move. If move is the symbol `ready', it +means our opponent is now waiting for us to move our move. Otherwise, +move should be a string representing the algebraic notation for the +move." + (while (= (char-before) ?.) + (delete-backward-char 1)) + (cond + ((eq move 'wait) + (insert "...")) + ((eq move 'ready) t) + (t + (if (= (char-syntax (char-before)) ? ) + (insert move)) + (if color + (move-to-column 11 t) + (insert ?\n (format "%d. " (1+ sequence)))))) + (let ((wind (get-buffer-window (current-buffer)))) + (if wind + (set-window-point wind (point))))) + (provide 'chess-pgn) ;;; chess-pgn.el ends here |
