language.el 6.84 KB
Newer Older
David Kågedal's avatar
David Kågedal committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;;;;;
;;;;; $Id$
;;;;; Copyright (C) 1991, 1996  Lysator Academic Computer Association.
;;;;;
;;;;; This file is part of the LysKOM server.
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
;;;;; the Free Software Foundation; either version 2, or (at your option) 
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: language.el
;;;; Author: Niels Mller
;;;;
;;;;

(require 'lyskom-vars "vars")
Niels Möller's avatar
Niels Möller committed
34

35
36
37
38
39
40
41
42
43
;;(defconst lyskom-category-properties		    
;;  '((command . lyskom-command)			    
;;    (menu    . lyskom-menu)			    
;;    (message . lyskom-message))			    
;;  "Property names for saving different categories.")

(defvar lyskom-language-symbols nil
  "Symbols with language data bound to them")

44
;;; Variables
Niels Möller's avatar
Niels Möller committed
45

David Kågedal's avatar
David Kågedal committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(defvar lyskom-language-vars nil
  "A list of all language-dependent variables.")

(defun lyskom-language-var-internal (var language val)
  "Defines a language-local variable value."
  (or (memq var lyskom-language-vars)
      (setq lyskom-language-vars
	    (cons var lyskom-language-vars)))
  (let* ((alist (get var 'lyskom-language-var))
	 (entry (assq language alist)))
    (if entry
	(setcdr entry val)
      (put var 'lyskom-language-var (cons (cons language val) alist)))))

(defmacro lyskom-language-var (var language val)
  (list 'lyskom-language-var-internal
	(list 'quote var)
	(list 'quote language)
	(list 'quote val)))

(put 'lyskom-language-var 'lisp-indent-function 2)

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
(defun lyskom-set-language-vars (language)
  (mapcar
   (function
    (lambda (var)
      (if (or (not (symbol-value var))
	      (get var 'lyskom-language-force))
	  (set var (eval (cdr (assq language
				    (get var 'lyskom-language-var))))))))
   lyskom-language-vars))

;;; Keymaps

(defvar lyskom-language-keymaps nil
  "A list of all language-dependent variables.")

(defun lyskom-language-keymap-internal (keymap language langmap)
  "Defines a language-local variable value."
  ;; If the "real" keymap has no value, set it to an empty keymap
  (if (eval keymap)
      nil
    (set keymap (make-sparse-keymap)))
  ;; Add it to the list of keymaps
  (or (memq keymap lyskom-language-keymaps)
      (setq lyskom-language-keymaps
	    (cons keymap lyskom-language-keymaps)))
  ;; Modify the property list
  (let* ((alist (get keymap 'lyskom-language-keymap))
	 (entry (assq language alist)))
    (if entry
	(setcdr entry langmap)
      (put keymap 'lyskom-language-keymap
	   (cons (cons language langmap) alist)))))

(defmacro lyskom-language-keymap (keymap language langmap)
  (list 'lyskom-language-keymap-internal
	(list 'quote keymap)
	(list 'quote language)
	(list 'quote langmap)))

(put 'lyskom-language-keymap 'lisp-indent-function 2)

(defun lyskom-set-language-keymaps (language)
  (mapcar
   (function
    (lambda (map)
      (setcdr (symbol-value map)
	      (eval (cdr (assq language
			       (get map 'lyskom-language-keymap)))))))
   lyskom-language-keymaps))

;;; String catalogs

(defvar lyskom-language-categories nil
  "Categories used")

(defun lyskom-language-strings-internal (category language alist)
Niels Möller's avatar
Niels Möller committed
124
125
126
127
  "Associates names to symbols.

CATEGORY and LANGUAGE determines what kind of association to
create. ALIST is a mapping from symbols to strings."
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  ;; Record category
  (or (memq category lyskom-language-categories)
      (setq lyskom-language-categories
	    (cons category lyskom-language-categories)))
  (mapcar (function (lambda (pair)
		      (let* ((symbol (car pair))
			     (string (cdr pair))
			     (llist (get symbol category))
			     (entry (assq language llist)))
			;; Record symbol
			(or (memq symbol lyskom-language-symbols)
			    (setq lyskom-language-symbols
				  (cons symbol lyskom-language-symbols)))
			(if entry
			    (setcdr entry string)
			  (put symbol category
			       (cons (cons language string) llist))))))
	  alist))
Niels Möller's avatar
Niels Möller committed
146

147
148
149
150
151
152
(defmacro lyskom-language-strings (category language alist)
  (list 'lyskom-language-strings-internal
	(list 'quote category)
	(list 'quote language)
	alist)) 

David Kågedal's avatar
David Kågedal committed
153
(put 'lyskom-language-strings 'lisp-indent-function 2)
Niels Möller's avatar
Niels Möller committed
154

155
156
157
158
159
160
161
(defsubst lyskom-get-string-internal (symbol category)
    (cdr (assq lyskom-language (get symbol category))))

(defsubst lyskom-get-string-error (function symbol category)
  (signal 'lyskom-internal-error
	  (list function (list symbol category ": string not found"))))

Niels Möller's avatar
Niels Möller committed
162
163
(defun lyskom-get-string (symbol &optional category)
  "Returns string assiciated with SYMBOL"
164
165
166
167
168
    (or (lyskom-get-string-internal symbol (or category 'lyskom-message))
        (lyskom-get-string-error 'lyskom-get-string
                                 symbol
                                 (or category 'lyskom-message))))

Niels Möller's avatar
Niels Möller committed
169
170
171
172

(defun lyskom-get-strings (symbols &optional category)
  "Returns an alist of (symbol . string) pairs

173
according to CATEGORY and lyskom-language. Kind of inverse to
Niels Möller's avatar
Niels Möller committed
174
175
176
177
178
lyskom-define-language."
  (mapcar (function (lambda (symbol)
		      (cons symbol (lyskom-get-string symbol category))))
	  symbols))

179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
(defun lyskom-get-menu-string (symbol)
  "Returns the name of a menu(item)

Looks for the 'lyskom-menu category, or 'lyskom-command
if 'lyskom-menu is not found."
    (or (lyskom-get-string-internal symbol 'lyskom-menu)
        (lyskom-get-string-internal symbol 'lyskom-command)
        (lyskom-get-string-error 'lyskom-get-menu-string symbol 'lyskom-menu)))

;;(defun nisse-filter (pred list)
;;  (cond ((null list) nil)
;;	  ((funcall pred (car list))
;;	   (cons (car list) (nisse-filter pred (cdr list))))
;;	  (t (nisse-filter pred (cdr list)))))
    
(defun lyskom-string-check-category (category)
  "Returns list of names for the cetegory, and their supported languages"
  (delq nil (mapcar (function
		     (lambda (symbol)
		       (let ((info (get symbol category)))
			 (if info (cons symbol (mapcar 'car info))))))
		    lyskom-language-symbols)))

202
203
204
205
206
207
208
209
210
211
212
213

(defun lyskom-define-language (language name)
  ;; Do nothing for now
  )

(defun lyskom-set-language (language)
  "Set the current language to LANGUAGE."
  (setq lyskom-language language)
  (lyskom-set-language-vars language)
  (lyskom-set-language-keymaps language)
  (lyskom-build-menus)) 

214
			      
David Kågedal's avatar
David Kågedal committed
215
216
217
(provide 'lyskom-language)

;;; language.el ends here