comparison lisp/code-files.el @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents ca2d04c5710a
children e38acbeb1cae
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
1 ;;; code-files.el --- File I/O functions for XEmacs. 1 ;;; code-files.el --- File I/O functions for XEmacs.
2 2
3 ;; Copyright (C) 1992,93,94,95 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992,93,94,95 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Amdahl Corporation. 4 ;; Copyright (C) 1995 Amdahl Corporation.
5 ;; Copyright (C) 1995 Sun Microsystems. 5 ;; Copyright (C) 1995 Sun Microsystems.
6 ;; Copyright (C) 2001 Ben Wing.
6 7
7 ;; This file is part of XEmacs. 8 ;; This file is part of XEmacs.
8 9
9 ;; XEmacs is free software; you can redistribute it and/or modify it 10 ;; XEmacs is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by 11 ;; under the terms of the GNU General Public License as published by
33 ;; This file was derived from the former mule-files.el which has been removed 34 ;; This file was derived from the former mule-files.el which has been removed
34 ;; as of XEmacs 21.2.15. 35 ;; as of XEmacs 21.2.15.
35 36
36 ;;; Code: 37 ;;; Code:
37 38
38 (setq-default buffer-file-coding-system 'raw-text)
39 (put 'buffer-file-coding-system 'permanent-local t) 39 (put 'buffer-file-coding-system 'permanent-local t)
40
41 (defvar buffer-file-coding-system-when-loaded nil
42 "Coding system used when current buffer's file was read in.
43
44 Automatically buffer-local when set in any fashion. This is set
45 automatically when a file is loaded and is used when the file needs to be
46 reloaded (e.g. `revert-buffer'). Normally this will have the same value as
47 `buffer-file-coding-system', but the latter may be changed because it's
48 also used to specify the encoding when the file is written out.")
49 (make-variable-buffer-local 'buffer-file-coding-system-when-loaded)
50 (put 'buffer-file-coding-system-when-loaded 'permanent-local t)
40 51
41 (define-obsolete-variable-alias 52 (define-obsolete-variable-alias
42 'file-coding-system 53 'file-coding-system
43 'buffer-file-coding-system) 54 'buffer-file-coding-system)
44 55
45 (define-obsolete-variable-alias 56 (define-obsolete-variable-alias
46 'overriding-file-coding-system 57 'overriding-file-coding-system
47 'coding-system-for-read) 58 'coding-system-for-read)
48 59
49 (defvar buffer-file-coding-system-for-read 'undecided 60 ;; NOTE: The real default value is set in code-init.el.
50 "Coding system used when reading a file. 61 (defvar buffer-file-coding-system-for-read nil
62 "Default coding system used when reading a file.
51 This provides coarse-grained control; for finer-grained control, use 63 This provides coarse-grained control; for finer-grained control, use
52 `file-coding-system-alist'. From a Lisp program, if you wish to 64 `file-coding-system-alist'. From a Lisp program, if you wish to
53 unilaterally specify the coding system used for one particular 65 unilaterally specify the coding system used for one particular
54 operation, you should bind the variable `coding-system-for-read' 66 operation, you should bind the variable `coding-system-for-read'
55 rather than setting this variable, which is intended to be used for 67 rather than setting this variable, which is intended to be used for
56 global environment specification.") 68 global environment specification.
69
70 See `insert-file-contents' for a full description of how a file's
71 coding system is determined when it is read in.")
57 72
58 (define-obsolete-variable-alias 73 (define-obsolete-variable-alias
59 'file-coding-system-for-read 74 'file-coding-system-for-read
60 'buffer-file-coding-system-for-read) 75 'buffer-file-coding-system-for-read)
61 76
322 the whole thing because (1) it preserves some marker positions 337 the whole thing because (1) it preserves some marker positions
323 and (2) it puts less data in the undo list. 338 and (2) it puts less data in the undo list.
324 339
325 The coding system used for decoding the file is determined as follows: 340 The coding system used for decoding the file is determined as follows:
326 341
327 1. `coding-system-for-read', if non-nil. 342 1. `coding-system-for-read', if non-nil. (Intended as a temporary overriding
328 2. The result of `insert-file-contents-pre-hook', if non-nil. 343 mechanism for use by Lisp code.)
329 3. The matching value for this filename from 344 2. The result of `insert-file-contents-pre-hook', if non-nil. (Intended for
330 `file-coding-system-alist', if any. 345 handling tricky cases where the coding system of the file cannot be
331 4. `buffer-file-coding-system-for-read', if non-nil. 346 determined just by looking at the filename's extension and the standard
347 auto-detection mechanism isn't suitable, so more clever code is required.
348 In general, this hook should rarely be used.)
349 3. The matching value for this filename from `file-coding-system-alist',
350 if any. (Intended as the standard way of determining encoding from
351 the name, or esp. the extension, of the file. Akin to the way
352 file-name extensions are used under MS Windows to determine how to
353 handle the file, but more flexible.)
354 4. `buffer-file-coding-system-for-read', if non-nil. (Intended to be where
355 the global default coding system is set. Usually, you want to use
356 the value `undecided', to let the system auto-detect according to the
357 priorities set up by `set-coding-priority-list'. This is usually
358 initialized from the `coding-system' property of the current language
359 environment.)
332 5. The coding system 'raw-text. 360 5. The coding system 'raw-text.
333 361
334 If a local value for `buffer-file-coding-system' in the current buffer 362 If a local value for `buffer-file-coding-system' in the current buffer
335 does not exist, it is set to the coding system which was actually used 363 does not exist, it is set to the coding system which was actually used
336 for reading. 364 for reading.
365
366 #### This should explain in more detail the exact workings of the
367 coding-system determination procedure.
337 368
338 See also `insert-file-contents-access-hook', 369 See also `insert-file-contents-access-hook',
339 `insert-file-contents-pre-hook', `insert-file-contents-error-hook', 370 `insert-file-contents-pre-hook', `insert-file-contents-error-hook',
340 and `insert-file-contents-post-hook'." 371 and `insert-file-contents-post-hook'."
341 (let (return-val coding-system used-codesys) 372 (let (return-val coding-system used-codesys)
386 (set-marker endmark (+ (point) (nth 1 return-val))) 417 (set-marker endmark (+ (point) (nth 1 return-val)))
387 (if func 418 (if func
388 (unwind-protect 419 (unwind-protect
389 (save-excursion 420 (save-excursion
390 (let (buffer-read-only) 421 (let (buffer-read-only)
391 (funcall func (point) (marker-position endmark)))) 422 (if (>= (function-max-args func) 2)
423 ;; #### fuckme! Someone at FSF changed the calling
424 ;; convention of post-read-conversion. We try to
425 ;; support the old way. #### Should we kill this?
426 (funcall func (point) (marker-position endmark))
427 (funcall func (- (marker-position endmark) (point))))))
392 (if visit 428 (if visit
393 (progn 429 (progn
394 (set-buffer-auto-saved) 430 (set-buffer-auto-saved)
395 (set-buffer-modified-p nil))))) 431 (set-buffer-modified-p nil)))))
396 (setcar (cdr return-val) (- (marker-position endmark) (point)))) 432 (setcar (cdr return-val) (- (marker-position endmark) (point))))
397 ;; now finally set the buffer's `buffer-file-coding-system'. 433 ;; now finally set the buffer's `buffer-file-coding-system' ...
398 (if (run-hook-with-args-until-success 'insert-file-contents-post-hook 434 (if (run-hook-with-args-until-success 'insert-file-contents-post-hook
399 filename visit return-val) 435 filename visit return-val)
400 nil 436 nil
401 (if (local-variable-p 'buffer-file-coding-system (current-buffer)) 437 (if (local-variable-p 'buffer-file-coding-system (current-buffer))
402 ;; if buffer-file-coding-system is already local, just 438 ;; if buffer-file-coding-system is already local, just
405 (set-buffer-file-coding-system 441 (set-buffer-file-coding-system
406 (subsidiary-coding-system buffer-file-coding-system 442 (subsidiary-coding-system buffer-file-coding-system
407 (coding-system-eol-type coding-system))) 443 (coding-system-eol-type coding-system)))
408 ;; otherwise actually set buffer-file-coding-system. 444 ;; otherwise actually set buffer-file-coding-system.
409 (set-buffer-file-coding-system coding-system))) 445 (set-buffer-file-coding-system coding-system)))
446 ;; ... and `buffer-file-coding-system-when-loaded'. the machinations
447 ;; of set-buffer-file-coding-system cause the actual coding system
448 ;; object to be stored, so do that here, too.
449 (setq buffer-file-coding-system-when-loaded
450 (get-coding-system coding-system))
410 return-val)) 451 return-val))
411 452
412 (defvar write-region-pre-hook nil 453 (defvar write-region-pre-hook nil
413 "A special hook to decide the coding system used for writing out a file. 454 "A special hook to decide the coding system used for writing out a file.
414 455