Mercurial > emacs
annotate lisp/dos-w32.el @ 20500:cfb872a45411
(isearch-mode-map): Don't count above 256
when setting up printing characters.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 21 Dec 1997 02:33:57 +0000 |
parents | c4d7c2fd4852 |
children | cbd9e55a6cdc |
rev | line source |
---|---|
16591
afb15f49a0c9
Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents:
16234
diff
changeset
|
1 ;;; dos-w32.el --- Functions shared among MS-DOS and W32 (NT/95) platforms |
16026 | 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 ;; Use ";" instead of ":" as a path separator (from files.el). | |
33 (setq path-separator ";") | |
34 | |
35 ;; Set the null device (for compile.el). | |
36 (setq grep-null-device "NUL") | |
37 | |
38 ;; Set the grep regexp to match entries with drive letters. | |
39 (setq grep-regexp-alist | |
40 '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3))) | |
41 | |
42 ;; For distinguishing file types based upon suffixes. | |
43 (defvar file-name-buffer-file-type-alist | |
44 '( | |
45 ("[:/].*config.sys$" . nil) ; config.sys text | |
46 ("\\.elc$" . t) ; emacs stuff | |
19970
c4d7c2fd4852
(file-name-buffer-file-type-alist): Remove the files with ".dos" extension
Eli Zaretskii <eliz@gnu.org>
parents:
19690
diff
changeset
|
47 ("\\.\\(obj\\|exe\\|com\\|lib\\|sym\\|sys\\|chk\\|out\\|bin\\|ico\\|pif\\|class\\)$" . t) |
16026 | 48 ; MS-Dos stuff |
19690
ceed5706d45e
(file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents:
19656
diff
changeset
|
49 ("\\.\\(dll\\|drv\\|cpl\\|scr\\vbx\\|386\\|vxd\\|fon\\|fnt\\|fot\\|ttf\\|grp\\)$" . t) |
ceed5706d45e
(file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents:
19656
diff
changeset
|
50 ; Windows stuff |
ceed5706d45e
(file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents:
19656
diff
changeset
|
51 ("\\.\\(hlp\\|bmp\\|wav\\|avi\\|mpg\\|jpg\\|tif\\mov\\au\\)" . t) |
ceed5706d45e
(file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents:
19656
diff
changeset
|
52 ; known binary data files |
16026 | 53 ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t) |
54 ; Packers | |
19690
ceed5706d45e
(file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents:
19656
diff
changeset
|
55 ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\|jar\\)$" . t) |
16026 | 56 ; Unix stuff |
57 ("\\.tp[ulpw]$" . t) | |
58 ; Borland Pascal stuff | |
59 ("[:/]tags$" . t) | |
60 ; Emacs TAGS file | |
61 ) | |
62 "*Alist for distinguishing text files from binary files. | |
63 Each element has the form (REGEXP . TYPE), where REGEXP is matched | |
64 against the file name, and TYPE is nil for text, t for binary.") | |
65 | |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
66 ;; Return the pair matching filename on file-name-buffer-file-type-alist, |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
67 ;; or nil otherwise. |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
68 (defun find-buffer-file-type-match (filename) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
69 (let ((alist file-name-buffer-file-type-alist) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
70 (found nil)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
71 (let ((case-fold-search t)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
72 (setq filename (file-name-sans-versions filename)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
73 (while (and (not found) alist) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
74 (if (string-match (car (car alist)) filename) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
75 (setq found (car alist))) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
76 (setq alist (cdr alist))) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
77 found))) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
78 |
19656
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
79 ;; Don't check for untranslated file systems here. |
16026 | 80 (defun find-buffer-file-type (filename) |
19656
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
81 (let ((match (find-buffer-file-type-match filename)) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
82 (code)) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
83 (if (not match) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
84 default-buffer-file-type |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
85 (setq code (cdr match)) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
86 (cond ((memq code '(nil t)) code) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
87 ((and (symbolp code) (fboundp code)) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
88 (funcall code filename)))))) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
89 |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
90 (setq-default buffer-file-coding-system 'undecided-dos) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
91 |
18912
d6d9a466fad2
(find-buffer-file-type-coding-system,
Geoff Voelker <voelker@cs.washington.edu>
parents:
18872
diff
changeset
|
92 (defun find-buffer-file-type-coding-system (command) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
93 "Choose a coding system for a file operation. |
18872
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
94 If COMMAND is `insert-file-contents', the coding system is chosen based |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
95 upon the filename, the contents of `untranslated-filesystem-list' and |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
96 `file-name-buffer-file-type-alist', and whether the file exists: |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
97 |
18872
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
98 If it matches in `untranslated-filesystem-list': |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
99 If the file exists: `no-conversion' |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
100 If the file does not exist: `undecided' |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
101 If it matches in `file-name-buffer-file-type-alist': |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
102 If the match is t (for binary): `no-conversion' |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
103 If the match is nil (for dos-text): `undecided-dos' |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
104 Otherwise: |
18872
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
105 If the file exists: `undecided' |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
106 If the file does not exist: `undecided-dos' |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
107 |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
108 If COMMAND is `write-region', the coding system is chosen based upon |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
109 the value of `buffer-file-coding-system' and `buffer-file-type'. If |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
110 `buffer-file-coding-system' is non-nil, its value is used. If it is |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
111 nil and `buffer-file-type' is t, the coding system is `no-conversion'. |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
112 Otherwise, it is `undecided-dos'. |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
113 |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
114 The two most common situations are when DOS and Unix files are read |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
115 and written, and their names do not match in |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
116 `untranslated-filesystem-list' and `file-name-buffer-file-type-alist'. |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
117 In these cases, the coding system initially will be `undecided'. As |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
118 the file is read in the DOS case, the coding system will be changed to |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
119 `undecided-dos' as CR/LFs are detected. As the file is read in the |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
120 Unix case, the coding system will be changed to `undecided-unix' as |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
121 LFs are detected. In both cases, `buffer-file-coding-system' will be |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
122 set to the appropriate coding system, and the value of |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
123 `buffer-file-coding-system' will be used when writing the file." |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
124 |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
125 (let ((op (nth 0 command)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
126 (target) |
18863
62090ffa4583
(find-buffer-file-type-coding-system):
Richard M. Stallman <rms@gnu.org>
parents:
18858
diff
changeset
|
127 (binary nil) (text nil) |
19656
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
128 (undecided nil) (undecided-unix nil)) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
129 (cond ((eq op 'insert-file-contents) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
130 (setq target (nth 1 command)) |
19656
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
131 ;; First check for a file name that indicates |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
132 ;; it is truly binary. |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
133 (setq binary (find-buffer-file-type target)) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
134 (cond (binary) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
135 ;; Next check for files that MUST use DOS eol conversion. |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
136 ((find-buffer-file-type-match target) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
137 (setq text t)) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
138 ;; For any other existing file, decide based on contents. |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
139 ((file-exists-p target) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
140 (setq undecided t)) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
141 ;; Next check for a non-DOS file system. |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
142 ((untranslated-file-p target) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
143 (setq undecided-unix t))) |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
144 (cond (binary '(no-conversion . no-conversion)) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
145 (text '(undecided-dos . undecided-dos)) |
19656
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
146 (undecided-unix '(undecided-unix . undecided-unix)) |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
147 (undecided '(undecided . undecided)) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
148 (t '(undecided-dos . undecided-dos)))) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
149 ((eq op 'write-region) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
150 (if buffer-file-coding-system |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
151 (cons buffer-file-coding-system |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
152 buffer-file-coding-system) |
19656
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
153 ;; Normally this is used only in a non-file-visiting |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
154 ;; buffer, because normally buffer-file-coding-system is non-nil |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
155 ;; in a file-visiting buffer. |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
156 (if buffer-file-type |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
157 '(no-conversion . no-conversion) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
158 '(undecided-dos . undecided-dos))))))) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
159 |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
160 (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system) |
16026 | 161 |
162 (defun find-file-binary (filename) | |
163 "Visit file FILENAME and treat it as binary." | |
164 (interactive "FFind file binary: ") | |
165 (let ((file-name-buffer-file-type-alist '(("" . t)))) | |
166 (find-file filename))) | |
167 | |
168 (defun find-file-text (filename) | |
169 "Visit file FILENAME and treat it as a text file." | |
170 (interactive "FFind file text: ") | |
171 (let ((file-name-buffer-file-type-alist '(("" . nil)))) | |
172 (find-file filename))) | |
173 | |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
174 (defun find-file-not-found-set-buffer-file-coding-system () |
16026 | 175 (save-excursion |
176 (set-buffer (current-buffer)) | |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
177 (let* ((dummy-insert-op (list 'insert-file-contents (buffer-file-name))) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
178 (coding-system-pair |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
179 (find-buffer-file-type-coding-system dummy-insert-op))) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
180 (setq buffer-file-coding-system (car coding-system-pair)) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
181 (setq buffer-file-type (eq buffer-file-coding-system 'no-conversion))))) |
16026 | 182 |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
183 ;;; To set the default coding system on new files. |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
184 (add-hook 'find-file-not-found-hooks |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
185 'find-file-not-found-set-buffer-file-coding-system) |
16026 | 186 |
187 ;;; To accomodate filesystems that do not require CR/LF translation. | |
188 (defvar untranslated-filesystem-list nil | |
189 "List of filesystems that require no CR/LF translation when reading | |
190 and writing files. Each filesystem in the list is a string naming | |
191 the directory prefix corresponding to the filesystem.") | |
192 | |
193 (defun untranslated-canonical-name (filename) | |
194 "Return FILENAME in a canonicalized form for use with the functions | |
195 dealing with untranslated filesystems." | |
196 (if (memq system-type '(ms-dos windows-nt)) | |
16889
8de32e992e4d
Change uses of win32 to w32.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16591
diff
changeset
|
197 ;; The canonical form for DOS/W32 is with A-Z downcased and all |
16026 | 198 ;; directory separators changed to directory-sep-char. |
199 (let ((name nil)) | |
200 (setq name (mapconcat | |
201 '(lambda (char) | |
202 (if (and (<= ?A char) (<= char ?Z)) | |
203 (char-to-string (+ (- char ?A) ?a)) | |
204 (char-to-string char))) | |
205 filename nil)) | |
206 ;; Use expand-file-name to canonicalize directory separators, except | |
207 ;; with bare drive letters (which would have the cwd appended). | |
208 (if (string-match "^.:$" name) | |
209 name | |
210 (expand-file-name name))) | |
211 filename)) | |
212 | |
213 (defun untranslated-file-p (filename) | |
214 "Return t if FILENAME is on a filesystem that does not require | |
215 CR/LF translation, and nil otherwise." | |
216 (let ((fs (untranslated-canonical-name filename)) | |
217 (ufs-list untranslated-filesystem-list) | |
218 (found nil)) | |
219 (while (and (not found) ufs-list) | |
220 (if (string-match (concat "^" (car ufs-list)) fs) | |
221 (setq found t) | |
222 (setq ufs-list (cdr ufs-list)))) | |
223 found)) | |
224 | |
225 (defun add-untranslated-filesystem (filesystem) | |
226 "Add FILESYSTEM to the list of filesystems that do not require | |
227 CR/LF translation. FILESYSTEM is a string containing the directory | |
228 prefix corresponding to the filesystem. For example, for a Unix | |
229 filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"." | |
17901
6ea4d90cc76b
(add-untranslated-filesystem)
Richard M. Stallman <rms@gnu.org>
parents:
16889
diff
changeset
|
230 (interactive "fUntranslated file system: ") |
16026 | 231 (let ((fs (untranslated-canonical-name filesystem))) |
232 (if (member fs untranslated-filesystem-list) | |
233 untranslated-filesystem-list | |
234 (setq untranslated-filesystem-list | |
235 (cons fs untranslated-filesystem-list))))) | |
236 | |
237 (defun remove-untranslated-filesystem (filesystem) | |
238 "Remove FILESYSTEM from the list of filesystems that do not require | |
239 CR/LF translation. FILESYSTEM is a string containing the directory | |
240 prefix corresponding to the filesystem. For example, for a Unix | |
241 filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"." | |
17901
6ea4d90cc76b
(add-untranslated-filesystem)
Richard M. Stallman <rms@gnu.org>
parents:
16889
diff
changeset
|
242 (interactive "fUntranslated file system: ") |
16026 | 243 (setq untranslated-filesystem-list |
244 (delete (untranslated-canonical-name filesystem) | |
245 untranslated-filesystem-list))) | |
246 | |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
247 ;; Process I/O decoding and encoding. |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
248 |
18912
d6d9a466fad2
(find-buffer-file-type-coding-system,
Geoff Voelker <voelker@cs.washington.edu>
parents:
18872
diff
changeset
|
249 (defun find-binary-process-coding-system (command) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
250 "Choose a coding system for process I/O. |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
251 The coding system for decode is 'no-conversion' if 'binary-process-output' |
18872
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
252 is non-nil, and 'undecided-dos' otherwise. Similarly, the coding system |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
253 for encode is 'no-conversion' if 'binary-process-input' is non-nil, |
18872
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
254 and 'undecided-dos' otherwise." |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
255 (let ((decode 'undecided-dos) |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
256 (encode 'undecided-dos)) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
257 (if binary-process-output |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
258 (setq decode 'no-conversion)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
259 (if binary-process-input |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
260 (setq encode 'no-conversion)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
261 (cons decode encode))) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
262 |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
263 (modify-coding-system-alist 'process "" 'find-binary-process-coding-system) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
264 |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
265 |
16591
afb15f49a0c9
Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents:
16234
diff
changeset
|
266 (provide 'dos-w32) |
16026 | 267 |
16591
afb15f49a0c9
Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents:
16234
diff
changeset
|
268 ;;; dos-w32.el ends here |