diff options
| -rw-r--r-- | lisp/dos-w32.el | 91 |
1 files changed, 76 insertions, 15 deletions
diff --git a/lisp/dos-w32.el b/lisp/dos-w32.el index a617bbec74e..cb159e6fc6d 100644 --- a/lisp/dos-w32.el +++ b/lisp/dos-w32.el | |||
| @@ -64,25 +64,67 @@ | |||
| 64 | Each element has the form (REGEXP . TYPE), where REGEXP is matched | 64 | Each element has the form (REGEXP . TYPE), where REGEXP is matched |
| 65 | against the file name, and TYPE is nil for text, t for binary.") | 65 | against the file name, and TYPE is nil for text, t for binary.") |
| 66 | 66 | ||
| 67 | ;; Return the pair matching filename on file-name-buffer-file-type-alist, | ||
| 68 | ;; or nil otherwise. | ||
| 69 | (defun find-buffer-file-type-match (filename) | ||
| 70 | (let ((alist file-name-buffer-file-type-alist) | ||
| 71 | (found nil)) | ||
| 72 | (let ((case-fold-search t)) | ||
| 73 | (setq filename (file-name-sans-versions filename)) | ||
| 74 | (while (and (not found) alist) | ||
| 75 | (if (string-match (car (car alist)) filename) | ||
| 76 | (setq found (car alist))) | ||
| 77 | (setq alist (cdr alist))) | ||
| 78 | found))) | ||
| 79 | |||
| 67 | (defun find-buffer-file-type (filename) | 80 | (defun find-buffer-file-type (filename) |
| 68 | ;; First check if file is on an untranslated filesystem, then on the alist. | 81 | ;; First check if file is on an untranslated filesystem, then on the alist. |
| 69 | (if (untranslated-file-p filename) | 82 | (if (untranslated-file-p filename) |
| 70 | t ; for binary | 83 | t ; for binary |
| 71 | (let ((alist file-name-buffer-file-type-alist) | 84 | (let ((match (find-buffer-file-type-match filename)) |
| 72 | (found nil) | 85 | (code)) |
| 73 | (code nil)) | 86 | (if (not match) |
| 74 | (let ((case-fold-search t)) | 87 | default-buffer-file-type |
| 75 | (setq filename (file-name-sans-versions filename)) | 88 | (setq code (cdr match)) |
| 76 | (while (and (not found) alist) | 89 | (cond ((memq code '(nil t)) code) |
| 77 | (if (string-match (car (car alist)) filename) | 90 | ((and (symbolp code) (fboundp code)) |
| 78 | (setq code (cdr (car alist)) | 91 | (funcall code filename))))))) |
| 79 | found t)) | 92 | |
| 80 | (setq alist (cdr alist)))) | 93 | (defun find-buffer-file-type-coding-system (command args) |
| 81 | (if found | 94 | "Choose a coding system for a file operation. |
| 82 | (cond ((memq code '(nil t)) code) | 95 | If COMMAND is 'insert-file-contents', the coding system is chosen based |
| 83 | ((and (symbolp code) (fboundp code)) | 96 | upon the filename, the contents of 'untranslated-filesystem-list' and |
| 84 | (funcall code filename))) | 97 | 'file-name-buffer-file-type-alist', and whether the file exists: |
| 85 | default-buffer-file-type)))) | 98 | |
| 99 | If it matches in 'untranslated-filesystem-list': 'no-conversion' | ||
| 100 | If it matches in 'file-name-buffer-file-type-alist': | ||
| 101 | If the match is t (for binary): 'no-conversion' | ||
| 102 | If the match is nil (for text): 'emacs-mule-dos' | ||
| 103 | Otherwise: | ||
| 104 | If the file exists: 'undecided' | ||
| 105 | If the file does not exist: 'emacs-mule-dos' | ||
| 106 | |||
| 107 | If COMMAND is 'write-region', the coding system is chosen based | ||
| 108 | upon the value of 'buffer-file-type': If t, the coding system is | ||
| 109 | 'no-conversion', otherwise it is 'emacs-mule-dos'." | ||
| 110 | (let ((op (nth 0 command)) | ||
| 111 | (target) | ||
| 112 | (binary) | ||
| 113 | (undecided nil)) | ||
| 114 | (cond ((eq op 'insert-file-contents) | ||
| 115 | (setq target (nth 1 command)) | ||
| 116 | (setq binary (find-buffer-file-type target)) | ||
| 117 | (if (not binary) | ||
| 118 | (setq undecided | ||
| 119 | (and (file-exists-p target) | ||
| 120 | (not (find-buffer-file-type-match target)))))) | ||
| 121 | ((eq op 'write-region) | ||
| 122 | (setq binary buffer-file-type))) | ||
| 123 | (cond (binary '(no-conversion . no-conversion)) | ||
| 124 | (undecided '(undecided . undecided)) | ||
| 125 | (t '(emacs-mule-dos . emacs-mule-dos))))) | ||
| 126 | |||
| 127 | (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system) | ||
| 86 | 128 | ||
| 87 | (defun find-file-binary (filename) | 129 | (defun find-file-binary (filename) |
| 88 | "Visit file FILENAME and treat it as binary." | 130 | "Visit file FILENAME and treat it as binary." |
| @@ -166,6 +208,25 @@ filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"." | |||
| 166 | (delete (untranslated-canonical-name filesystem) | 208 | (delete (untranslated-canonical-name filesystem) |
| 167 | untranslated-filesystem-list))) | 209 | untranslated-filesystem-list))) |
| 168 | 210 | ||
| 211 | ;; Process I/O decoding and encoding. | ||
| 212 | |||
| 213 | (defun find-binary-process-coding-system (op args) | ||
| 214 | "Choose a coding system for process I/O. | ||
| 215 | The coding system for decode is 'no-conversion' if 'binary-process-output' | ||
| 216 | is non-nil, and 'emacs-mule-dos' otherwise. Similarly, the coding system | ||
| 217 | for encode is 'no-conversion' if 'binary-process-input' is non-nil, | ||
| 218 | and 'emacs-mule-dos' otherwise." | ||
| 219 | (let ((decode 'emacs-mule-dos) | ||
| 220 | (encode 'emacs-mule-dos)) | ||
| 221 | (if binary-process-output | ||
| 222 | (setq decode 'no-conversion)) | ||
| 223 | (if binary-process-input | ||
| 224 | (setq encode 'no-conversion)) | ||
| 225 | (cons decode encode))) | ||
| 226 | |||
| 227 | (modify-coding-system-alist 'process "" 'find-binary-process-coding-system) | ||
| 228 | |||
| 229 | |||
| 169 | (provide 'dos-w32) | 230 | (provide 'dos-w32) |
| 170 | 231 | ||
| 171 | ;;; dos-w32.el ends here | 232 | ;;; dos-w32.el ends here |