summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO6
-rw-r--r--chess-pgn.el18
2 files changed, 17 insertions, 7 deletions
diff --git a/TODO b/TODO
index d4559ad..f943012 100644
--- a/TODO
+++ b/TODO
@@ -1,11 +1,5 @@
- Allow the user to retract a move when playing against an engine
-- Once a king or rook is moved, clear castling rights
-
-- Handle piece promotion, which is not dealt with at all right now
-
-- In chess-pgn.el, output the PGN tags in standard order
-
- In edit mode, mouse-2 and mouse-3 should provide a drop-down list of
pieces the square can be set to. Cursor movement is really not the
best for chess-images. I still need to figure out how best to
diff --git a/chess-pgn.el b/chess-pgn.el
index cd02371..ae0adc3 100644
--- a/chess-pgn.el
+++ b/chess-pgn.el
@@ -103,6 +103,11 @@
(if plies
(insert ? ))))
+(defvar chess-pgn-tag-order
+ '("Event" "Site" "Date" "Round"
+ "White" "WhiteElo" "Black" "BlackElo"
+ "Result" "TimeControl"))
+
(defun chess-game-to-pgn (game &optional indented)
"Convert a chess GAME to PGN notation.
If INDENTED is non-nil, indent the move texts."
@@ -114,7 +119,18 @@ If INDENTED is non-nil, indent the move texts."
(if (and (not fen)
(not (equal chess-starting-position first-pos)))
(chess-game-set-tag game "FEN" (chess-pos-to-fen first-pos))))
- (dolist (tag (chess-game-tags game))
+ (dolist (tag (sort (copy-alist (chess-game-tags game))
+ (function
+ (lambda (left right)
+ (let ((l-idx (position left chess-pgn-tag-order
+ :test 'equal))
+ (r-idx (position right chess-pgn-tag-order
+ :test 'equal)))
+ (cond
+ ((and l-idx (not r-idx)) t)
+ ((and (not l-idx) r-idx) nil)
+ ((and l-idx r-idx) (< l-idx r-idx))
+ (t (string-lessp left right))))))))
(insert (format "[%s \"%s\"]\n" (car tag) (cdr tag))))
(insert ?\n)
(let ((begin (point)))