771
|
1 ;;; code-init.el --- Handle coding system default values
|
|
2
|
853
|
3 ;; Copyright (C) 2001, 2002 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
|
|
72 (defvar coding-system-variable-default-value-table
|
|
73 '((buffer-file-coding-system-for-read binary raw-text undecided raw-text undecided)
|
|
74 (default-buffer-file-coding-system binary binary iso-2022-8 raw-text-dos mswindows-multibyte-dos)
|
|
75 (file-name binary binary binary raw-text-dos mswindows-multibyte-system-default-dos)
|
|
76 (native binary binary binary raw-text-dos mswindows-multibyte-system-default-dos)
|
|
77 (keyboard binary raw-text undecided raw-text undecided)
|
|
78 ;; the `terminal' coding system is used for output to stderr. such
|
|
79 ;; streams do automatic lf->crlf encoding in the C library, so we need
|
|
80 ;; to not do the same translations ourselves.
|
|
81 (terminal binary binary binary binary mswindows-multibyte-unix)
|
|
82 (default-process-coding-system-read binary raw-text undecided raw-text undecided)
|
853
|
83 (default-process-coding-system-write binary binary binary raw-text mswindows-multibyte-system-default)
|
771
|
84 (no-conversion-coding-system-mapping binary raw-text raw-text raw-text mswindows-multibyte)
|
|
85 ))
|
|
86
|
|
87 (defvar coding-system-default-configuration-list
|
|
88 '(unix-no-mule-no-eol-detection
|
|
89 unix-no-mule-eol-detection
|
|
90 unix-mule
|
|
91 windows-no-mule
|
|
92 windows-mule))
|
|
93
|
|
94 (defvar coding-system-default-variable-list
|
|
95 '(buffer-file-coding-system-for-read
|
|
96 default-buffer-file-coding-system
|
|
97 file-name
|
|
98 native
|
|
99 keyboard
|
|
100 terminal
|
|
101 default-process-coding-system-read
|
|
102 default-process-coding-system-write))
|
|
103
|
|
104 (defun get-coding-system-variable (var)
|
|
105 "Return the value of a basic coding system variable.
|
|
106 This is intended as a uniform interface onto the coding system settings that
|
|
107 control how encoding detection and conversion works. See
|
|
108 `coding-system-variable-default-value' for a list of the possible values of
|
|
109 VAR."
|
|
110 (case var
|
|
111 (buffer-file-coding-system-for-read buffer-file-coding-system-for-read)
|
|
112 (default-buffer-file-coding-system
|
|
113 (default-value 'buffer-file-coding-system))
|
|
114 (file-name (coding-system-aliasee 'file-name))
|
|
115 (native (coding-system-aliasee 'native))
|
|
116 (keyboard (coding-system-aliasee 'keyboard))
|
|
117 (terminal (coding-system-aliasee 'terminal))
|
|
118 (default-process-coding-system-read (car default-process-coding-system))
|
|
119 (default-process-coding-system-write (cdr default-process-coding-system))
|
|
120 (t (error 'invalid-constant "Invalid coding system variable" var))))
|
|
121
|
|
122 (defun set-coding-system-variable (var value)
|
|
123 "Set a basic coding system variable to VALUE.
|
|
124 This is intended as a uniform interface onto the coding system settings that
|
|
125 control how encoding detection and conversion works. See
|
|
126 `coding-system-variable-default-value' for a list of the possible values of
|
|
127 VAR."
|
|
128 (case var
|
|
129 (buffer-file-coding-system-for-read
|
|
130 (set-buffer-file-coding-system-for-read value))
|
|
131 (default-buffer-file-coding-system
|
|
132 (set-default-buffer-file-coding-system value))
|
|
133 (file-name (define-coding-system-alias 'file-name value))
|
|
134 (native (define-coding-system-alias 'native value))
|
|
135 (keyboard (set-keyboard-coding-system value))
|
|
136 (terminal (set-terminal-coding-system value))
|
|
137 (default-process-coding-system-read
|
|
138 (setq default-process-coding-system
|
|
139 (cons value (cdr default-process-coding-system))))
|
|
140 (default-process-coding-system-write
|
|
141 (setq default-process-coding-system
|
|
142 (cons (car default-process-coding-system) value)))
|
|
143 (t (error 'invalid-constant "Invalid coding system variable" var))))
|
|
144
|
|
145 (defun coding-system-variable-default-value (var &optional config)
|
|
146 "Return the appropriate default value for a coding system variable.
|
|
147
|
|
148 VAR specifies the variable, and CONFIG the configuration, defaulting
|
|
149 to the current system configuration (as returned by
|
|
150 `coding-system-current-system-configuration').
|
|
151
|
|
152 The table of default values looks like this: (see below for abbreviations)
|
|
153
|
|
154
|
853
|
155 Unix Unix+EOL Unix+Mule MSW MSW+Mule
|
771
|
156 ------------------------------------------------------------------------------
|
853
|
157 bfcs-for-read binary raw-text undecided raw-text undecided
|
|
158 default bfcs binary binary iso-2022-8 raw-text-dos MSW-MB-dos
|
|
159 file-name binary binary binary raw-text-dos MSW-MB-SD-dos
|
|
160 native binary binary binary raw-text-dos MSW-MB-SD-dos
|
|
161 keyboard binary raw-text undecided raw-text undecided
|
|
162 terminal binary binary binary binary MSW-MB-unix
|
|
163 process-read binary raw-text undecided raw-text undecided
|
|
164 process-write binary binary binary raw-text MSW-MB-SD
|
|
165 no-conv-cs binary raw-text raw-text raw-text MSW-MB
|
771
|
166
|
|
167
|
|
168 VAR can be one of: (abbreviations in parens)
|
|
169
|
|
170 `buffer-file-coding-system-for-read' (bfcs-for-read)
|
|
171
|
|
172 Lisp variable of the same name; the default coding system used when
|
|
173 reading in a file, in the absence of more specific settings. (See
|
|
174 `insert-file-contents' for a description of exactly how a file's
|
|
175 coding system is determined when it's read in.)
|
|
176
|
|
177 `default-buffer-file-coding-system' (default bfcs)
|
|
178
|
|
179 Default value of `buffer-file-coding-system', the buffer-local
|
|
180 variable specifying a file's coding system to be used when it is
|
|
181 written out. Set using `set-default-buffer-file-coding-system' (or
|
|
182 the primitive `setq-default'). When a file is read in,
|
|
183 `buffer-file-coding-system' for that file is set from the coding
|
|
184 system used to read the file in; the default value applies to newly
|
|
185 created files.
|
|
186
|
|
187 `file-name' (file-name)
|
|
188
|
|
189 The coding system named `file-name'. Changed using
|
|
190 `define-coding-system-alias'. Used internally when passing file
|
|
191 names to or from system API's, unless the particular API specifies
|
|
192 another coding system.
|
|
193
|
|
194 `native' (native)
|
|
195
|
|
196 The coding system named `native'. Changed using
|
|
197 `define-coding-system-alias'. Used internally when passing
|
|
198 non-file-name text to or from system API's, unless the particular
|
|
199 API specifies another coding system.
|
|
200
|
|
201 `keyboard' (keyboard)
|
|
202
|
|
203 #### fill in
|
|
204
|
|
205 `terminal' (terminal)
|
|
206
|
|
207 #### fill in
|
|
208
|
|
209 `default-process-coding-system-read' (process-read)
|
|
210
|
|
211 #### fill in
|
|
212
|
|
213 `default-process-coding-system-write' (process-write)
|
|
214
|
|
215 #### fill in
|
|
216
|
|
217 `no-conversion-coding-system-mapping' (no-conv-cs)
|
|
218
|
|
219 Coding system used when category `no-conversion' is detected.
|
|
220
|
|
221
|
|
222 CONFIG is one of: (abbreviations in parens)
|
|
223
|
|
224 `unix-no-mule-no-eol-detection' (Unix)
|
|
225
|
|
226 Unix, no Mule support, no automatic EOL detection. (Controlled by
|
|
227 `eol-detection-enabled-p', which is set by the command-line flag
|
|
228 -enable-eol-detection or the configure flag --with-default-eol-detection.)
|
|
229
|
|
230 `unix-no-mule-eol-detection' (Unix+EOL)
|
|
231
|
|
232 Unix, no Mule support, automatic EOL detection.
|
|
233
|
|
234 `unix-mule' (Unix+Mule)
|
|
235
|
|
236 Unix, Mule support.
|
|
237
|
|
238 `windows-no-mule' (MSW)
|
|
239
|
|
240 MS Windows or Cygwin, no Mule support.
|
|
241
|
|
242 `windows-mule'. (MSW+Mule)
|
|
243
|
|
244 MS Windows or Cygwin, Mule support.
|
|
245
|
|
246
|
|
247 The following coding system abbreviations are also used in the table:
|
|
248
|
|
249 MSW-MB = mswindows-multibyte
|
|
250 MSW-MB = mswindows-multibyte-system-default
|
|
251 "
|
|
252 (setq config (or config (coding-system-current-system-configuration)))
|
|
253 (let ((defs (cdr (assq var coding-system-variable-default-value-table))))
|
|
254 (or defs (error 'invalid-constant "Invalid coding system variable" var))
|
|
255 (let ((pos (position config coding-system-default-configuration-list)))
|
|
256 (or pos (error 'invalid-constant "Invalid coding system configuration"
|
|
257 config))
|
|
258 (nth pos defs))))
|
|
259
|
|
260 (defun reset-coding-system-defaults (&optional config)
|
|
261 "Reset all basic coding system variables are set to their default values.
|
|
262 See `coding-system-variable-default-value'."
|
|
263 (setq config (or config (coding-system-current-system-configuration)))
|
|
264 (mapcar #'(lambda (var)
|
|
265 (set-coding-system-variable
|
|
266 var (coding-system-variable-default-value var config)))
|
|
267 coding-system-default-variable-list))
|
|
268
|
|
269 (defun reset-coding-categories-to-default ()
|
|
270 "Reset all coding categories (used for automatic detection) to their defaults.
|
|
271
|
|
272 The order of priorities of coding categories and the coding system
|
|
273 bound to each category are as follows:
|
|
274
|
|
275 coding category coding system
|
|
276 --------------------------------------------------
|
|
277 utf-16-little-endian-bom utf-16-little-endian
|
|
278 utf-16-bom utf-16-bom
|
|
279 iso-7 iso-2022-7bit
|
|
280 no-conversion raw-text
|
|
281 utf-8 utf-8
|
|
282 iso-8-1 iso-8859-1
|
|
283 iso-8-2 ctext (iso-8859-1 alias)
|
|
284 iso-8-designate ctext (iso-8859-1 alias)
|
|
285 iso-lock-shift iso-2022-lock
|
|
286 shift-jis shift-jis
|
|
287 big5 big5
|
|
288 utf-16-little-endian utf-16-little-endian
|
|
289 utf-16 utf-16
|
|
290 ucs-4 ucs-4
|
|
291 "
|
|
292 ;; #### What a mess! This needs to be overhauled.
|
|
293
|
|
294 ;; The old table (from FSF synch?) was not what we use (cf mule-coding.el),
|
|
295 ;; and as documented iso-8-designate is inconsistent with iso-2022-8bit-ss2.
|
|
296 ;; The order of priorities of coding categories and the coding system
|
|
297 ;; bound to each category are as follows:
|
|
298 ;;
|
|
299 ;; coding category coding system
|
|
300 ;; --------------------------------------------------
|
|
301 ;; iso-8-2 iso-8859-1
|
|
302 ;; iso-8-1 iso-8859-1
|
|
303 ;; iso-7 iso-2022-7bit
|
|
304 ;; iso-lock-shift iso-2022-lock
|
|
305 ;; iso-8-designate iso-2022-8bit-ss2
|
|
306 ;; no-conversion raw-text
|
|
307 ;; shift-jis shift_jis
|
|
308 ;; big5 big5
|
|
309 ;; ucs-4 ----
|
|
310 ;; utf-8 ----
|
|
311 (when (featurep 'mule)
|
|
312 (set-coding-category-system 'iso-7 'iso-2022-7)
|
|
313 (set-coding-category-system 'iso-8-1 'iso-8859-1)
|
|
314 (set-coding-category-system 'iso-8-2 'ctext)
|
|
315 (set-coding-category-system 'iso-lock-shift 'iso-2022-lock)
|
|
316 (set-coding-category-system 'iso-8-designate 'ctext)
|
|
317 (if (find-coding-system 'shift-jis)
|
|
318 (set-coding-category-system 'shift-jis 'shift-jis))
|
|
319 (if (find-coding-system 'big5)
|
|
320 (set-coding-category-system 'big5 'big5))
|
|
321 )
|
|
322 (set-coding-category-system
|
|
323 'no-conversion
|
|
324 (coding-system-variable-default-value 'no-conversion-coding-system-mapping))
|
|
325 (set-coding-category-system 'ucs-4 'ucs-4)
|
|
326 (set-coding-category-system 'utf-8 'utf-8)
|
|
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
|
|
336 iso-7
|
|
337 no-conversion
|
|
338 utf-8
|
|
339 iso-8-1
|
|
340 iso-8-2
|
|
341 iso-8-designate
|
|
342 iso-lock-shift
|
|
343 shift-jis
|
|
344 big5
|
|
345 utf-16-little-endian
|
|
346 utf-16
|
|
347 ucs-4)
|
|
348 '(utf-16-little-endian-bom
|
|
349 utf-16-bom
|
|
350 no-conversion
|
|
351 utf-8
|
|
352 utf-16-little-endian
|
|
353 utf-16
|
|
354 ucs-4))))
|
|
355
|
|
356 (defun reset-language-environment ()
|
|
357 "Reset coding system environment of XEmacs to the default status.
|
|
358 All basic coding system variables are set to their default values, as
|
|
359 are the coding categories used for automatic detection and their
|
|
360 priority.
|
|
361
|
|
362 BE VERY CERTAIN YOU WANT TO DO THIS BEFORE DOING IT!
|
|
363
|
|
364 For more information, see `reset-coding-system-defaults' and
|
|
365 `reset-coding-categories-to-default'."
|
|
366 (reset-coding-system-defaults)
|
|
367 (reset-coding-categories-to-default))
|
|
368
|
|
369 ;; Initialize everything so that the remaining Lisp files can contain
|
|
370 ;; extended characters. (They will be in ISO-7 format)
|
|
371
|
|
372 ;; !!####!! The Lisp files should all be in UTF-8!!! That way, all
|
|
373 ;; special characters appear as high bits and there's no problem with
|
|
374 ;; the Lisp parser trying to read a Mule file and getting all screwed
|
|
375 ;; up. The only other thing then would be characters; we just need to
|
|
376 ;; modify the Lisp parser to read the stuff directly after a ? as
|
|
377 ;; UTF-8 and return a 30-bit value directly, and modify the character
|
|
378 ;; routines a bit to allow such a beast to exist. MAKE IT A POINT TO
|
|
379 ;; IMPLEMENT THIS AS ONE OF MY FUTURE PROJECTS. --ben
|
|
380
|
|
381 (reset-language-environment)
|
|
382
|
|
383 ;;; code-init.el ends here
|