comparison lisp/code-files.el @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents a4f53d9b3154
children 8626e4521993
comparison
equal deleted inserted replaced
370:bd866891f083 371:cc15677e0335
69 ("TUTORIAL\\.pl$" . iso-8859-2) 69 ("TUTORIAL\\.pl$" . iso-8859-2)
70 ("TUTORIAL\\.ro$" . iso-8859-2) 70 ("TUTORIAL\\.ro$" . iso-8859-2)
71 ;; ("\\.\\(el\\|emacs\\|info\\(-[0-9]+\\)?\\|texi\\)$" . iso-2022-8) 71 ;; ("\\.\\(el\\|emacs\\|info\\(-[0-9]+\\)?\\|texi\\)$" . iso-2022-8)
72 ;; ("\\(ChangeLog\\|CHANGES-beta\\)$" . iso-2022-8) 72 ;; ("\\(ChangeLog\\|CHANGES-beta\\)$" . iso-2022-8)
73 ("\\.\\(gz\\|Z\\)$" . binary) 73 ("\\.\\(gz\\|Z\\)$" . binary)
74 74 ("/spool/mail/.*$" . convert-mbox-coding-system))
75 ;; This idea is totally broken, and the code didn't work anyway.
76 ;; Mailboxes should be decoded by mail clients, who actually know
77 ;; how to deal with them. Otherwise, their contents should be
78 ;; treated as `binary'.
79 ;("/spool/mail/.*$" . convert-mbox-coding-system)
80 )
81 "Alist to decide a coding system to use for a file I/O operation. 75 "Alist to decide a coding system to use for a file I/O operation.
82 The format is ((PATTERN . VAL) ...), 76 The format is ((PATTERN . VAL) ...),
83 where PATTERN is a regular expression matching a file name, 77 where PATTERN is a regular expression matching a file name,
84 VAL is a coding system, a cons of coding systems, or a function symbol. 78 VAL is a coding system, a cons of coding systems, or a function symbol.
85 If VAL is a coding system, it is used for both decoding and encoding 79 If VAL is a coding system, it is used for both decoding and encoding
198 ) 192 )
199 (cond ((consp codesys) (find-coding-system (cdr codesys))) 193 (cond ((consp codesys) (find-coding-system (cdr codesys)))
200 ((find-coding-system codesys)) 194 ((find-coding-system codesys))
201 )))) 195 ))))
202 196
203 ;; This is completely broken, not only in implementation (does not 197 (defun convert-mbox-coding-system (filename visit start end)
204 ;; understand MIME), but in concept -- such high-level decoding should 198 "Decoding function for Unix mailboxes.
205 ;; be done by mail readers, not by IO code! 199 Does separate detection and decoding on each message, since each
206 200 message might be in a different encoding."
207 ;(defun convert-mbox-coding-system (filename visit start end) 201 (let ((buffer-read-only nil))
208 ;... 202 (save-restriction
203 (narrow-to-region start end)
204 (goto-char (point-min))
205 (while (not (eobp))
206 (let ((start (point))
207 end)
208 (forward-char 1)
209 (if (re-search-forward "^From" nil 'move)
210 (beginning-of-line))
211 (setq end (point))
212 (decode-coding-region start end 'undecided))))))
209 213
210 (defun find-coding-system-magic-cookie () 214 (defun find-coding-system-magic-cookie ()
211 "Look for the coding-system magic cookie in the current buffer.\n" 215 "Look for the coding-system magic cookie in the current buffer.\n"
212 "The coding-system magic cookie is the exact string\n" 216 "The coding-system magic cookie is the exact string\n"
213 "\";;;###coding system: \" followed by a valid coding system symbol,\n" 217 "\";;;###coding system: \" followed by a valid coding system symbol,\n"
371 it means replace the current buffer contents (in the accessible portion) 375 it means replace the current buffer contents (in the accessible portion)
372 with the file contents. This is better than simply deleting and inserting 376 with the file contents. This is better than simply deleting and inserting
373 the whole thing because (1) it preserves some marker positions 377 the whole thing because (1) it preserves some marker positions
374 and (2) it puts less data in the undo list. 378 and (2) it puts less data in the undo list.
375 379
380 NOTE: When Mule support is enabled, the REPLACE argument is
381 currently ignored.
382
376 The coding system used for decoding the file is determined as follows: 383 The coding system used for decoding the file is determined as follows:
377 384
378 1. `coding-system-for-read', if non-nil. 385 1. `coding-system-for-read', if non-nil.
379 2. The result of `insert-file-contents-pre-hook', if non-nil. 386 2. The result of `insert-file-contents-pre-hook', if non-nil.
380 3. The matching value for this filename from 387 3. The matching value for this filename from
399 (setq coding-system 406 (setq coding-system
400 (or 407 (or
401 ;; #1. 408 ;; #1.
402 coding-system-for-read 409 coding-system-for-read
403 ;; #2. 410 ;; #2.
404 (run-special-hook-with-args 'insert-file-contents-pre-hook 411 (run-hook-with-args-until-success
405 filename visit) 412 'insert-file-contents-pre-hook
413 filename visit)
406 ;; #3. 414 ;; #3.
407 (find-file-coding-system-for-read-from-filename filename) 415 (find-file-coding-system-for-read-from-filename filename)
408 ;; #4. 416 ;; #4.
409 buffer-file-coding-system-for-read 417 buffer-file-coding-system-for-read
410 ;; #5. 418 ;; #5.
443 (progn 451 (progn
444 (set-buffer-auto-saved) 452 (set-buffer-auto-saved)
445 (set-buffer-modified-p nil))))) 453 (set-buffer-modified-p nil)))))
446 (setcar (cdr return-val) (- (marker-position endmark) (point)))) 454 (setcar (cdr return-val) (- (marker-position endmark) (point))))
447 ;; now finally set the buffer's `buffer-file-coding-system'. 455 ;; now finally set the buffer's `buffer-file-coding-system'.
448 (if (run-special-hook-with-args 'insert-file-contents-post-hook 456 (if (run-hook-with-args-until-success 'insert-file-contents-post-hook
449 filename visit return-val) 457 filename visit return-val)
450 nil 458 nil
451 (if (local-variable-p 'buffer-file-coding-system (current-buffer)) 459 (if (local-variable-p 'buffer-file-coding-system (current-buffer))
452 ;; if buffer-file-coding-system is already local, just 460 ;; if buffer-file-coding-system is already local, just
453 ;; set its eol type to what was found, if it wasn't 461 ;; set its eol type to what was found, if it wasn't
454 ;; set already. 462 ;; set already.
512 coding system. 520 coding system.
513 See also `write-region-pre-hook' and `write-region-post-hook'." 521 See also `write-region-pre-hook' and `write-region-post-hook'."
514 (interactive "r\nFWrite region to file: \ni\ni\ni\nZCoding-system: ") 522 (interactive "r\nFWrite region to file: \ni\ni\ni\nZCoding-system: ")
515 (setq coding-system 523 (setq coding-system
516 (or coding-system-for-write 524 (or coding-system-for-write
517 (run-special-hook-with-args 525 (run-hook-with-args-until-success
518 'write-region-pre-hook start end filename append visit lockname) 526 'write-region-pre-hook start end filename append visit lockname)
519 coding-system 527 coding-system
520 buffer-file-coding-system 528 buffer-file-coding-system
521 (find-file-coding-system-for-write-from-filename filename) 529 (find-file-coding-system-for-write-from-filename filename)
522 )) 530 ))