771
|
1 ;;; code-init.el --- Handle coding system default values
|
|
2
|
1318
|
3 ;; Copyright (C) 2001, 2002, 2003 Ben Wing.
|
771
|
4
|
|
5 ;; This file is part of XEmacs.
|
|
6
|
|
7 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
8 ;; under the terms of the GNU General Public License as published by
|
|
9 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
10 ;; any later version.
|
|
11
|
|
12 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 ;; General Public License for more details.
|
|
16
|
|
17 ;; You should have received a copy of the GNU General Public License
|
|
18 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 ;; Boston, MA 02111-1307, USA.
|
|
21
|
|
22 ;;; Commentary:
|
|
23
|
|
24 ;; Placed in a separate file so it can be loaded after the various
|
|
25 ;; coding systems have been created, because we'll be using them at
|
|
26 ;; load time.
|
|
27
|
|
28 ;;; Code:
|
|
29
|
|
30 (defcustom eol-detection-enabled-p (or (featurep 'mule)
|
|
31 (memq system-type '(windows-nt
|
|
32 cygwin32))
|
|
33 (featurep 'unix-default-eol-detection))
|
|
34 "True if XEmacs automatically detects the EOL type when reading files.
|
|
35 Normally, this is always the case on Windows or when international (Mule)
|
|
36 support is compiled into this XEmacs. Otherwise, it is currently off by
|
|
37 default, but this may change. Don't set this; nothing will happen. Instead,
|
|
38 use the Options menu or `set-eol-detection'."
|
|
39 :group 'encoding
|
|
40 :type 'boolean
|
|
41 ;; upon initialization, we don't want the whole business of
|
|
42 ;; set-eol-detection to be called. We will init everything appropriately
|
|
43 ;; later in the same file, when reset-language-environment is called.
|
|
44 :initialize #'(lambda (var val)
|
|
45 (setq eol-detection-enabled-p val))
|
|
46 :set #'(lambda (var val)
|
|
47 (set-eol-detection val)
|
|
48 (setq eol-detection-enabled-p val)))
|
|
49
|
|
50 (defun set-eol-detection (flag)
|
|
51 "Enable (if FLAG is non-nil) or disable automatic EOL detection of files.
|
|
52 EOL detection is enabled by default on Windows or when international (Mule)
|
|
53 support is compiled into this XEmacs. Otherwise, it is currently off by
|
|
54 default, but this may change. NOTE: You *REALLY* should not turn off EOL
|
|
55 detection on Windows! Your files will have lots of annoying ^M's in them
|
|
56 if you do this."
|
|
57 (dolist (x '(buffer-file-coding-system-for-read
|
|
58 keyboard
|
|
59 default-process-coding-system-read
|
|
60 no-conversion-coding-system-mapping))
|
|
61 (set-coding-system-variable
|
|
62 x (coding-system-change-eol-conversion (get-coding-system-variable x)
|
|
63 (if flag nil 'lf)))))
|
|
64
|
|
65 (defun coding-system-current-system-configuration ()
|
|
66 (cond ((memq system-type '(windows-nt cygwin32))
|
|
67 (if (featurep 'mule) 'windows-mule 'windows-no-mule))
|
|
68 ((featurep 'mule) 'unix-mule)
|
|
69 (eol-detection-enabled-p 'unix-no-mule-eol-detection)
|
|
70 (t 'unix-no-mule-no-eol-detection)))
|
|
71
|
1318
|
72 ;; NOTE NOTE NOTE: These values may get overridden when the language
|
|
73 ;; environment is initialized (set-language-environment-coding-systems).
|
771
|
74 (defvar coding-system-variable-default-value-table
|
1318
|
75 '((buffer-file-coding-system-for-read
|
|
76 binary raw-text undecided raw-text undecided)
|
|
77 (default-buffer-file-coding-system
|
|
78 binary binary iso-2022-8 raw-text-dos mswindows-multibyte-dos)
|
|
79 (native
|
|
80 binary binary binary raw-text-dos mswindows-multibyte-system-default-dos)
|
|
81 (keyboard
|
1471
|
82 binary raw-text undecided-unix raw-text undecided-unix)
|
771
|
83 ;; the `terminal' coding system is used for output to stderr. such
|
|
84 ;; streams do automatic lf->crlf encoding in the C library, so we need
|
|
85 ;; to not do the same translations ourselves.
|
1318
|
86 (terminal
|
|
87 binary binary binary binary mswindows-multibyte-unix)
|
|
88 (default-process-coding-system-read
|
|
89 binary raw-text undecided raw-text undecided)
|
|
90 (default-process-coding-system-write
|
|
91 binary binary binary raw-text mswindows-multibyte-system-default)
|
|
92 (no-conversion-coding-system-mapping
|
|
93 binary raw-text raw-text raw-text mswindows-multibyte)
|
771
|
94 ))
|
|
95
|
|
96 (defvar coding-system-default-configuration-list
|
|
97 '(unix-no-mule-no-eol-detection
|
|
98 unix-no-mule-eol-detection
|
|
99 unix-mule
|
|
100 windows-no-mule
|
|
101 windows-mule))
|
|
102
|
|
103 (defvar coding-system-default-variable-list
|
|
104 '(buffer-file-coding-system-for-read
|
|
105 default-buffer-file-coding-system
|
|
106 native
|
|
107 keyboard
|
|
108 terminal
|
|
109 default-process-coding-system-read
|
|
110 default-process-coding-system-write))
|
|
111
|
|
112 (defun get-coding-system-variable (var)
|
|
113 "Return the value of a basic coding system variable.
|
|
114 This is intended as a uniform interface onto the coding system settings that
|
|
115 control how encoding detection and conversion works. See
|
|
116 `coding-system-variable-default-value' for a list of the possible values of
|
|
117 VAR."
|
|
118 (case var
|
|
119 (buffer-file-coding-system-for-read buffer-file-coding-system-for-read)
|
|
120 (default-buffer-file-coding-system
|
|
121 (default-value 'buffer-file-coding-system))
|
|
122 (native (coding-system-aliasee 'native))
|
|
123 (keyboard (coding-system-aliasee 'keyboard))
|
|
124 (terminal (coding-system-aliasee 'terminal))
|
|
125 (default-process-coding-system-read (car default-process-coding-system))
|
|
126 (default-process-coding-system-write (cdr default-process-coding-system))
|
|
127 (t (error 'invalid-constant "Invalid coding system variable" var))))
|
|
128
|
|
129 (defun set-coding-system-variable (var value)
|
|
130 "Set a basic coding system variable to VALUE.
|
|
131 This is intended as a uniform interface onto the coding system settings that
|
|
132 control how encoding detection and conversion works. See
|
|
133 `coding-system-variable-default-value' for a list of the possible values of
|
|
134 VAR."
|
|
135 (case var
|
|
136 (buffer-file-coding-system-for-read
|
|
137 (set-buffer-file-coding-system-for-read value))
|
|
138 (default-buffer-file-coding-system
|
|
139 (set-default-buffer-file-coding-system value))
|
|
140 (native (define-coding-system-alias 'native value))
|
|
141 (keyboard (set-keyboard-coding-system value))
|
|
142 (terminal (set-terminal-coding-system value))
|
|
143 (default-process-coding-system-read
|
|
144 (setq default-process-coding-system
|
|
145 (cons value (cdr default-process-coding-system))))
|
|
146 (default-process-coding-system-write
|
|
147 (setq default-process-coding-system
|
|
148 (cons (car default-process-coding-system) value)))
|
|
149 (t (error 'invalid-constant "Invalid coding system variable" var))))
|
|
150
|
|
151 (defun coding-system-variable-default-value (var &optional config)
|
|
152 "Return the appropriate default value for a coding system variable.
|
|
153
|
|
154 VAR specifies the variable, and CONFIG the configuration, defaulting
|
|
155 to the current system configuration (as returned by
|
|
156 `coding-system-current-system-configuration').
|
|
157
|
|
158 The table of default values looks like this: (see below for abbreviations)
|
|
159
|
|
160
|
1471
|
161 Unix Unix+EOL Unix+Mule MSW MSW+Mule
|
|
162 -----------------------------------------------------------------------------
|
|
163 bfcs-for-read binary raw-text undecided raw-text undecided
|
|
164 default bfcs binary binary iso-2022-8 raw-text-dos MSW-MB-dos
|
|
165 native binary binary binary raw-text-dos MSW-MB-SD-dos
|
|
166 keyboard binary raw-text undecided-unix raw-text undecided-unix
|
|
167 terminal binary binary binary binary MSW-MB-unix
|
|
168 process-read binary raw-text undecided raw-text undecided
|
|
169 process-write binary binary binary raw-text MSW-MB-SD
|
|
170 no-conv-cs binary raw-text raw-text raw-text MSW-MB
|
771
|
171
|
|
172
|
|
173 VAR can be one of: (abbreviations in parens)
|
|
174
|
|
175 `buffer-file-coding-system-for-read' (bfcs-for-read)
|
|
176
|
|
177 Lisp variable of the same name; the default coding system used when
|
|
178 reading in a file, in the absence of more specific settings. (See
|
|
179 `insert-file-contents' for a description of exactly how a file's
|
|
180 coding system is determined when it's read in.)
|
|
181
|
|
182 `default-buffer-file-coding-system' (default bfcs)
|
|
183
|
|
184 Default value of `buffer-file-coding-system', the buffer-local
|
|
185 variable specifying a file's coding system to be used when it is
|
|
186 written out. Set using `set-default-buffer-file-coding-system' (or
|
|
187 the primitive `setq-default'). When a file is read in,
|
|
188 `buffer-file-coding-system' for that file is set from the coding
|
|
189 system used to read the file in; the default value applies to newly
|
|
190 created files.
|
|
191
|
|
192 `native' (native)
|
|
193
|
|
194 The coding system named `native'. Changed using
|
|
195 `define-coding-system-alias'. Used internally when passing
|
1318
|
196 text to or from system API's, unless the particular
|
771
|
197 API specifies another coding system.
|
|
198
|
|
199 `keyboard' (keyboard)
|
|
200
|
|
201 #### fill in
|
|
202
|
|
203 `terminal' (terminal)
|
|
204
|
|
205 #### fill in
|
|
206
|
|
207 `default-process-coding-system-read' (process-read)
|
|
208
|
|
209 #### fill in
|
|
210
|
|
211 `default-process-coding-system-write' (process-write)
|
|
212
|
|
213 #### fill in
|
|
214
|
|
215 `no-conversion-coding-system-mapping' (no-conv-cs)
|
|
216
|
|
217 Coding system used when category `no-conversion' is detected.
|
|
218
|
|
219
|
|
220 CONFIG is one of: (abbreviations in parens)
|
|
221
|
|
222 `unix-no-mule-no-eol-detection' (Unix)
|
|
223
|
|
224 Unix, no Mule support, no automatic EOL detection. (Controlled by
|
|
225 `eol-detection-enabled-p', which is set by the command-line flag
|
|
226 -enable-eol-detection or the configure flag --with-default-eol-detection.)
|
|
227
|
|
228 `unix-no-mule-eol-detection' (Unix+EOL)
|
|
229
|
|
230 Unix, no Mule support, automatic EOL detection.
|
|
231
|
|
232 `unix-mule' (Unix+Mule)
|
|
233
|
|
234 Unix, Mule support.
|
|
235
|
|
236 `windows-no-mule' (MSW)
|
|
237
|
|
238 MS Windows or Cygwin, no Mule support.
|
|
239
|
|
240 `windows-mule'. (MSW+Mule)
|
|
241
|
|
242 MS Windows or Cygwin, Mule support.
|
|
243
|
|
244
|
|
245 The following coding system abbreviations are also used in the table:
|
|
246
|
|
247 MSW-MB = mswindows-multibyte
|
|
248 MSW-MB = mswindows-multibyte-system-default
|
|
249 "
|
|
250 (setq config (or config (coding-system-current-system-configuration)))
|
|
251 (let ((defs (cdr (assq var coding-system-variable-default-value-table))))
|
|
252 (or defs (error 'invalid-constant "Invalid coding system variable" var))
|
|
253 (let ((pos (position config coding-system-default-configuration-list)))
|
|
254 (or pos (error 'invalid-constant "Invalid coding system configuration"
|
|
255 config))
|
|
256 (nth pos defs))))
|
|
257
|
|
258 (defun reset-coding-system-defaults (&optional config)
|
|
259 "Reset all basic coding system variables are set to their default values.
|
|
260 See `coding-system-variable-default-value'."
|
|
261 (setq config (or config (coding-system-current-system-configuration)))
|
|
262 (mapcar #'(lambda (var)
|
|
263 (set-coding-system-variable
|
|
264 var (coding-system-variable-default-value var config)))
|
|
265 coding-system-default-variable-list))
|
|
266
|
|
267 (defun reset-coding-categories-to-default ()
|
|
268 "Reset all coding categories (used for automatic detection) to their defaults.
|
|
269
|
|
270 The order of priorities of coding categories and the coding system
|
|
271 bound to each category are as follows:
|
|
272
|
|
273 coding category coding system
|
|
274 --------------------------------------------------
|
|
275 utf-16-little-endian-bom utf-16-little-endian
|
|
276 utf-16-bom utf-16-bom
|
985
|
277 utf-8-bom utf-8-bom
|
771
|
278 iso-7 iso-2022-7bit
|
|
279 no-conversion raw-text
|
|
280 utf-8 utf-8
|
|
281 iso-8-1 iso-8859-1
|
|
282 iso-8-2 ctext (iso-8859-1 alias)
|
|
283 iso-8-designate ctext (iso-8859-1 alias)
|
|
284 iso-lock-shift iso-2022-lock
|
|
285 shift-jis shift-jis
|
|
286 big5 big5
|
|
287 utf-16-little-endian utf-16-little-endian
|
|
288 utf-16 utf-16
|
|
289 ucs-4 ucs-4
|
|
290 "
|
|
291 ;; #### What a mess! This needs to be overhauled.
|
|
292
|
|
293 ;; The old table (from FSF synch?) was not what we use (cf mule-coding.el),
|
|
294 ;; and as documented iso-8-designate is inconsistent with iso-2022-8bit-ss2.
|
|
295 ;; The order of priorities of coding categories and the coding system
|
|
296 ;; bound to each category are as follows:
|
|
297 ;;
|
|
298 ;; coding category coding system
|
|
299 ;; --------------------------------------------------
|
|
300 ;; iso-8-2 iso-8859-1
|
|
301 ;; iso-8-1 iso-8859-1
|
|
302 ;; iso-7 iso-2022-7bit
|
|
303 ;; iso-lock-shift iso-2022-lock
|
|
304 ;; iso-8-designate iso-2022-8bit-ss2
|
|
305 ;; no-conversion raw-text
|
|
306 ;; shift-jis shift_jis
|
|
307 ;; big5 big5
|
|
308 ;; ucs-4 ----
|
|
309 ;; utf-8 ----
|
|
310 (when (featurep 'mule)
|
|
311 (set-coding-category-system 'iso-7 'iso-2022-7)
|
|
312 (set-coding-category-system 'iso-8-1 'iso-8859-1)
|
|
313 (set-coding-category-system 'iso-8-2 'ctext)
|
|
314 (set-coding-category-system 'iso-lock-shift 'iso-2022-lock)
|
|
315 (set-coding-category-system 'iso-8-designate 'ctext)
|
|
316 (if (find-coding-system 'shift-jis)
|
|
317 (set-coding-category-system 'shift-jis 'shift-jis))
|
|
318 (if (find-coding-system 'big5)
|
|
319 (set-coding-category-system 'big5 'big5))
|
|
320 )
|
|
321 (set-coding-category-system
|
|
322 'no-conversion
|
|
323 (coding-system-variable-default-value 'no-conversion-coding-system-mapping))
|
|
324 (set-coding-category-system 'ucs-4 'ucs-4)
|
|
325 (set-coding-category-system 'utf-8 'utf-8)
|
985
|
326 (set-coding-category-system 'utf-8-bom 'utf-8-bom)
|
771
|
327 (set-coding-category-system 'utf-16-little-endian 'utf-16-little-endian)
|
|
328 (set-coding-category-system 'utf-16 'utf-16)
|
|
329 (set-coding-category-system 'utf-16-little-endian-bom
|
|
330 'utf-16-little-endian-bom)
|
|
331 (set-coding-category-system 'utf-16-bom 'utf-16-bom)
|
|
332 (set-coding-priority-list
|
|
333 (if (featurep 'mule)
|
|
334 '(utf-16-little-endian-bom
|
|
335 utf-16-bom
|
985
|
336 utf-8-bom
|
771
|
337 iso-7
|
|
338 no-conversion
|
|
339 utf-8
|
|
340 iso-8-1
|
|
341 iso-8-2
|
|
342 iso-8-designate
|
|
343 iso-lock-shift
|
|
344 shift-jis
|
|
345 big5
|
|
346 utf-16-little-endian
|
|
347 utf-16
|
|
348 ucs-4)
|
|
349 '(utf-16-little-endian-bom
|
|
350 utf-16-bom
|
985
|
351 utf-8-bom
|
771
|
352 no-conversion
|
|
353 utf-8
|
|
354 utf-16-little-endian
|
|
355 utf-16
|
|
356 ucs-4))))
|
|
357
|
|
358 (defun reset-language-environment ()
|
|
359 "Reset coding system environment of XEmacs to the default status.
|
|
360 All basic coding system variables are set to their default values, as
|
|
361 are the coding categories used for automatic detection and their
|
|
362 priority.
|
|
363
|
|
364 BE VERY CERTAIN YOU WANT TO DO THIS BEFORE DOING IT!
|
|
365
|
|
366 For more information, see `reset-coding-system-defaults' and
|
|
367 `reset-coding-categories-to-default'."
|
|
368 (reset-coding-system-defaults)
|
|
369 (reset-coding-categories-to-default))
|
|
370
|
|
371 ;; Initialize everything so that the remaining Lisp files can contain
|
|
372 ;; extended characters. (They will be in ISO-7 format)
|
|
373
|
|
374 ;; !!####!! The Lisp files should all be in UTF-8!!! That way, all
|
|
375 ;; special characters appear as high bits and there's no problem with
|
|
376 ;; the Lisp parser trying to read a Mule file and getting all screwed
|
|
377 ;; up. The only other thing then would be characters; we just need to
|
|
378 ;; modify the Lisp parser to read the stuff directly after a ? as
|
|
379 ;; UTF-8 and return a 30-bit value directly, and modify the character
|
|
380 ;; routines a bit to allow such a beast to exist. MAKE IT A POINT TO
|
|
381 ;; IMPLEMENT THIS AS ONE OF MY FUTURE PROJECTS. --ben
|
|
382
|
|
383 (reset-language-environment)
|
|
384
|
|
385 ;;; code-init.el ends here
|