diff options
| author | Geoff Voelker | 1997-08-17 01:49:50 +0000 |
|---|---|---|
| committer | Geoff Voelker | 1997-08-17 01:49:50 +0000 |
| commit | 99bf72f2eec6333920e91db988767b61e4dec927 (patch) | |
| tree | 0daf1ea9f23f2c5dea375ca0d6f9817e757fb577 | |
| parent | 04e6f79c441391a316d6e983a57ea03278116ce1 (diff) | |
| download | emacs-99bf72f2eec6333920e91db988767b61e4dec927.tar.gz emacs-99bf72f2eec6333920e91db988767b61e4dec927.zip | |
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.
| -rw-r--r-- | lisp/dos-w32.el | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/lisp/dos-w32.el b/lisp/dos-w32.el index cdc3e066ce9..bf7d5447fd7 100644 --- a/lisp/dos-w32.el +++ b/lisp/dos-w32.el | |||
| @@ -85,6 +85,8 @@ against the file name, and TYPE is nil for text, t for binary.") | |||
| 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 |
| @@ -101,9 +103,23 @@ upon the filename, the contents of `untranslated-filesystem-list' and | |||
| 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) |
| @@ -118,13 +134,18 @@ upon the value of `buffer-file-type': If t, the coding system is | |||
| 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 | ||
| @@ -140,15 +161,18 @@ upon the value of `buffer-file-type': If t, the coding system is | |||
| 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 |