]> code.delx.au - gnu-emacs-elpa/blob - packages/arbitools/arbitools.el
Update packages/yasnippet by subtree-merging from its github-based upstream
[gnu-emacs-elpa] / packages / arbitools / arbitools.el
1 ;;; arbitools.el --- Package for chess tournaments administration
2
3 ;; Copyright 2016 Free Software Foundation, Inc.
4
5 ;; Author: David Gonzalez Gandara <dggandara@member.fsf.org>
6 ;; Version: 0.51
7
8 ;; This program is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12 ;;
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; REQUIRES:
24 ;; ---------------------------
25 ;;
26 ;;
27 ;; USAGE:
28 ;; ---------------------------
29 ;; arbitools.el is an interface for the pythong package "arbitools",
30 ;; designed to manage chess tournament reports. If you don't install the
31 ;; python package you can still have the syntax colouring.
32 ;;
33 ;; FEATURES:
34 ;; ----------------------------
35 ;; - Syntax colouring for the official trf FIDE files. This facilitates
36 ;; manual edition of the files.
37 ;;
38 ;; - Updating the players ratings. By means of the function arbitools-update
39 ;;
40 ;; - Adding players to an existing file. By arbitools-add
41 ;;
42 ;; - Getting standings and report files from a tournament file. By
43 ;; arbitools-standings.
44 ;;
45 ;; You will find more information in www.ourenxadrez.org/arbitools.htm
46
47 ;;; Code:
48
49 (defun arbitools-update (elolist)
50 "Update the players ratings."
51 (interactive "selolist:")
52 ;; FIXME: What if `list' is "foo; bar"?
53 (call-process "arbitools-run.py" nil nil nil "update" buffer-file-name "-l" elolist))
54
55 (defun arbitools-add (addfile)
56 "Add players to an existing file."
57 (interactive "faddfile: ")
58 ;; FIXME: What if `addlist' is "foo; bar"?
59 (call-process "arbitools-add.py" nil nil nil "-a" addfile "-i" buffer-file-name))
60
61 (defun arbitools-standings ()
62 "Get standings and report files from a tournament file."
63 (interactive)
64 ;; (shell-command (concat (expand-file-name "arbitools-standings.py") " -i " buffer-file-name))) ;this is to use the actual path
65 (call-process "arbitools-standings.py" nil nil nil "-i" buffer-file-name))
66
67 (defun arbitools-delete-round (round)
68 "Delete round"
69 (interactive "sround: ")
70 (beginning-of-buffer)
71 (while (re-search-forward "^001" nil t)
72 (forward-char (+ 88 (* (- (string-to-number round) 1) 10)))
73 (delete-char 10)
74 (insert " "))
75 (beginning-of-buffer))
76
77 (defun arbitools-insert-result (round white black result)
78 "Insert a result"
79 (interactive "sround: \nswhite: \nsblack: \nsresult: ")
80 (beginning-of-buffer)
81 (while (re-search-forward "^001" nil t)
82 (forward-char 4) ;; rank number
83 ;; (print (format "%s" white))
84 (when (string= white (thing-at-point 'word))
85 ;;go to first round taking into account the cursor is in the rank number
86 (forward-char (+ 85 (* (- (string-to-number round) 1) 10)))
87 (insert " ") ;; replace the first positions with spaces
88 (delete-char 2) ;; delete the former characters
89 ;; make room for bigger numbers
90 (cond ((= 2 (length black))
91 (backward-char 1))
92 ((= 3 (length black))
93 (backward-char 2)))
94 (insert (format "%s w %s" black result))
95 (delete-char 5)
96 ;; adjust when numbers are longer
97 (cond ((= 2 (length black)) (delete-char 1))
98 ((= 3 (length black)) (delete-char 2))))
99 (when (string= black (thing-at-point 'word))
100 ;;go to first round taking into account the cursor is in the rank number
101 (forward-char (+ 85 (* (- (string-to-number round) 1) 10)))
102 (insert " ") ;; replace the first positions with spaces
103 (delete-char 2) ;; delete the former characters
104 ;; make room for bigger numbers
105 (cond ((= 2 (length white)) (backward-char 1))
106 ((= 3 (length white)) (backward-char 2)))
107 (cond ((string= "1" result) (insert (format "%s b 0" white)))
108 ((string= "0" result) (insert (format "%s b 1" white))))
109 (delete-char 5)
110 ;; adjust when numbers are longer
111 (cond ((= 2 (length white)) (delete-char 1))
112 ((= 3 (length white)) (delete-char 2)))))
113 (beginning-of-buffer))
114
115 (defun arbitools-it3 ()
116 "Get the IT3 tournament report."
117 (interactive)
118 (call-process "arbitools-run.py" nil nil nil "it3" buffer-file-name))
119
120 (defun arbitools-fedarating ()
121 "Get the FEDA rating admin file."
122 (interactive)
123 (call-process "arbitools-run.py" nil nil nil "fedarating" buffer-file-name))
124
125 (defvar arbitools-mode-map
126 (let ((map (make-sparse-keymap)))
127 (define-key map (kbd "C-c i") 'arbitools-it3)
128 map)
129 "Keymap for Arbitools major mode.")
130
131
132 (easy-menu-define arbitools-mode-menu arbitools-mode-map
133 "Menu for Arbitools mode"
134 '("Arbitools"
135 ["Insert Result" arbitools-insert-result]
136 ["Delete Round" arbitools-delete-round]
137 "---"
138 ["Get It3 form Report" arbitools-it3]
139 ["Get FEDA Ratinf file" arbitools-fedarating]
140 ))
141
142
143 (defvar arbitools-highlights
144 '(("^001" . font-lock-function-name-face) ; name of the tournament
145 ("^012.*" . font-lock-comment-face)
146 ("\\(^022\\|^032\\|^042\\|^052\\|^062\\|^072\\|^082\\|^092\\|^102\\|^112\\|^122\\).*" . font-lock-constant-face)
147 ("^132.*" . font-lock-warning-face) ;dates
148 ("^013" . font-lock-warning-face) ;teams
149 ("\\(^013.\\{1\\}\\)\\(.\\{31\\}\\)" 2 font-lock-comment-face) ;; teams
150 ;; (" [0-9]\\{6,\\} " . font-lock-variable-name-face) ;FIDE ID
151 ("\\(^001.\\{11\\}\\)\\(.\\{32\\}\\)" 2 font-lock-string-face) ;; Name of the player (by position)
152 ("\\(^001.\\{55\\}\\)\\(.\\{10\\}\\)" 2 font-lock-function-name-face) ;; FIDE ID
153 ("\\(^001.\\{88\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face) ;; round 1 opponent
154 ;; ("\\(^132.\\{88\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face) ;; round 1 date line
155 ("\\(^001.\\{93\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face) ;; round 1 colour
156 ("\\(^001.\\{95\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face) ;; round 1 result
157 ;; rest of rounds
158 ("\\(^001.\\{98\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
159 ;; ("\\(^132.\\{98\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
160 ("\\(^001.\\{103\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
161 ("\\(^001.\\{105\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
162 ("\\(^001.\\{108\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
163 ;; ("\\(^132.\\{108\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
164 ("\\(^001.\\{113\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
165 ("\\(^001.\\{115\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
166 ("\\(^001.\\{118\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
167 ;; ("\\(^132.\\{118\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
168 ("\\(^001.\\{123\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
169 ("\\(^001.\\{125\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
170 ("\\(^001.\\{128\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
171 ;; ("\\(^132.\\{128\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
172 ("\\(^001.\\{133\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
173 ("\\(^001.\\{135\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
174 ("\\(^001.\\{138\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
175 ;; ("\\(^132.\\{138\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
176 ("\\(^001.\\{143\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
177 ("\\(^001.\\{145\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
178 ("\\(^001.\\{148\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
179 ;; ("\\(^132.\\{148\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
180 ("\\(^001.\\{153\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
181 ("\\(^001.\\{155\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
182 ("\\(^001.\\{158\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
183 ;; ("\\(^132.\\{158\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
184 ("\\(^001.\\{163\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
185 ("\\(^001.\\{165\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
186 ("\\(^001.\\{168\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
187 ;; ("\\(^132.\\{168\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
188 ("\\(^001.\\{173\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
189 ("\\(^001.\\{175\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
190 ("\\(^001.\\{178\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
191 ;; ("\\(^132.\\{178\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
192 ("\\(^001.\\{183\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
193 ("\\(^001.\\{185\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
194 ("\\(^001.\\{188\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
195 ;; ("\\(^132.\\{188\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
196 ("\\(^001.\\{193\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
197 ("\\(^001.\\{195\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)
198 ("\\(^001.\\{198\\}\\)\\(.\\{4\\}\\)" 2 font-lock-comment-face)
199 ;; ("\\(^132.\\{198\\}\\)\\(.\\{8\\}\\)" 2 font-lock-string-face)
200 ("\\(^001.\\{203\\}\\)\\(.\\{1\\}\\)" 2 font-lock-string-face)
201 ("\\(^001.\\{205\\}\\)\\(.\\{1\\}\\)" 2 font-lock-function-name-face)))
202
203 ;;;###autoload
204 (define-derived-mode arbitools-mode
205 fundamental-mode
206 "Arbitools"
207 "Major mode for Chess Tournament Management."
208 ;(setq font-lock-defaults '(arbitools-highlights))
209 (use-local-map arbitools-mode-map)
210 (set (make-local-variable 'font-lock-defaults) '(arbitools-highlights)))
211
212 ;;;###autoload
213 (add-to-list 'auto-mode-alist '("\\.trf?\\'" . arbitools-mode))
214
215 (provide 'arbitools)
216
217 ;;; arbitools.el ends here