comparison lisp/code-files.el @ 4650:8905163c49c5

#'find-file: set b-f-c-s even on error (cf. non-existent files), handle undecided coding-systems passed back from #'insert-file-contents-internal better. tests/ChangeLog addition: 2009-07-13 Aidan Kehoe <kehoea@parhasard.net> * automated/mule-tests.el: Now that find-file on a nonexistent path gives a modified buffer, we want to set this kind of buffer to be non-modified here before killing it. lisp/ChangeLog addition: 2009-07-13 Aidan Kehoe <kehoea@parhasard.net> * code-files.el (insert-file-contents): Set the buffer coding system even on error; especially important when dealing with nonexistent files. If the `coding-system' property of an undecided coding system is itself undecided, don't use that as a value for buffer-file-coding-system.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 13 Jul 2009 20:45:26 +0100
parents e4ed58cb0e5b
children 308d34e9f07d
comparison
equal deleted inserted replaced
4649:3972966a4588 4650:8905163c49c5
437 replace coding-system 437 replace coding-system
438 ;; store here! 438 ;; store here!
439 'used-codesys)) 439 'used-codesys))
440 )) 440 ))
441 (file-error 441 (file-error
442 ;; If we error, which we may if the file does not exist, we still
443 ;; want to set the buffer-file-coding-system if that is
444 ;; appropriate:
445 (when (eq 'undecided (coding-system-type coding-system))
446 (setq used-codesys (coding-system-property coding-system
447 'coding-system))
448 (if (and used-codesys
449 (not (eq 'undecided (coding-system-type used-codesys))))
450 ;; If this property is available, and not undecided, it should
451 ;; be a coding system that we can use to write a file (as
452 ;; opposed to the true undecided coding system, which trashes
453 ;; non-Latin-1 on writing). It might just be the value of
454 ;; coding-system passed to #'insert-file-contents-internal.
455 (setq coding-system used-codesys)
456 ;; Otherwise, take the value normally specified by the
457 ;; language environment:
458 (setq coding-system (default-value
459 'buffer-file-coding-system))))
460 (if (local-variable-p 'buffer-file-coding-system
461 (current-buffer))
462 (set-buffer-file-coding-system
463 (subsidiary-coding-system
464 buffer-file-coding-system
465 (coding-system-eol-type coding-system)) t t)
466 (set-buffer-file-coding-system coding-system t t))
467 (setq buffer-file-coding-system-when-loaded
468 coding-system)
442 (run-hook-with-args 'insert-file-contents-error-hook 469 (run-hook-with-args 'insert-file-contents-error-hook
443 filename visit err) 470 filename visit err)
444 (signal (car err) (cdr err)))) 471 (signal (car err) (cdr err))))
445 (setq coding-system used-codesys) 472 (setq coding-system used-codesys)
446 ;; If the file was zero-length, used-codesys is undecided. Set it to 473 ;; If the file was zero-length, used-codesys is undecided. Set it to
447 ;; a more sane value. 474 ;; a more sane value.
448 (when (eq 'undecided (coding-system-type coding-system)) 475 (when (eq 'undecided (coding-system-type coding-system))
449 (unless (zerop (buffer-size)) 476 (unless (zerop (buffer-size))
450 (warn "%s: autodetection failed: setting to default." 477 (warn "%s: autodetection failed: setting to default."
451 (file-name-nondirectory (buffer-file-name)))) 478 (file-name-nondirectory (buffer-file-name))))
452 (setq coding-system 479 (setq used-codesys (coding-system-property coding-system
453 (or 480 'coding-system))
454 ;; If this property is available, it will be a coding 481 (if (and used-codesys
455 ;; system that we can use to write a file (as opposed to 482 (not (eq 'undecided (coding-system-type used-codesys))))
456 ;; the true undecided coding system, which trashes 483 ;; If this property is available, and not undecided, it should
457 ;; non-Latin-1 on writing). It might just be the value of 484 ;; be a coding system that we can use to write a file (as
458 ;; coding-system passed to #'insert-file-contents-internal. 485 ;; opposed to the true undecided coding system, which trashes
459 (coding-system-property coding-system 'coding-system) 486 ;; non-Latin-1 on writing). It might just be the value of
460 ;; Otherwise, take the value normally specified by the 487 ;; coding-system passed to #'insert-file-contents-internal.
461 ;; language environment: 488 (setq coding-system used-codesys)
462 (default-value 'buffer-file-coding-system)))) 489 ;; Otherwise, take the value normally specified by the
490 ;; language environment:
491 (setq coding-system (default-value 'buffer-file-coding-system))))
463 ;; call any `post-read-conversion' for the coding system that 492 ;; call any `post-read-conversion' for the coding system that
464 ;; was used ... 493 ;; was used ...
465 (let ((func 494 (let ((func
466 (coding-system-property coding-system 'post-read-conversion)) 495 (coding-system-property coding-system 'post-read-conversion))
467 (endmark (make-marker))) 496 (endmark (make-marker)))