Mercurial > hg > xemacs-beta
comparison lisp/code-files.el @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | de805c49cfc1 |
children | da8ed4261e83 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
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 | 6 |
7 ;; This file is part of XEmacs. | 7 ;; This file is part of XEmacs. |
8 | |
9 ;; This file is very similar to mule-files.el | |
8 | 10 |
9 ;; XEmacs is free software; you can redistribute it and/or modify it | 11 ;; 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 | 12 ;; under the terms of the GNU General Public License as published by |
11 ;; the Free Software Foundation; either version 2, or (at your option) | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
12 ;; any later version. | 14 ;; any later version. |
19 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
20 ;; along with XEmacs; see the file COPYING. If not, write to the | 22 ;; along with XEmacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
22 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02111-1307, USA. |
23 | 25 |
24 ;;; Synched up with: Not synched. | |
25 | |
26 ;;; Commentary: | 26 ;;; Commentary: |
27 | 27 |
28 ;; Derived from mule.el in the original Mule but heavily modified | 28 ;;; Derived from mule.el in the original Mule but heavily modified |
29 ;; by Ben Wing. | 29 ;;; by Ben Wing. |
30 | 30 |
31 ;; 1997/3/11 modified by MORIOKA Tomohiko to sync with Emacs 20 API. | 31 ;; 1997/3/11 modified by MORIOKA Tomohiko to sync with Emacs 20 API. |
32 | 32 |
33 ;; This file was derived from the former mule-files.el which has been removed | |
34 ;; as of XEmacs 21.2.15. | |
35 | |
36 ;;; Code: | 33 ;;; Code: |
37 | 34 |
38 (setq-default buffer-file-coding-system 'raw-text) | 35 (setq-default buffer-file-coding-system 'no-conversion) |
39 (put 'buffer-file-coding-system 'permanent-local t) | 36 (put 'buffer-file-coding-system 'permanent-local t) |
40 | 37 |
41 (define-obsolete-variable-alias | 38 (define-obsolete-variable-alias |
42 'file-coding-system | 39 'file-coding-system |
43 'buffer-file-coding-system) | 40 'buffer-file-coding-system) |
66 ,@(mapcar | 63 ,@(mapcar |
67 #'(lambda (regexp) (cons regexp 'binary)) binary-file-regexps) | 64 #'(lambda (regexp) (cons regexp 'binary)) binary-file-regexps) |
68 ("TUTORIAL\\.\\(?:hr\\|pl\\|ro\\)\\'" . iso-8859-2) | 65 ("TUTORIAL\\.\\(?:hr\\|pl\\|ro\\)\\'" . iso-8859-2) |
69 ;; ("\\.\\(el\\|emacs\\|info\\(-[0-9]+\\)?\\|texi\\)$" . iso-2022-8) | 66 ;; ("\\.\\(el\\|emacs\\|info\\(-[0-9]+\\)?\\|texi\\)$" . iso-2022-8) |
70 ;; ("\\(ChangeLog\\|CHANGES-beta\\)$" . iso-2022-8) | 67 ;; ("\\(ChangeLog\\|CHANGES-beta\\)$" . iso-2022-8) |
71 | 68 ("/spool/mail/.*$" . convert-mbox-coding-system)) |
72 ;; This idea is totally broken, and the code didn't work anyway. | |
73 ;; Mailboxes should be decoded by mail clients, who actually know | |
74 ;; how to deal with them. Otherwise, their contents should be | |
75 ;; treated as `binary'. | |
76 ;("/spool/mail/.*$" . convert-mbox-coding-system) | |
77 ) | |
78 "Alist to decide a coding system to use for a file I/O operation. | 69 "Alist to decide a coding system to use for a file I/O operation. |
79 The format is ((PATTERN . VAL) ...), | 70 The format is ((PATTERN . VAL) ...), |
80 where PATTERN is a regular expression matching a file name, | 71 where PATTERN is a regular expression matching a file name, |
81 VAL is a coding system, a cons of coding systems, or a function symbol. | 72 VAL is a coding system, a cons of coding systems, or a function symbol. |
82 If VAL is a coding system, it is used for both decoding and encoding | 73 If VAL is a coding system, it is used for both decoding and encoding |
195 ) | 186 ) |
196 (cond ((consp codesys) (find-coding-system (cdr codesys))) | 187 (cond ((consp codesys) (find-coding-system (cdr codesys))) |
197 ((find-coding-system codesys)) | 188 ((find-coding-system codesys)) |
198 )))) | 189 )))) |
199 | 190 |
200 ;; This is completely broken, not only in implementation (does not | 191 (defun convert-mbox-coding-system (filename visit start end) |
201 ;; understand MIME), but in concept -- such high-level decoding should | 192 "Decoding function for Unix mailboxes. |
202 ;; be done by mail readers, not by IO code! | 193 Does separate detection and decoding on each message, since each |
203 | 194 message might be in a different encoding." |
204 ;(defun convert-mbox-coding-system (filename visit start end) | 195 (let ((buffer-read-only nil)) |
205 ;... | 196 (save-restriction |
197 (narrow-to-region start end) | |
198 (goto-char (point-min)) | |
199 (while (not (eobp)) | |
200 (let ((start (point)) | |
201 end) | |
202 (forward-char 1) | |
203 (if (re-search-forward "^From" nil 'move) | |
204 (beginning-of-line)) | |
205 (setq end (point)) | |
206 (decode-coding-region start end 'undecided)))))) | |
206 | 207 |
207 (defun find-coding-system-magic-cookie () | 208 (defun find-coding-system-magic-cookie () |
208 "Look for the coding-system magic cookie in the current buffer.\n" | 209 "Look for the coding-system magic cookie in the current buffer.\n" |
209 "The coding-system magic cookie is the exact string\n" | 210 "The coding-system magic cookie is the exact string\n" |
210 "\";;;###coding system: \" followed by a valid coding system symbol,\n" | 211 "\";;;###coding system: \" followed by a valid coding system symbol,\n" |
281 (or (and (not elc) coding-system-for-read) ; prefer for source file | 282 (or (and (not elc) coding-system-for-read) ; prefer for source file |
282 ;; find magic-cookie | 283 ;; find magic-cookie |
283 (save-excursion | 284 (save-excursion |
284 (set-buffer (get-buffer-create " *load*")) | 285 (set-buffer (get-buffer-create " *load*")) |
285 (erase-buffer) | 286 (erase-buffer) |
286 (let ((coding-system-for-read 'raw-text)) | 287 (let ((coding-system-for-read 'no-conversion)) |
287 (insert-file-contents path nil 1 3001)) | 288 (insert-file-contents path nil 1 3001)) |
288 (find-coding-system-magic-cookie)) | 289 (find-coding-system-magic-cookie)) |
289 (if elc | 290 (if elc |
290 ;; if reading a byte-compiled file and we didn't find | 291 ;; if reading a byte-compiled file and we didn't find |
291 ;; a coding-system magic cookie, then use `binary'. | 292 ;; a coding-system magic cookie, then use `binary'. |
368 it means replace the current buffer contents (in the accessible portion) | 369 it means replace the current buffer contents (in the accessible portion) |
369 with the file contents. This is better than simply deleting and inserting | 370 with the file contents. This is better than simply deleting and inserting |
370 the whole thing because (1) it preserves some marker positions | 371 the whole thing because (1) it preserves some marker positions |
371 and (2) it puts less data in the undo list. | 372 and (2) it puts less data in the undo list. |
372 | 373 |
374 NOTE: When Mule support is enabled, the REPLACE argument is | |
375 currently ignored. | |
376 | |
373 The coding system used for decoding the file is determined as follows: | 377 The coding system used for decoding the file is determined as follows: |
374 | 378 |
375 1. `coding-system-for-read', if non-nil. | 379 1. `coding-system-for-read', if non-nil. |
376 2. The result of `insert-file-contents-pre-hook', if non-nil. | 380 2. The result of `insert-file-contents-pre-hook', if non-nil. |
377 3. The matching value for this filename from | 381 3. The matching value for this filename from |
378 `file-coding-system-alist', if any. | 382 `file-coding-system-alist', if any. |
379 4. `buffer-file-coding-system-for-read', if non-nil. | 383 4. `buffer-file-coding-system-for-read', if non-nil. |
380 5. The coding system 'raw-text. | 384 5. The coding system 'no-conversion. |
381 | 385 |
382 If a local value for `buffer-file-coding-system' in the current buffer | 386 If a local value for `buffer-file-coding-system' in the current buffer |
383 does not exist, it is set to the coding system which was actually used | 387 does not exist, it is set to the coding system which was actually used |
384 for reading. | 388 for reading. |
385 | 389 |
404 ;; #3. | 408 ;; #3. |
405 (find-file-coding-system-for-read-from-filename filename) | 409 (find-file-coding-system-for-read-from-filename filename) |
406 ;; #4. | 410 ;; #4. |
407 buffer-file-coding-system-for-read | 411 buffer-file-coding-system-for-read |
408 ;; #5. | 412 ;; #5. |
409 'raw-text)) | 413 'no-conversion)) |
410 (if (consp coding-system) | 414 (if (consp coding-system) |
411 (setq return-val coding-system) | 415 (setq return-val coding-system) |
412 (if (null (find-coding-system coding-system)) | 416 (if (null (find-coding-system coding-system)) |
413 (progn | 417 (progn |
414 (message | 418 (message |
549 coding-system))) | 553 coding-system))) |
550 (run-hook-with-args 'write-region-post-hook | 554 (run-hook-with-args 'write-region-post-hook |
551 start end filename append visit lockname | 555 start end filename append visit lockname |
552 coding-system))) | 556 coding-system))) |
553 | 557 |
554 ;;; The following was all that remained in mule-files.el, so I moved it | 558 ;;; mule-files.el ends here |
555 ;;; here for neatness. -sb | |
556 (when (featurep 'mule) | |
557 (setq-default buffer-file-coding-system 'iso-2022-8)) | |
558 | |
559 ;;; code-files.el ends here |