comparison lisp/code-init.el @ 4989:d2ec55325515

make utf-8 default for Cygwin 1.7, rewrite init code determining default coding systems -------------------- ChangeLog entries follow: -------------------- lisp/ChangeLog addition: 2010-02-06 Ben Wing <ben@xemacs.org> * code-init.el: * code-init.el (set-eol-detection): * code-init.el (coding-system-current-system-configuration): * code-init.el (coding-system-default-configuration-table): New. * code-init.el (no-mule-no-eol-detection): * code-init.el (define-coding-system-default-configuration): New. * code-init.el (coding-system-variable-default-value-table): Removed. * code-init.el (no-mule-eol-detection): * code-init.el (coding-system-default-configuration-list): Removed. * code-init.el (coding-system-default-variable-list): * code-init.el (get-coding-system-variable): * code-init.el (set-coding-system-variable): * code-init.el (coding-system-variable-default-value): * code-init.el (reset-coding-categories-to-default): Significant clean-up, add Cygwin-UTF-8 support. 1. Shorten the names of the coding system variables to follow what used to be considered the "abbreviations": default-process-coding-system-read -> process-read default-process-coding-system-write -> process-write buffer-file-coding-system-for-read -> bfcs-for-read default-buffer-file-coding-system -> default-bfcs no-conversion-coding-system-mapping -> no-conv-cs 2. Instead of listing all the defaults in a big, strangely organized table, use a new function `define-coding-system-default-configuration' to define a particular configuration. This uses a hash table stored in `coding-system-default-configuration-table'. Rewrite `coding-system-variable-default-value' appropriately. 3. Rename configurations to eliminate `unix' from the name: unix-no-mule-no-eol-detection -> no-mule-no-eol-detection unix-no-mule-eol-detection -> no-mule-eol-detection unix-mule -> mule This is because these are really for all systems but Windows, not just Unix. 4. Add configuration `cygwin-utf-8', enabled when (featurep 'cygwin-use-utf-8). Uses `utf-8' for all defaults except for `bfcs-for-read', which is `undecided'.
author Ben Wing <ben@xemacs.org>
date Sat, 06 Feb 2010 03:59:18 -0600
parents 1d74a1d115ee
children 308d34e9f07d
comparison
equal deleted inserted replaced
4918:c914214b788d 4989:d2ec55325515
1 ;;; code-init.el --- Handle coding system default values 1 ;;; code-init.el --- Handle coding system default values
2 2
3 ;; Copyright (C) 2001, 2002, 2003 Ben Wing. 3 ;; Copyright (C) 2001, 2002, 2003, 2010 Ben Wing.
4 4
5 ;; This file is part of XEmacs. 5 ;; This file is part of XEmacs.
6 6
7 ;; XEmacs is free software; you can redistribute it and/or modify it 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 8 ;; under the terms of the GNU General Public License as published by
18 ;; along with XEmacs; see the file COPYING. If not, write to the 18 ;; along with XEmacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA. 20 ;; Boston, MA 02111-1307, USA.
21 21
22 ;;; Commentary: 22 ;;; Commentary:
23
24 ;; Author: Ben wing, 2001?
23 25
24 ;; Placed in a separate file so it can be loaded after the various 26 ;; 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 27 ;; coding systems have been created, because we'll be using them at
26 ;; load time. 28 ;; load time.
27 29
58 EOL detection is enabled by default on Windows or when international (Mule) 60 EOL detection is enabled by default on Windows or when international (Mule)
59 support is compiled into this XEmacs. Otherwise, it is currently off by 61 support is compiled into this XEmacs. Otherwise, it is currently off by
60 default, but this may change. NOTE: You *REALLY* should not turn off EOL 62 default, but this may change. NOTE: You *REALLY* should not turn off EOL
61 detection on Windows! Your files will have lots of annoying ^M's in them 63 detection on Windows! Your files will have lots of annoying ^M's in them
62 if you do this." 64 if you do this."
63 (dolist (x '(buffer-file-coding-system-for-read 65 (dolist (x '(bfcs-for-read
64 keyboard 66 keyboard
65 default-process-coding-system-read 67 process-read
66 no-conversion-coding-system-mapping)) 68 no-conv-cs))
67 (set-coding-system-variable 69 (set-coding-system-variable
68 x (coding-system-change-eol-conversion (get-coding-system-variable x) 70 x (coding-system-change-eol-conversion (get-coding-system-variable x)
69 (if flag nil 'lf))))) 71 (if flag nil 'lf)))))
70 72
71 (defun coding-system-current-system-configuration () 73 (defun coding-system-current-system-configuration ()
72 (cond ((memq system-type '(windows-nt cygwin32)) 74 "Function to decide which default coding system configuration applies."
75 (cond ((featurep 'cygwin-use-utf-8) 'cygwin-utf-8)
76 ((memq system-type '(windows-nt cygwin32))
73 (if (featurep 'mule) 'windows-mule 'windows-no-mule)) 77 (if (featurep 'mule) 'windows-mule 'windows-no-mule))
74 ((featurep 'mule) 'unix-mule) 78 ((featurep 'mule) 'mule)
75 (eol-detection-enabled-p 'unix-no-mule-eol-detection) 79 (eol-detection-enabled-p 'no-mule-eol-detection)
76 (t 'unix-no-mule-no-eol-detection))) 80 (t 'no-mule-no-eol-detection)))
81
82 (defvar coding-system-default-configuration-table (make-hash-table))
83
84 (defun define-coding-system-default-configuration (name doc props)
85 (puthash name (nconc `(doc ,doc) props)
86 coding-system-default-configuration-table))
77 87
78 ;; NOTE NOTE NOTE: These values may get overridden when the language 88 ;; NOTE NOTE NOTE: These values may get overridden when the language
79 ;; environment is initialized (set-language-environment-coding-systems). 89 ;; environment is initialized (set-language-environment-coding-systems).
80 (defvar coding-system-variable-default-value-table 90 (define-coding-system-default-configuration
81 '((buffer-file-coding-system-for-read 91 'no-mule-no-eol-detection
82 binary raw-text undecided raw-text undecided) 92 "No Mule support, EOL detection not enabled."
83 (default-buffer-file-coding-system 93 '(bfcs-for-read binary
84 ;; #### iso-2022-8 with no eol specified? can that be OK? 94 default-bfcs binary
85 binary binary iso-2022-8 raw-text-dos mswindows-multibyte-dos) 95 process-read binary
86 (native 96 process-write binary
87 binary binary binary raw-text-dos mswindows-multibyte-system-default-dos) 97 keyboard binary
88 (keyboard 98 native binary
89 binary raw-text undecided-unix raw-text undecided-unix) 99 no-conv-cs binary
90 ;; the `terminal' coding system is used for output to stderr. such 100 terminal binary))
91 ;; streams do automatic lf->crlf encoding in the C library, so we need 101
92 ;; to not do the same translations ourselves. 102 (define-coding-system-default-configuration
93 (terminal 103 'no-mule-eol-detection
94 binary binary binary binary mswindows-multibyte-unix) 104 "No Mule support, EOL detection enabled."
95 (default-process-coding-system-read 105 '(bfcs-for-read raw-text
96 binary raw-text undecided raw-text undecided) 106 default-bfcs binary
97 (default-process-coding-system-write 107 process-read raw-text
98 binary binary binary raw-text mswindows-multibyte-system-default) 108 process-write binary
99 (no-conversion-coding-system-mapping 109 keyboard raw-text
100 binary raw-text raw-text raw-text mswindows-multibyte) 110 native binary
101 )) 111 no-conv-cs raw-text
102 112 terminal binary))
103 (defvar coding-system-default-configuration-list 113
104 '(unix-no-mule-no-eol-detection 114 (define-coding-system-default-configuration
105 unix-no-mule-eol-detection 115 'mule
106 unix-mule 116 "Mule support enabled."
107 windows-no-mule 117 '(bfcs-for-read undecided
108 windows-mule)) 118 default-bfcs iso-2022-8
119 process-read undecided
120 process-write binary
121 keyboard undecided-unix
122 native binary
123 no-conv-cs raw-text
124 terminal binary))
125
126 (define-coding-system-default-configuration
127 'windows-no-mule
128 "Microsoft Windows, no Mule support."
129 '(bfcs-for-read raw-text
130 default-bfcs raw-text-dos
131 process-read raw-text
132 process-write raw-text
133 keyboard raw-text
134 native raw-text-dos
135 no-conv-cs raw-text
136 terminal binary))
137
138 (define-coding-system-default-configuration
139 'windows-mule
140 "Microsoft Windows, Mule support enabled."
141 '(bfcs-for-read undecided
142 default-bfcs mswindows-multibyte-dos
143 process-read undecided
144 process-write mswindows-multibyte-system-default
145 keyboard undecided-unix
146 native mswindows-multibyte-system-default-dos
147 no-conv-cs mswindows-multibyte
148 terminal mswindows-multibyte-unix))
149
150 (define-coding-system-default-configuration
151 'cygwin-utf-8
152 "Mule support enabled."
153 '(bfcs-for-read undecided
154 default-bfcs utf-8
155 process-read utf-8
156 process-write utf-8
157 keyboard utf-8
158 native utf-8
159 no-conv-cs utf-8
160 terminal utf-8))
109 161
110 (defvar coding-system-default-variable-list 162 (defvar coding-system-default-variable-list
111 '(buffer-file-coding-system-for-read 163 '(bfcs-for-read
112 default-buffer-file-coding-system 164 default-bfcs
113 native 165 native
114 keyboard 166 keyboard
115 terminal 167 terminal
116 default-process-coding-system-read 168 process-read
117 default-process-coding-system-write 169 process-write
118 no-conversion-coding-system-mapping)) 170 no-conv-cs))
119 171
120 (defun get-coding-system-variable (var) 172 (defun get-coding-system-variable (var)
121 "Return the value of a basic coding system variable. 173 "Return the value of a basic coding system variable.
122 This is intended as a uniform interface onto the coding system settings that 174 This is intended as a uniform interface onto the coding system settings that
123 control how encoding detection and conversion works. See 175 control how encoding detection and conversion works. See
124 `coding-system-variable-default-value' for a list of the possible values of 176 `coding-system-variable-default-value' for a list of the possible values of
125 VAR." 177 VAR."
126 (case var 178 (case var
127 (buffer-file-coding-system-for-read buffer-file-coding-system-for-read) 179 (bfcs-for-read buffer-file-coding-system-for-read)
128 (default-buffer-file-coding-system 180 (default-bfcs
129 (default-value 'buffer-file-coding-system)) 181 (default-value 'buffer-file-coding-system))
130 (native (coding-system-aliasee 'native)) 182 (native (coding-system-aliasee 'native))
131 (keyboard (coding-system-aliasee 'keyboard)) 183 (keyboard (coding-system-aliasee 'keyboard))
132 (terminal (coding-system-aliasee 'terminal)) 184 (terminal (coding-system-aliasee 'terminal))
133 (default-process-coding-system-read (car default-process-coding-system)) 185 (process-read (car default-process-coding-system))
134 (default-process-coding-system-write (cdr default-process-coding-system)) 186 (process-write (cdr default-process-coding-system))
135 (no-conversion-coding-system-mapping 187 (no-conv-cs
136 (coding-category-system 'no-conversion)) 188 (coding-category-system 'no-conversion))
137 (t (error 'invalid-constant "Invalid coding system variable" var)))) 189 (t (error 'invalid-constant "Invalid coding system variable" var))))
138 190
139 (defun set-coding-system-variable (var value) 191 (defun set-coding-system-variable (var value)
140 "Set a basic coding system variable to VALUE. 192 "Set a basic coding system variable to VALUE.
141 This is intended as a uniform interface onto the coding system settings that 193 This is intended as a uniform interface onto the coding system settings that
142 control how encoding detection and conversion works. See 194 control how encoding detection and conversion works. See
143 `coding-system-variable-default-value' for a list of the possible values of 195 `coding-system-variable-default-value' for a list of the possible values of
144 VAR." 196 VAR."
145 (case var 197 (case var
146 (buffer-file-coding-system-for-read 198 (bfcs-for-read
147 (set-buffer-file-coding-system-for-read value)) 199 (set-buffer-file-coding-system-for-read value))
148 (default-buffer-file-coding-system 200 (default-bfcs
149 (set-default-buffer-file-coding-system value)) 201 (set-default-buffer-file-coding-system value))
150 (native (define-coding-system-alias 'native value)) 202 (native (define-coding-system-alias 'native value))
151 (keyboard (set-keyboard-coding-system value)) 203 (keyboard (set-keyboard-coding-system value))
152 (terminal (set-terminal-coding-system value)) 204 (terminal (set-terminal-coding-system value))
153 (default-process-coding-system-read 205 (process-read
154 (setq default-process-coding-system 206 (setq default-process-coding-system
155 (cons value (cdr default-process-coding-system)))) 207 (cons value (cdr default-process-coding-system))))
156 (default-process-coding-system-write 208 (process-write
157 (setq default-process-coding-system 209 (setq default-process-coding-system
158 (cons (car default-process-coding-system) value))) 210 (cons (car default-process-coding-system) value)))
159 (no-conversion-coding-system-mapping 211 (no-conv-cs
160 (set-coding-category-system 'no-conversion value)) 212 (set-coding-category-system 'no-conversion value))
161 (t (error 'invalid-constant "Invalid coding system variable" var)))) 213 (t (error 'invalid-constant "Invalid coding system variable" var))))
162 214
163 (defun coding-system-variable-default-value (var &optional config) 215 (defun coding-system-variable-default-value (var &optional config)
164 "Return the appropriate default value for a coding system variable. 216 "Return the appropriate default value for a coding system variable.
168 `coding-system-current-system-configuration'). 220 `coding-system-current-system-configuration').
169 221
170 The table of default values looks like this: (see below for abbreviations) 222 The table of default values looks like this: (see below for abbreviations)
171 223
172 224
173 Unix Unix+EOL Unix+Mule MSW MSW+Mule 225 NoMule NoMuleEOL Mule MSW MSWMule CygUTF
174 ----------------------------------------------------------------------------- 226 ------------------------------------------------------------------------------
175 bfcs-for-read binary raw-text undecided raw-text undecided 227 bfcs-for-read binary raw-text undecided raw-text undecided undecided
176 default bfcs binary binary iso-2022-8 raw-text-dos MSW-MB-dos 228 default-bfcs binary binary iso-2022-8 raw-text-dos MSW-MB-dos utf-8
177 native binary binary binary raw-text-dos MSW-MB-SD-dos 229 native binary binary binary raw-text-dos MSW-MB-SD-dos utf-8
178 keyboard binary raw-text undecided-unix raw-text undecided-unix 230 keyboard binary raw-text undecided- raw-text undecided- utf-8
179 terminal binary binary binary binary MSW-MB-unix 231 unix unix
180 process-read binary raw-text undecided raw-text undecided 232 terminal binary binary binary binary MSW-MB-unix utf-8
181 process-write binary binary binary raw-text MSW-MB-SD 233 process-read binary raw-text undecided raw-text undecided utf-8
182 no-conv-cs binary raw-text raw-text raw-text MSW-MB 234 process-write binary binary binary raw-text MSW-MB-SD utf-8
183 235 no-conv-cs binary raw-text raw-text raw-text MSW-MB utf-8
184 236
185 VAR can be one of: (abbreviations in parens) 237
186 238 VAR can be one of:
187 `buffer-file-coding-system-for-read' (bfcs-for-read) 239
240 `bfcs-for-read'
188 241
189 Lisp variable of the same name; the default coding system used when 242 Lisp variable of the same name; the default coding system used when
190 reading in a file, in the absence of more specific settings. (See 243 reading in a file, in the absence of more specific settings. (See
191 `insert-file-contents' for a description of exactly how a file's 244 `insert-file-contents' for a description of exactly how a file's
192 coding system is determined when it's read in.) 245 coding system is determined when it's read in.)
193 246
194 `default-buffer-file-coding-system' (default bfcs) 247 `default-bfcs'
195 248
196 Default value of `buffer-file-coding-system', the buffer-local 249 Default value of `buffer-file-coding-system', the buffer-local
197 variable specifying a file's coding system to be used when it is 250 variable specifying a file's coding system to be used when it is
198 written out. Set using `set-default-buffer-file-coding-system' (or 251 written out. Set using `set-default-buffer-file-coding-system' (or
199 the primitive `setq-default'). When a file is read in, 252 the primitive `setq-default'). When a file is read in,
200 `buffer-file-coding-system' for that file is set from the coding 253 `buffer-file-coding-system' for that file is set from the coding
201 system used to read the file in; the default value applies to newly 254 system used to read the file in; the default value applies to newly
202 created files. 255 created files.
203 256
204 `native' (native) 257 `native'
205 258
206 The coding system named `native'. Changed using 259 The coding system named `native'. Changed using
207 `define-coding-system-alias'. Used internally when passing 260 `define-coding-system-alias'. Used internally when passing
208 text to or from system API's, unless the particular 261 text to or from system API's, unless the particular
209 API specifies another coding system. 262 API specifies another coding system.
210 263
211 `keyboard' (keyboard) 264 `keyboard'
212 265
213 #### fill in 266 #### fill in
214 267
215 `terminal' (terminal) 268 `terminal'
216 269
217 #### fill in 270 #### fill in
218 271
219 `default-process-coding-system-read' (process-read) 272 `process-read'
220 273
221 #### fill in 274 #### fill in
222 275
223 `default-process-coding-system-write' (process-write) 276 `process-write'
224 277
225 #### fill in 278 #### fill in
226 279
227 `no-conversion-coding-system-mapping' (no-conv-cs) 280 `no-conv-cs'
228 281
229 Coding system used when category `no-conversion' is detected. 282 Coding system used when category `no-conversion' is detected.
230 283
231 284
232 CONFIG is one of: (abbreviations in parens) 285 CONFIG is one of: (abbreviations in parens)
233 286
234 `unix-no-mule-no-eol-detection' (Unix) 287 `no-mule-no-eol-detection' (NoMule)
235 288
236 Unix, no Mule support, no automatic EOL detection. (Controlled by 289 Non-Windows, no Mule support, no automatic EOL detection. (Controlled by
237 `eol-detection-enabled-p', which is set by the command-line flag 290 `eol-detection-enabled-p', which is set by the command-line flag
238 -enable-eol-detection or the configure flag --with-default-eol-detection.) 291 -enable-eol-detection or the configure flag --with-default-eol-detection.)
239 292
240 `unix-no-mule-eol-detection' (Unix+EOL) 293 `unix-no-mule-eol-detection' (NoMuleEOL)
241 294
242 Unix, no Mule support, automatic EOL detection. 295 Non-Windows, no Mule support, automatic EOL detection.
243 296
244 `unix-mule' (Unix+Mule) 297 `unix-mule' (Mule)
245 298
246 Unix, Mule support. 299 Non-Windows, Mule support.
247 300
248 `windows-no-mule' (MSW) 301 `windows-no-mule' (MSW)
249 302
250 MS Windows or Cygwin, no Mule support. 303 MS Windows or old Cygwin, no Mule support.
251 304
252 `windows-mule'. (MSW+Mule) 305 `windows-mule' (MSWMule)
253 306
254 MS Windows or Cygwin, Mule support. 307 MS Windows or old Cygwin, Mule support.
255 308
309 `cygwin-utf-8' (CygUTF)
310
311 Cygwin 1.7 or later, which uses UTF-8 consistently.
256 312
257 The following coding system abbreviations are also used in the table: 313 The following coding system abbreviations are also used in the table:
258 314
259 MSW-MB = mswindows-multibyte 315 MSW-MB = mswindows-multibyte
260 MSW-MB = mswindows-multibyte-system-default 316 MSW-MB = mswindows-multibyte-system-default
261 " 317 "
262 (setq config (or config (coding-system-current-system-configuration))) 318 (setq config (or config (coding-system-current-system-configuration)))
263 (let ((defs (cdr (assq var coding-system-variable-default-value-table)))) 319 (or (memq var coding-system-default-variable-list)
264 (or defs (error 'invalid-constant "Invalid coding system variable" var)) 320 (error 'invalid-constant "Invalid coding system variable" var))
265 (let ((pos (position config coding-system-default-configuration-list))) 321 (let ((props (gethash config coding-system-default-configuration-table)))
266 (or pos (error 'invalid-constant "Invalid coding system configuration" 322 (or props (error 'invalid-constant "Invalid coding system configuration"
267 config)) 323 config))
268 (nth pos defs)))) 324 (getf props var)))
269 325
270 (defun reset-coding-system-defaults (&optional config) 326 (defun reset-coding-system-defaults (&optional config)
271 "Reset all basic coding system variables are set to their default values. 327 "Reset all basic coding system variables are set to their default values.
272 See `coding-system-variable-default-value'." 328 See `coding-system-variable-default-value'."
273 (setq config (or config (coding-system-current-system-configuration))) 329 (setq config (or config (coding-system-current-system-configuration)))
330 (if (find-coding-system 'big5) 386 (if (find-coding-system 'big5)
331 (set-coding-category-system 'big5 'big5)) 387 (set-coding-category-system 'big5 'big5))
332 ) 388 )
333 (set-coding-category-system 389 (set-coding-category-system
334 'no-conversion 390 'no-conversion
335 (coding-system-variable-default-value 'no-conversion-coding-system-mapping)) 391 (coding-system-variable-default-value 'no-conv-cs))
336 (set-coding-category-system 'ucs-4 'ucs-4) 392 (set-coding-category-system 'ucs-4 'ucs-4)
337 (set-coding-category-system 'utf-8 'utf-8) 393 (set-coding-category-system 'utf-8 'utf-8)
338 (set-coding-category-system 'utf-8-bom 'utf-8-bom) 394 (set-coding-category-system 'utf-8-bom 'utf-8-bom)
339 (set-coding-category-system 'utf-16-little-endian 'utf-16-little-endian) 395 (set-coding-category-system 'utf-16-little-endian 'utf-16-little-endian)
340 (set-coding-category-system 'utf-16 'utf-16) 396 (set-coding-category-system 'utf-16 'utf-16)