comparison lisp/dos-w32.el @ 19400:95183e63d1dd

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.
author Geoff Voelker <voelker@cs.washington.edu>
date Sun, 17 Aug 1997 01:49:50 +0000
parents d6d9a466fad2
children 98e7893f8679
comparison
equal deleted inserted replaced
19399:8ece1f8d2ff6 19400:95183e63d1dd
83 (setq code (cdr match)) 83 (setq code (cdr match))
84 (cond ((memq code '(nil t)) code) 84 (cond ((memq code '(nil t)) code)
85 ((and (symbolp code) (fboundp code)) 85 ((and (symbolp code) (fboundp code))
86 (funcall code filename))))))) 86 (funcall code filename)))))))
87 87
88 (setq-default buffer-file-coding-system 'undecided-dos)
89
88 (defun find-buffer-file-type-coding-system (command) 90 (defun find-buffer-file-type-coding-system (command)
89 "Choose a coding system for a file operation. 91 "Choose a coding system for a file operation.
90 If COMMAND is `insert-file-contents', the coding system is chosen based 92 If COMMAND is `insert-file-contents', the coding system is chosen based
91 upon the filename, the contents of `untranslated-filesystem-list' and 93 upon the filename, the contents of `untranslated-filesystem-list' and
92 `file-name-buffer-file-type-alist', and whether the file exists: 94 `file-name-buffer-file-type-alist', and whether the file exists:
99 If the match is nil (for dos-text): `undecided-dos' 101 If the match is nil (for dos-text): `undecided-dos'
100 Otherwise: 102 Otherwise:
101 If the file exists: `undecided' 103 If the file exists: `undecided'
102 If the file does not exist: `undecided-dos' 104 If the file does not exist: `undecided-dos'
103 105
104 If COMMAND is `write-region', the coding system is chosen based 106 If COMMAND is `write-region', the coding system is chosen based upon
105 upon the value of `buffer-file-type': If t, the coding system is 107 the value of `buffer-file-coding-system' and `buffer-file-type'. If
106 `no-conversion', otherwise it is `undecided-dos'." 108 `buffer-file-coding-system' is non-nil, its value is used. If it is
109 nil and `buffer-file-type' is t, the coding system is `no-conversion'.
110 Otherwise, it is `undecided-dos'.
111
112 The two most common situations are when DOS and Unix files are read
113 and written, and their names do not match in
114 `untranslated-filesystem-list' and `file-name-buffer-file-type-alist'.
115 In these cases, the coding system initially will be `undecided'. As
116 the file is read in the DOS case, the coding system will be changed to
117 `undecided-dos' as CR/LFs are detected. As the file is read in the
118 Unix case, the coding system will be changed to `undecided-unix' as
119 LFs are detected. In both cases, `buffer-file-coding-system' will be
120 set to the appropriate coding system, and the value of
121 `buffer-file-coding-system' will be used when writing the file."
122
107 (let ((op (nth 0 command)) 123 (let ((op (nth 0 command))
108 (target) 124 (target)
109 (binary nil) (text nil) 125 (binary nil) (text nil)
110 (undecided nil)) 126 (undecided nil))
111 (cond ((eq op 'insert-file-contents) 127 (cond ((eq op 'insert-file-contents)
116 (setq binary t)) 132 (setq binary t))
117 (setq binary (find-buffer-file-type target)) 133 (setq binary (find-buffer-file-type target))
118 (unless binary 134 (unless binary
119 (if (find-buffer-file-type-match target) 135 (if (find-buffer-file-type-match target)
120 (setq text t) 136 (setq text t)
121 (setq undecided (file-exists-p target)))))) 137 (setq undecided (file-exists-p target)))))
122 ((eq op 'write-region) 138 (cond (binary '(no-conversion . no-conversion))
123 (setq binary buffer-file-type))) 139 (text '(undecided-dos . undecided-dos))
124 (cond (binary '(no-conversion . no-conversion)) 140 (undecided '(undecided . undecided))
125 (text '(undecided-dos . undecided-dos)) 141 (t '(undecided-dos . undecided-dos))))
126 (undecided '(undecided . undecided)) 142 ((eq op 'write-region)
127 (t '(undecided-dos . undecided-dos))))) 143 (if buffer-file-coding-system
144 (cons buffer-file-coding-system
145 buffer-file-coding-system)
146 (if buffer-file-type
147 '(no-conversion . no-conversion)
148 '(undecided-dos . undecided-dos)))))))
128 149
129 (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system) 150 (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system)
130 151
131 (defun find-file-binary (filename) 152 (defun find-file-binary (filename)
132 "Visit file FILENAME and treat it as binary." 153 "Visit file FILENAME and treat it as binary."
138 "Visit file FILENAME and treat it as a text file." 159 "Visit file FILENAME and treat it as a text file."
139 (interactive "FFind file text: ") 160 (interactive "FFind file text: ")
140 (let ((file-name-buffer-file-type-alist '(("" . nil)))) 161 (let ((file-name-buffer-file-type-alist '(("" . nil))))
141 (find-file filename))) 162 (find-file filename)))
142 163
143 (defun find-file-not-found-set-buffer-file-type () 164 (defun find-file-not-found-set-buffer-file-coding-system ()
144 (save-excursion 165 (save-excursion
145 (set-buffer (current-buffer)) 166 (set-buffer (current-buffer))
146 (setq buffer-file-type (find-buffer-file-type (buffer-file-name)))) 167 (let* ((dummy-insert-op (list 'insert-file-contents (buffer-file-name)))
147 nil) 168 (coding-system-pair
148 169 (find-buffer-file-type-coding-system dummy-insert-op)))
149 ;;; To set the default file type on new files. 170 (setq buffer-file-coding-system (car coding-system-pair))
150 (add-hook 'find-file-not-found-hooks 'find-file-not-found-set-buffer-file-type) 171 (setq buffer-file-type (eq buffer-file-coding-system 'no-conversion)))))
151 172
173 ;;; To set the default coding system on new files.
174 (add-hook 'find-file-not-found-hooks
175 'find-file-not-found-set-buffer-file-coding-system)
152 176
153 ;;; To accomodate filesystems that do not require CR/LF translation. 177 ;;; To accomodate filesystems that do not require CR/LF translation.
154 (defvar untranslated-filesystem-list nil 178 (defvar untranslated-filesystem-list nil
155 "List of filesystems that require no CR/LF translation when reading 179 "List of filesystems that require no CR/LF translation when reading
156 and writing files. Each filesystem in the list is a string naming 180 and writing files. Each filesystem in the list is a string naming