Commit | Line | Data |
---|---|---|
f37fec30 | 1 | ;;; dos-nt.el --- Functions shared among MS-DOS and W32 (NT/95) platforms |
a750bcaa RS |
2 | |
3 | ;; Copyright (C) 1996 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Maintainer: Geoff Voelker (voelker@cs.washington.edu) | |
6 | ;; Keywords: internal | |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
12 | ;; the Free Software Foundation; either version 2, or (at your option) | |
13 | ;; any later version. | |
14 | ||
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | ;; Boston, MA 02111-1307, USA. | |
24 | ||
25 | ;;; Commentary: | |
26 | ||
27 | ;; Parts of this code are duplicated functions taken from dos-fns.el | |
28 | ;; and winnt.el. | |
29 | ||
30 | ;;; Code: | |
31 | ||
32 | ;;; Add %t: into the mode line format just after the open-paren. | |
33 | (let ((tail (member " %[(" mode-line-format))) | |
34 | (setcdr tail (cons (purecopy "%t:") | |
35 | (cdr tail)))) | |
36 | ||
37 | ;; Use ";" instead of ":" as a path separator (from files.el). | |
38 | (setq path-separator ";") | |
39 | ||
40 | ;; Set the null device (for compile.el). | |
41 | (setq grep-null-device "NUL") | |
42 | ||
43 | ;; Set the grep regexp to match entries with drive letters. | |
44 | (setq grep-regexp-alist | |
45 | '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3))) | |
46 | ||
47 | ;; For distinguishing file types based upon suffixes. | |
48 | (defvar file-name-buffer-file-type-alist | |
49 | '( | |
50 | ("[:/].*config.sys$" . nil) ; config.sys text | |
51 | ("\\.elc$" . t) ; emacs stuff | |
52 | ("\\.\\(obj\\|exe\\|com\\|lib\\|sys\\|chk\\|out\\|bin\\|ico\\|pif\\)$" . t) | |
53 | ; MS-Dos stuff | |
54 | ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t) | |
55 | ; Packers | |
56 | ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\)$" . t) | |
57 | ; Unix stuff | |
58 | ("\\.tp[ulpw]$" . t) | |
59 | ; Borland Pascal stuff | |
60 | ("[:/]tags$" . t) | |
61 | ; Emacs TAGS file | |
62 | ) | |
63 | "*Alist for distinguishing text files from binary files. | |
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.") | |
66 | ||
67 | (defun find-buffer-file-type (filename) | |
68 | ;; First check if file is on an untranslated filesystem, then on the alist. | |
69 | (if (untranslated-file-p filename) | |
70 | t ; for binary | |
71 | (let ((alist file-name-buffer-file-type-alist) | |
72 | (found nil) | |
73 | (code nil)) | |
74 | (let ((case-fold-search t)) | |
75 | (setq filename (file-name-sans-versions filename)) | |
76 | (while (and (not found) alist) | |
77 | (if (string-match (car (car alist)) filename) | |
78 | (setq code (cdr (car alist)) | |
79 | found t)) | |
80 | (setq alist (cdr alist)))) | |
81 | (if found | |
82 | (cond ((memq code '(nil t)) code) | |
83 | ((and (symbolp code) (fboundp code)) | |
84 | (funcall code filename))) | |
85 | default-buffer-file-type)))) | |
86 | ||
87 | (defun find-file-binary (filename) | |
88 | "Visit file FILENAME and treat it as binary." | |
89 | (interactive "FFind file binary: ") | |
90 | (let ((file-name-buffer-file-type-alist '(("" . t)))) | |
91 | (find-file filename))) | |
92 | ||
93 | (defun find-file-text (filename) | |
94 | "Visit file FILENAME and treat it as a text file." | |
95 | (interactive "FFind file text: ") | |
96 | (let ((file-name-buffer-file-type-alist '(("" . nil)))) | |
97 | (find-file filename))) | |
98 | ||
99 | (defun find-file-not-found-set-buffer-file-type () | |
100 | (save-excursion | |
101 | (set-buffer (current-buffer)) | |
102 | (setq buffer-file-type (find-buffer-file-type (buffer-file-name)))) | |
103 | nil) | |
104 | ||
105 | ;;; To set the default file type on new files. | |
106 | (add-hook 'find-file-not-found-hooks 'find-file-not-found-set-buffer-file-type) | |
107 | ||
108 | ||
109 | ;;; To accomodate filesystems that do not require CR/LF translation. | |
110 | (defvar untranslated-filesystem-list nil | |
111 | "List of filesystems that require no CR/LF translation when reading | |
112 | and writing files. Each filesystem in the list is a string naming | |
113 | the directory prefix corresponding to the filesystem.") | |
114 | ||
115 | (defun untranslated-canonical-name (filename) | |
116 | "Return FILENAME in a canonicalized form for use with the functions | |
117 | dealing with untranslated filesystems." | |
118 | (if (memq system-type '(ms-dos windows-nt)) | |
119 | ;; The canonical form for DOS/NT/Win95 is with A-Z downcased and all | |
120 | ;; directory separators changed to directory-sep-char. | |
121 | (let ((name nil)) | |
122 | (setq name (mapconcat | |
123 | '(lambda (char) | |
124 | (if (and (<= ?A char) (<= char ?Z)) | |
125 | (char-to-string (+ (- char ?A) ?a)) | |
126 | (char-to-string char))) | |
127 | filename nil)) | |
128 | ;; Use expand-file-name to canonicalize directory separators, except | |
129 | ;; with bare drive letters (which would have the cwd appended). | |
130 | (if (string-match "^.:$" name) | |
131 | name | |
132 | (expand-file-name name))) | |
133 | filename)) | |
134 | ||
135 | (defun untranslated-file-p (filename) | |
136 | "Return t if FILENAME is on a filesystem that does not require | |
137 | CR/LF translation, and nil otherwise." | |
138 | (let ((fs (untranslated-canonical-name filename)) | |
139 | (ufs-list untranslated-filesystem-list) | |
140 | (found nil)) | |
141 | (while (and (not found) ufs-list) | |
142 | (if (string-match (concat "^" (car ufs-list)) fs) | |
143 | (setq found t) | |
144 | (setq ufs-list (cdr ufs-list)))) | |
145 | found)) | |
146 | ||
147 | (defun add-untranslated-filesystem (filesystem) | |
148 | "Add FILESYSTEM to the list of filesystems that do not require | |
149 | CR/LF translation. FILESYSTEM is a string containing the directory | |
150 | prefix corresponding to the filesystem. For example, for a Unix | |
151 | filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"." | |
152 | (let ((fs (untranslated-canonical-name filesystem))) | |
153 | (if (member fs untranslated-filesystem-list) | |
154 | untranslated-filesystem-list | |
155 | (setq untranslated-filesystem-list | |
156 | (cons fs untranslated-filesystem-list))))) | |
157 | ||
158 | (defun remove-untranslated-filesystem (filesystem) | |
159 | "Remove FILESYSTEM from the list of filesystems that do not require | |
160 | CR/LF translation. FILESYSTEM is a string containing the directory | |
161 | prefix corresponding to the filesystem. For example, for a Unix | |
162 | filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"." | |
163 | (setq untranslated-filesystem-list | |
164 | (delete (untranslated-canonical-name filesystem) | |
165 | untranslated-filesystem-list))) | |
166 | ||
167 | (provide 'dos-nt) | |
168 | ||
169 | ;;; dos-nt.el ends here |