]> code.delx.au - gnu-emacs-elpa/blob - chess-message.el
* chess-pos.el (chess-pos-search*)
[gnu-emacs-elpa] / chess-message.el
1 ;;; chess-message.el --- Code shared by all chess displays
2
3 ;; Copyright (C) 2014 Free Software Foundation, Inc.
4
5 ;; This is free software; you can redistribute it and/or modify it under
6 ;; the terms of the GNU General Public License as published by the Free
7 ;; Software Foundation; either version 3, or (at your option) any later
8 ;; version.
9 ;;
10 ;; This is distributed in the hope that it will be useful, but WITHOUT
11 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 ;; for more details.
14 ;;
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
17
18 ;;; Commentary:
19
20 ;;; Code:
21
22 (defgroup chess-message nil
23 "Support for message catalogs in chess.el."
24 :group 'chess)
25
26 (defcustom chess-message-language 'english
27 "The language to use when reporting messages."
28 :type 'symbol
29 :group 'chess-message)
30
31 ;;; Code:
32
33 (defvar chess-message-catalog nil)
34
35 (defun chess-message-catalog (catalog definitions)
36 (let ((entry (assq catalog chess-message-catalog)))
37 (if entry
38 (dolist (def definitions)
39 (let ((str (assq (car def) (cdr entry))))
40 (if str
41 (setcdr str (cdr def))
42 (setcdr entry (cons def (cdr entry))))))
43 (push (cons catalog definitions) chess-message-catalog))))
44
45 (defun chess-string (key &rest arguments)
46 (let* ((entry (assq chess-message-language chess-message-catalog))
47 (msg (and entry (cdr (assq key (cdr entry))))))
48 (if msg
49 (apply 'format msg arguments)
50 (format "Message not found: %s" key))))
51
52 (defsubst chess-message (key &rest arguments)
53 (message (apply 'chess-string key arguments)))
54
55 (defsubst chess-error (key &rest arguments)
56 (error (apply 'chess-string key arguments)))
57
58 (put 'chess-message-catalog 'lisp-indent-function 1)
59
60 (provide 'chess-message)
61
62 ;;; chess-message.el ends here