comparison lisp/mule/mule-files.el @ 108:360340f9fd5f r20-1b6

Import from CVS: tag r20-1b6
author cvs
date Mon, 13 Aug 2007 09:18:39 +0200
parents 364816949b59
children fe104dbd9147
comparison
equal deleted inserted replaced
107:523141596bda 108:360340f9fd5f
31 ;;;; #### also think more about `binary' vs. `no-conversion' 31 ;;;; #### also think more about `binary' vs. `no-conversion'
32 32
33 (setq-default file-coding-system 'iso-2022-8) 33 (setq-default file-coding-system 'iso-2022-8)
34 (put 'file-coding-system 'permanent-local t) 34 (put 'file-coding-system 'permanent-local t)
35 35
36 (defvar overriding-file-coding-system nil 36 (defvar coding-system-for-write nil
37 "Overriding coding system used when writing a file.
38 You should *bind* this, not set it. If this is non-nil, it specifies
39 the coding system that will be used when a file is wrote in, and
40 overrides `file-coding-system', `insert-file-contents-pre-hook',
41 etc. Use those variables instead of this one for permanent changes
42 to the environment.")
43
44 (defvar coding-system-for-read nil
37 "Overriding coding system used when reading a file. 45 "Overriding coding system used when reading a file.
38 You should *bind* this, not set it. If this is non-nil, it specifies 46 You should *bind* this, not set it. If this is non-nil, it specifies
39 the coding system that will be used when a file is read in, and 47 the coding system that will be used when a file is read in, and
40 overrides `file-coding-system-for-read', `file-coding-system-alist', 48 overrides `file-coding-system-for-read', `file-coding-system-alist',
41 etc. Use those variables instead of this one for permanent changes 49 etc. Use those variables instead of this one for permanent changes
45 "Coding system used when reading a file. 53 "Coding system used when reading a file.
46 This provides coarse-grained control; for finer-grained control, 54 This provides coarse-grained control; for finer-grained control,
47 use `file-coding-system-alist'. From a Lisp program, if you wish 55 use `file-coding-system-alist'. From a Lisp program, if you wish
48 to unilaterally specify the coding system used for one 56 to unilaterally specify the coding system used for one
49 particular operation, you should bind the variable 57 particular operation, you should bind the variable
50 `overriding-file-coding-system' rather than setting this variable, 58 `coding-system-for-read' rather than setting this variable,
51 which is intended to be used for global environment specification.") 59 which is intended to be used for global environment specification.")
52 60
53 (defvar file-coding-system-alist 61 (defvar file-coding-system-alist
54 ;; '(; ("\\.el$" . euc-japan) 62 ;; '(; ("\\.el$" . euc-japan)
55 '(("\\.el$" . iso-2022-8) 63 '(("\\.el$" . iso-2022-8)
60 ("/spool/mail/.*$" . convert-mbox-coding-system)) 68 ("/spool/mail/.*$" . convert-mbox-coding-system))
61 "Alist specifying the coding system used for particular files. 69 "Alist specifying the coding system used for particular files.
62 Each element of the alist is a cons of a regexp, specifying the files 70 Each element of the alist is a cons of a regexp, specifying the files
63 to be affected, and a coding system. This overrides the more 71 to be affected, and a coding system. This overrides the more
64 general specification in `file-coding-system-for-read', but is 72 general specification in `file-coding-system-for-read', but is
65 overridden by `overriding-file-coding-system'. 73 overridden by `coding-system-for-read'.
66 74
67 Instead of a coding system you may specify a function, and it will be 75 Instead of a coding system you may specify a function, and it will be
68 called after the file has been read in to decode the file. It is 76 called after the file has been read in to decode the file. It is
69 called with four arguments: FILENAME, VISIT, START, and END, the same 77 called with four arguments: FILENAME, VISIT, START, and END, the same
70 as the first four arguments to `insert-file-contents'.") 78 as the first four arguments to `insert-file-contents'.")
277 NOTE: When Mule support is enabled, the REPLACE argument is 285 NOTE: When Mule support is enabled, the REPLACE argument is
278 currently ignored. 286 currently ignored.
279 287
280 The coding system used for decoding the file is determined as follows: 288 The coding system used for decoding the file is determined as follows:
281 289
282 1. `overriding-file-coding-system', if non-nil. 290 1. `coding-system-for-read', if non-nil.
283 2. The result of `insert-file-contents-pre-hook', if non-nil. 291 2. The result of `insert-file-contents-pre-hook', if non-nil.
284 3. The matching value for this filename from `file-coding-system-alist', 292 3. The matching value for this filename from `file-coding-system-alist',
285 if any. 293 if any.
286 4. `file-coding-system-for-read', if non-nil. 294 4. `file-coding-system-for-read', if non-nil.
287 5. The coding system 'no-conversion. 295 5. The coding system 'no-conversion.
300 filename visit) 308 filename visit)
301 ;; determine the coding system to use, as described above. 309 ;; determine the coding system to use, as described above.
302 (setq coding-system 310 (setq coding-system
303 (or 311 (or
304 ;; #1. 312 ;; #1.
305 overriding-file-coding-system 313 coding-system-for-read
306 ;; #2. 314 ;; #2.
307 (run-special-hook-with-args 'insert-file-contents-pre-hook 315 (run-special-hook-with-args 'insert-file-contents-pre-hook
308 filename visit) 316 filename visit)
309 ;; #3. 317 ;; #3.
310 (let ((retval (find-file-coding-system-from-filename 318 (let ((retval (find-file-coding-system-from-filename
380 388
381 (defvar write-region-pre-hook nil 389 (defvar write-region-pre-hook nil
382 "A special hook to decide the coding system used for writing out a file. 390 "A special hook to decide the coding system used for writing out a file.
383 391
384 Before writing a file, `write-region' calls the functions on this hook 392 Before writing a file, `write-region' calls the functions on this hook
385 with arguments START, END, FILENAME, APPEND, VISIT, and CODING-SYTEM, 393 with arguments START, END, FILENAME, APPEND, VISIT, and CODING-SYSTEM,
386 the same as the corresponding arguments in the call to 394 the same as the corresponding arguments in the call to
387 `write-region'. 395 `write-region'.
388 396
389 The return value of the functions should be either 397 The return value of the functions should be either
390 398
429 Interactively, with a prefix arg, you will be prompted for the 437 Interactively, with a prefix arg, you will be prompted for the
430 coding system. 438 coding system.
431 See also `write-region-pre-hook' and `write-region-post-hook'." 439 See also `write-region-pre-hook' and `write-region-post-hook'."
432 (interactive "r\nFWrite region to file: \ni\ni\ni\nZCoding-system: ") 440 (interactive "r\nFWrite region to file: \ni\ni\ni\nZCoding-system: ")
433 (setq coding-system 441 (setq coding-system
434 (or (run-special-hook-with-args 442 (or coding-system-for-write
443 (run-special-hook-with-args
435 'write-region-pre-hook start end filename append visit lockname) 444 'write-region-pre-hook start end filename append visit lockname)
436 coding-system 445 coding-system
437 file-coding-system)) 446 file-coding-system))
438 (if (consp coding-system) 447 (if (consp coding-system)
439 coding-system 448 coding-system