comparison lisp/dos-w32.el @ 19656:98e7893f8679

(find-buffer-file-type): Don't check for untranslated file systems here. (find-buffer-file-type-coding-system): For reading a file, check for binary file, then text file, then existing file, then whether file name is translated.
author Richard M. Stallman <rms@gnu.org>
date Mon, 01 Sep 1997 17:04:41 +0000
parents 95183e63d1dd
children ceed5706d45e
comparison
equal deleted inserted replaced
19655:47d11f4bbc6c 19656:98e7893f8679
70 (if (string-match (car (car alist)) filename) 70 (if (string-match (car (car alist)) filename)
71 (setq found (car alist))) 71 (setq found (car alist)))
72 (setq alist (cdr alist))) 72 (setq alist (cdr alist)))
73 found))) 73 found)))
74 74
75 ;; Don't check for untranslated file systems here.
75 (defun find-buffer-file-type (filename) 76 (defun find-buffer-file-type (filename)
76 ;; First check if file is on an untranslated filesystem, then on the alist. 77 (let ((match (find-buffer-file-type-match filename))
77 (if (untranslated-file-p filename) 78 (code))
78 t ; for binary 79 (if (not match)
79 (let ((match (find-buffer-file-type-match filename)) 80 default-buffer-file-type
80 (code)) 81 (setq code (cdr match))
81 (if (not match) 82 (cond ((memq code '(nil t)) code)
82 default-buffer-file-type 83 ((and (symbolp code) (fboundp code))
83 (setq code (cdr match)) 84 (funcall code filename))))))
84 (cond ((memq code '(nil t)) code)
85 ((and (symbolp code) (fboundp code))
86 (funcall code filename)))))))
87 85
88 (setq-default buffer-file-coding-system 'undecided-dos) 86 (setq-default buffer-file-coding-system 'undecided-dos)
89 87
90 (defun find-buffer-file-type-coding-system (command) 88 (defun find-buffer-file-type-coding-system (command)
91 "Choose a coding system for a file operation. 89 "Choose a coding system for a file operation.
121 `buffer-file-coding-system' will be used when writing the file." 119 `buffer-file-coding-system' will be used when writing the file."
122 120
123 (let ((op (nth 0 command)) 121 (let ((op (nth 0 command))
124 (target) 122 (target)
125 (binary nil) (text nil) 123 (binary nil) (text nil)
126 (undecided nil)) 124 (undecided nil) (undecided-unix nil))
127 (cond ((eq op 'insert-file-contents) 125 (cond ((eq op 'insert-file-contents)
128 (setq target (nth 1 command)) 126 (setq target (nth 1 command))
129 (if (untranslated-file-p target) 127 ;; First check for a file name that indicates
130 (if (file-exists-p target) 128 ;; it is truly binary.
131 (setq undecided t) 129 (setq binary (find-buffer-file-type target))
132 (setq binary t)) 130 (cond (binary)
133 (setq binary (find-buffer-file-type target)) 131 ;; Next check for files that MUST use DOS eol conversion.
134 (unless binary 132 ((find-buffer-file-type-match target)
135 (if (find-buffer-file-type-match target) 133 (setq text t))
136 (setq text t) 134 ;; For any other existing file, decide based on contents.
137 (setq undecided (file-exists-p target))))) 135 ((file-exists-p target)
136 (setq undecided t))
137 ;; Next check for a non-DOS file system.
138 ((untranslated-file-p target)
139 (setq undecided-unix t)))
138 (cond (binary '(no-conversion . no-conversion)) 140 (cond (binary '(no-conversion . no-conversion))
139 (text '(undecided-dos . undecided-dos)) 141 (text '(undecided-dos . undecided-dos))
142 (undecided-unix '(undecided-unix . undecided-unix))
140 (undecided '(undecided . undecided)) 143 (undecided '(undecided . undecided))
141 (t '(undecided-dos . undecided-dos)))) 144 (t '(undecided-dos . undecided-dos))))
142 ((eq op 'write-region) 145 ((eq op 'write-region)
143 (if buffer-file-coding-system 146 (if buffer-file-coding-system
144 (cons buffer-file-coding-system 147 (cons buffer-file-coding-system
145 buffer-file-coding-system) 148 buffer-file-coding-system)
149 ;; Normally this is used only in a non-file-visiting
150 ;; buffer, because normally buffer-file-coding-system is non-nil
151 ;; in a file-visiting buffer.
146 (if buffer-file-type 152 (if buffer-file-type
147 '(no-conversion . no-conversion) 153 '(no-conversion . no-conversion)
148 '(undecided-dos . undecided-dos))))))) 154 '(undecided-dos . undecided-dos)))))))
149 155
150 (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system) 156 (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system)