# HG changeset patch # User Geoff Voelker # Date 871782590 0 # Node ID 95183e63d1dd3827fd302df958ed7183d1fd507b # Parent 8ece1f8d2ff6a35c870da041803e218574eca5c9 Set default coding system to undecided-dos. (find-buffer-file-type-coding-system): For writing, use buffer-file-coding-system if set, otherwise buffer-file-type. (find-file-not-found-set-buffer-file-coding-system): Renamed from find-file-not-found-set-buffer-file-type. Set buffer-file-coding-system as well as buffer-file-type. diff -r 8ece1f8d2ff6 -r 95183e63d1dd lisp/dos-w32.el --- a/lisp/dos-w32.el Sun Aug 17 01:49:01 1997 +0000 +++ b/lisp/dos-w32.el Sun Aug 17 01:49:50 1997 +0000 @@ -85,6 +85,8 @@ ((and (symbolp code) (fboundp code)) (funcall code filename))))))) +(setq-default buffer-file-coding-system 'undecided-dos) + (defun find-buffer-file-type-coding-system (command) "Choose a coding system for a file operation. If COMMAND is `insert-file-contents', the coding system is chosen based @@ -101,9 +103,23 @@ If the file exists: `undecided' If the file does not exist: `undecided-dos' -If COMMAND is `write-region', the coding system is chosen based -upon the value of `buffer-file-type': If t, the coding system is -`no-conversion', otherwise it is `undecided-dos'." +If COMMAND is `write-region', the coding system is chosen based upon +the value of `buffer-file-coding-system' and `buffer-file-type'. If +`buffer-file-coding-system' is non-nil, its value is used. If it is +nil and `buffer-file-type' is t, the coding system is `no-conversion'. +Otherwise, it is `undecided-dos'. + +The two most common situations are when DOS and Unix files are read +and written, and their names do not match in +`untranslated-filesystem-list' and `file-name-buffer-file-type-alist'. +In these cases, the coding system initially will be `undecided'. As +the file is read in the DOS case, the coding system will be changed to +`undecided-dos' as CR/LFs are detected. As the file is read in the +Unix case, the coding system will be changed to `undecided-unix' as +LFs are detected. In both cases, `buffer-file-coding-system' will be +set to the appropriate coding system, and the value of +`buffer-file-coding-system' will be used when writing the file." + (let ((op (nth 0 command)) (target) (binary nil) (text nil) @@ -118,13 +134,18 @@ (unless binary (if (find-buffer-file-type-match target) (setq text t) - (setq undecided (file-exists-p target)))))) - ((eq op 'write-region) - (setq binary buffer-file-type))) - (cond (binary '(no-conversion . no-conversion)) - (text '(undecided-dos . undecided-dos)) - (undecided '(undecided . undecided)) - (t '(undecided-dos . undecided-dos))))) + (setq undecided (file-exists-p target))))) + (cond (binary '(no-conversion . no-conversion)) + (text '(undecided-dos . undecided-dos)) + (undecided '(undecided . undecided)) + (t '(undecided-dos . undecided-dos)))) + ((eq op 'write-region) + (if buffer-file-coding-system + (cons buffer-file-coding-system + buffer-file-coding-system) + (if buffer-file-type + '(no-conversion . no-conversion) + '(undecided-dos . undecided-dos))))))) (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system) @@ -140,15 +161,18 @@ (let ((file-name-buffer-file-type-alist '(("" . nil)))) (find-file filename))) -(defun find-file-not-found-set-buffer-file-type () +(defun find-file-not-found-set-buffer-file-coding-system () (save-excursion (set-buffer (current-buffer)) - (setq buffer-file-type (find-buffer-file-type (buffer-file-name)))) - nil) + (let* ((dummy-insert-op (list 'insert-file-contents (buffer-file-name))) + (coding-system-pair + (find-buffer-file-type-coding-system dummy-insert-op))) + (setq buffer-file-coding-system (car coding-system-pair)) + (setq buffer-file-type (eq buffer-file-coding-system 'no-conversion))))) -;;; To set the default file type on new files. -(add-hook 'find-file-not-found-hooks 'find-file-not-found-set-buffer-file-type) - +;;; To set the default coding system on new files. +(add-hook 'find-file-not-found-hooks + 'find-file-not-found-set-buffer-file-coding-system) ;;; To accomodate filesystems that do not require CR/LF translation. (defvar untranslated-filesystem-list nil