Mercurial > hg > xemacs-beta
comparison lisp/mule/mule-files.el @ 207:e45d5e7c476e r20-4b2
Import from CVS: tag r20-4b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:03:52 +0200 |
parents | acd284d43ca1 |
children | 1f0dabaa0855 |
comparison
equal
deleted
inserted
replaced
206:d3e9274cbc4e | 207:e45d5e7c476e |
---|---|
24 ;;; Commentary: | 24 ;;; Commentary: |
25 | 25 |
26 ;;; Derived from mule.el in the original Mule but heavily modified | 26 ;;; Derived from mule.el in the original Mule but heavily modified |
27 ;;; by Ben Wing. | 27 ;;; by Ben Wing. |
28 | 28 |
29 ;; 1997/3/11 modified by MORIOKA Tomohiko to sync with Emacs/mule API. | 29 ;; 1997/3/11 modified by MORIOKA Tomohiko to sync with Emacs 20 API. |
30 | 30 |
31 ;;; Code: | 31 ;;; Code: |
32 | |
33 ;;;; #### also think more about `binary' vs. `no-conversion' | |
34 | |
35 ;; Use `no-conversion' instead of `binary', because Emacs/mule does | |
36 ;; not have `binary' coding-system. | |
37 | |
38 ;; also think more about `internal'. | |
39 | |
40 | 32 |
41 (setq-default buffer-file-coding-system 'iso-2022-8) | 33 (setq-default buffer-file-coding-system 'iso-2022-8) |
42 (put 'buffer-file-coding-system 'permanent-local t) | 34 (put 'buffer-file-coding-system 'permanent-local t) |
43 | 35 |
44 (define-obsolete-variable-alias | 36 (define-obsolete-variable-alias |
47 | 39 |
48 (define-obsolete-variable-alias | 40 (define-obsolete-variable-alias |
49 'overriding-file-coding-system | 41 'overriding-file-coding-system |
50 'coding-system-for-read) | 42 'coding-system-for-read) |
51 | 43 |
52 (defvar buffer-file-coding-system-for-read 'automatic-conversion | 44 (defvar buffer-file-coding-system-for-read 'undecided |
53 "Coding system used when reading a file. | 45 "Coding system used when reading a file. |
54 This provides coarse-grained control; for finer-grained control, use | 46 This provides coarse-grained control; for finer-grained control, use |
55 `file-coding-system-alist'. From a Lisp program, if you wish to | 47 `file-coding-system-alist'. From a Lisp program, if you wish to |
56 unilaterally specify the coding system used for one particular | 48 unilaterally specify the coding system used for one particular |
57 operation, you should bind the variable `coding-system-for-read' | 49 operation, you should bind the variable `coding-system-for-read' |
64 | 56 |
65 (defvar file-coding-system-alist | 57 (defvar file-coding-system-alist |
66 '(("\\.elc$" . (binary . binary)) | 58 '(("\\.elc$" . (binary . binary)) |
67 ("loaddefs.el$" . (binary . binary)) | 59 ("loaddefs.el$" . (binary . binary)) |
68 ("\\.tar$" . (binary . binary)) | 60 ("\\.tar$" . (binary . binary)) |
61 ("TUTORIAL\\.hr$" . iso-8859-2) | |
69 ;; ("\\.\\(el\\|emacs\\|info\\(-[0-9]+\\)?\\|texi\\)$" . iso-2022-8) | 62 ;; ("\\.\\(el\\|emacs\\|info\\(-[0-9]+\\)?\\|texi\\)$" . iso-2022-8) |
70 ;; ("\\(ChangeLog\\|CHANGES-beta\\)$" . iso-2022-8) | 63 ;; ("\\(ChangeLog\\|CHANGES-beta\\)$" . iso-2022-8) |
71 ("\\.\\(gz\\|Z\\)$" . binary) | 64 ("\\.\\(gz\\|Z\\)$" . binary) |
72 ("/spool/mail/.*$" . convert-mbox-coding-system)) | 65 ("/spool/mail/.*$" . convert-mbox-coding-system)) |
73 "Alist to decide a coding system to use for a file I/O operation. | 66 "Alist to decide a coding system to use for a file I/O operation. |
192 end) | 185 end) |
193 (forward-char 1) | 186 (forward-char 1) |
194 (if (re-search-forward "^From" nil 'move) | 187 (if (re-search-forward "^From" nil 'move) |
195 (beginning-of-line)) | 188 (beginning-of-line)) |
196 (setq end (point)) | 189 (setq end (point)) |
197 (decode-coding-region start end 'automatic-conversion)))))) | 190 (decode-coding-region start end 'undecided)))))) |
198 | 191 |
199 (defun find-coding-system-magic-cookie () | 192 (defun find-coding-system-magic-cookie () |
200 "Look for the coding-system magic cookie in the current buffer.\n" | 193 "Look for the coding-system magic cookie in the current buffer.\n" |
201 "The coding-system magic cookie is the exact string\n" | 194 "The coding-system magic cookie is the exact string\n" |
202 "\";;;###coding system: \" followed by a valid coding system symbol,\n" | 195 "\";;;###coding system: \" followed by a valid coding system symbol,\n" |
207 "charset, and that the spaces make it even less likely since the space\n" | 200 "charset, and that the spaces make it even less likely since the space\n" |
208 "character is not a valid octet in any ISO 2022 encoding of most non-ASCII\n" | 201 "character is not a valid octet in any ISO 2022 encoding of most non-ASCII\n" |
209 "charsets." | 202 "charsets." |
210 (save-excursion | 203 (save-excursion |
211 (goto-char (point-min)) | 204 (goto-char (point-min)) |
212 (let ((case-fold-search nil)) | 205 (or (and (looking-at "^-\\*-[^\n]*coding: \\([^ \t\n;]+\\);[^\n]*-\\*-") |
213 (if (search-forward ";;;###coding system: " (+ (point-min) 3000) t) | 206 (let ((codesys (intern (buffer-substring |
214 (let ((start (point)) | 207 (match-beginning 1)(match-end 1))))) |
215 (end (progn | 208 (if (find-coding-system codesys) codesys))) |
216 (skip-chars-forward "^ \t\n\r") | 209 ;; (save-excursion |
217 (point)))) | 210 ;; (let (start end) |
218 (if (> end start) | 211 ;; (and (re-search-forward "^;+[ \t]*Local Variables:" nil t) |
219 (let ((codesys (intern (buffer-substring start end)))) | 212 ;; (setq start (match-end 0)) |
220 (if (find-coding-system codesys) codesys)))))))) | 213 ;; (re-search-forward "\n;+[ \t]*End:") |
214 ;; (setq end (match-beginning 0)) | |
215 ;; (save-restriction | |
216 ;; (narrow-to-region start end) | |
217 ;; (goto-char start) | |
218 ;; (re-search-forward "^;;; coding: \\([^\n]+\\)$" nil t) | |
219 ;; ) | |
220 ;; (let ((codesys | |
221 ;; (intern (buffer-substring | |
222 ;; (match-beginning 1)(match-end 1))))) | |
223 ;; (if (find-coding-system codesys) codesys)) | |
224 ;; ))) | |
225 (let ((case-fold-search nil)) | |
226 (if (search-forward | |
227 ";;;###coding system: " (+ (point-min) 3000) t) | |
228 (let ((start (point)) | |
229 (end (progn | |
230 (skip-chars-forward "^ \t\n\r") | |
231 (point)))) | |
232 (if (> end start) | |
233 (let ((codesys (intern (buffer-substring start end)))) | |
234 (if (find-coding-system codesys) codesys))) | |
235 ))) | |
236 ))) | |
221 | 237 |
222 (defun load (file &optional noerror nomessage nosuffix) | 238 (defun load (file &optional noerror nomessage nosuffix) |
223 "Execute a file of Lisp code named FILE. | 239 "Execute a file of Lisp code named FILE. |
224 First tries FILE with .elc appended, then tries with .el, | 240 First tries FILE with .elc appended, then tries with .el, |
225 then tries FILE unmodified. Searches directories in load-path. | 241 then tries FILE unmodified. Searches directories in load-path. |
249 (insert-file-contents path nil 1 3001)) | 265 (insert-file-contents path nil 1 3001)) |
250 (setq __codesys__ (find-coding-system-magic-cookie))) | 266 (setq __codesys__ (find-coding-system-magic-cookie))) |
251 ;; use string= instead of string-match to keep match-data. | 267 ;; use string= instead of string-match to keep match-data. |
252 (if (string= ".elc" (downcase (substring path -4))) | 268 (if (string= ".elc" (downcase (substring path -4))) |
253 ;; if reading a byte-compiled file and we didn't find | 269 ;; if reading a byte-compiled file and we didn't find |
254 ;; a coding-system magic cookie, then use `no-conversion'. | 270 ;; a coding-system magic cookie, then use `binary'. |
255 ;; We need to guarantee that we never do autodetection | 271 ;; We need to guarantee that we never do autodetection |
256 ;; on byte-compiled files because confusion here would | 272 ;; on byte-compiled files because confusion here would |
257 ;; be a very bad thing. Pre-existing byte-compiled | 273 ;; be a very bad thing. Pre-existing byte-compiled |
258 ;; files are always in the `no-conversion' system. | 274 ;; files are always in the `binary' coding system. |
259 ;; Also, byte-compiled files always use `lf' to terminate | 275 ;; Also, byte-compiled files always use `lf' to terminate |
260 ;; a line; don't risk confusion here either. | 276 ;; a line; don't risk confusion here either. |
261 (if (not __codesys__) | 277 (or __codesys__ |
262 (setq __codesys__ 'no-conversion)) | 278 (setq __codesys__ 'binary)) |
263 ;; otherwise use `buffer-file-coding-system-for-read', as normal | 279 ;; otherwise use `buffer-file-coding-system-for-read', as normal |
264 ;; #### need to do some looking up in | 280 ;; #### need to do some looking up in |
265 ;; #### file-coding-system-alist! | 281 ;; #### file-coding-system-alist! |
266 (if (not __codesys__) | 282 (or __codesys__ |
267 (setq __codesys__ buffer-file-coding-system-for-read))) | 283 (setq __codesys__ |
284 (or (find-file-coding-system-for-read-from-filename | |
285 file) | |
286 buffer-file-coding-system-for-read))) | |
287 ) | |
268 ;; now use the internal load to actually load the file. | 288 ;; now use the internal load to actually load the file. |
269 (load-internal file noerror nomessage nosuffix __codesys__)))))) | 289 (load-internal file noerror nomessage nosuffix __codesys__)))))) |
270 | 290 |
271 (defvar insert-file-contents-access-hook nil | 291 (defvar insert-file-contents-access-hook nil |
272 "A hook to make a file accessible before reading it. | 292 "A hook to make a file accessible before reading it. |
376 (if (consp coding-system) | 396 (if (consp coding-system) |
377 (setq return-val coding-system) | 397 (setq return-val coding-system) |
378 (if (null (find-coding-system coding-system)) | 398 (if (null (find-coding-system coding-system)) |
379 (progn | 399 (progn |
380 (message | 400 (message |
381 "Invalid coding-system (%s), using 'automatic-conversion" | 401 "Invalid coding-system (%s), using 'undecided" |
382 coding-system) | 402 coding-system) |
383 (setq coding-system 'automatic-conversion))) | 403 (setq coding-system 'undecided))) |
384 (setq return-val | 404 (setq return-val |
385 (insert-file-contents-internal filename visit beg end | 405 (insert-file-contents-internal filename visit beg end |
386 replace coding-system | 406 replace coding-system |
387 ;; store here! | 407 ;; store here! |
388 'used-codesys)) | 408 'used-codesys)) |