summaryrefslogtreecommitdiff
path: root/chess-pgn.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-04-08 05:52:08 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-04-08 05:52:08 +0000
commit69ee4a4fe6fa154cb631cdb921ad5b5885724a59 (patch)
tree15e7e6a838cc8f0aa3288afe127d4d222859ac44 /chess-pgn.el
parent54d66578bec3e22b42a5bc33198119968120fd35 (diff)
Output tags in typical order
Diffstat (limited to 'chess-pgn.el')
-rw-r--r--chess-pgn.el18
1 files changed, 17 insertions, 1 deletions
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)))