annotate lisp/dos-w32.el @ 19314:860783b225b9

(dos-print-region-function): Force EOL conversion to DOS CR-LF pairs.
author Richard M. Stallman <rms@gnu.org>
date Tue, 12 Aug 1997 05:47:05 +0000
parents d6d9a466fad2
children 95183e63d1dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Maintainer: Geoff Voelker (voelker@cs.washington.edu)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: internal
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; Parts of this code are duplicated functions taken from dos-fns.el
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; and winnt.el.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; Code:
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; Use ";" instead of ":" as a path separator (from files.el).
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 (setq path-separator ";")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; Set the null device (for compile.el).
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (setq grep-null-device "NUL")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; Set the grep regexp to match entries with drive letters.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (setq grep-regexp-alist
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; For distinguishing file types based upon suffixes.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (defvar file-name-buffer-file-type-alist
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 '(
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ("[:/].*config.sys$" . nil) ; config.sys text
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ("\\.elc$" . t) ; emacs stuff
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ("\\.\\(obj\\|exe\\|com\\|lib\\|sys\\|chk\\|out\\|bin\\|ico\\|pif\\)$" . t)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ; MS-Dos stuff
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ; Packers
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\)$" . t)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ; Unix stuff
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ("\\.tp[ulpw]$" . t)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ; Borland Pascal stuff
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ("[:/]tags$" . t)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ; Emacs TAGS file
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 )
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 "*Alist for distinguishing text files from binary files.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 Each element has the form (REGEXP . TYPE), where REGEXP is matched
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 against the file name, and TYPE is nil for text, t for binary.")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
62 ;; 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
63 ;; or nil otherwise.
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
64 (defun find-buffer-file-type-match (filename)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
65 (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
66 (found nil))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
67 (let ((case-fold-search t))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
68 (setq filename (file-name-sans-versions filename))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
69 (while (and (not found) alist)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
70 (if (string-match (car (car alist)) filename)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
71 (setq found (car alist)))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
72 (setq alist (cdr alist)))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
73 found)))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
74
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (defun find-buffer-file-type (filename)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; First check if file is on an untranslated filesystem, then on the alist.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (if (untranslated-file-p filename)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 t ; for binary
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
79 (let ((match (find-buffer-file-type-match filename))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
80 (code))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
81 (if (not match)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
82 default-buffer-file-type
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
83 (setq code (cdr match))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
84 (cond ((memq code '(nil t)) code)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
85 ((and (symbolp code) (fboundp code))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
86 (funcall code filename)))))))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
87
18912
d6d9a466fad2 (find-buffer-file-type-coding-system,
Geoff Voelker <voelker@cs.washington.edu>
parents: 18872
diff changeset
88 (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
89 "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
90 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
91 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
92 `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
93
18872
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
94 If it matches in `untranslated-filesystem-list':
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
95 If the file exists: `no-conversion'
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
96 If the file does not exist: `undecided'
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
97 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
98 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
99 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
100 Otherwise:
18872
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
101 If the file exists: `undecided'
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
102 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
103
18872
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
104 If COMMAND is `write-region', the coding system is chosen based
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
105 upon the value of `buffer-file-type': If t, the coding system is
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
106 `no-conversion', otherwise it is `undecided-dos'."
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
107 (let ((op (nth 0 command))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
108 (target)
18863
62090ffa4583 (find-buffer-file-type-coding-system):
Richard M. Stallman <rms@gnu.org>
parents: 18858
diff changeset
109 (binary nil) (text nil)
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
110 (undecided nil))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
111 (cond ((eq op 'insert-file-contents)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
112 (setq target (nth 1 command))
18872
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
113 (if (untranslated-file-p target)
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
114 (if (file-exists-p target)
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
115 (setq undecided t)
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
116 (setq binary t))
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
117 (setq binary (find-buffer-file-type target))
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
118 (unless binary
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
119 (if (find-buffer-file-type-match target)
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
120 (setq text t)
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
121 (setq undecided (file-exists-p target))))))
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
122 ((eq op 'write-region)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
123 (setq binary buffer-file-type)))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
124 (cond (binary '(no-conversion . no-conversion))
18872
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
125 (text '(undecided-dos . undecided-dos))
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
126 (undecided '(undecided . undecided))
18863
62090ffa4583 (find-buffer-file-type-coding-system):
Richard M. Stallman <rms@gnu.org>
parents: 18858
diff changeset
127 (t '(undecided-dos . undecided-dos)))))
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
128
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
129 (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (defun find-file-binary (filename)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 "Visit file FILENAME and treat it as binary."
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (interactive "FFind file binary: ")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (let ((file-name-buffer-file-type-alist '(("" . t))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (find-file filename)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (defun find-file-text (filename)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 "Visit file FILENAME and treat it as a text file."
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (interactive "FFind file text: ")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (let ((file-name-buffer-file-type-alist '(("" . nil))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (find-file filename)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (defun find-file-not-found-set-buffer-file-type ()
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (save-excursion
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (set-buffer (current-buffer))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (setq buffer-file-type (find-buffer-file-type (buffer-file-name))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 nil)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;;; To set the default file type on new files.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (add-hook 'find-file-not-found-hooks 'find-file-not-found-set-buffer-file-type)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ;;; To accomodate filesystems that do not require CR/LF translation.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (defvar untranslated-filesystem-list nil
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "List of filesystems that require no CR/LF translation when reading
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 and writing files. Each filesystem in the list is a string naming
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 the directory prefix corresponding to the filesystem.")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (defun untranslated-canonical-name (filename)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 "Return FILENAME in a canonicalized form for use with the functions
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 dealing with untranslated filesystems."
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (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
163 ;; The canonical form for DOS/W32 is with A-Z downcased and all
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; directory separators changed to directory-sep-char.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (let ((name nil))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (setq name (mapconcat
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 '(lambda (char)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (if (and (<= ?A char) (<= char ?Z))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (char-to-string (+ (- char ?A) ?a))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (char-to-string char)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 filename nil))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; Use expand-file-name to canonicalize directory separators, except
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; with bare drive letters (which would have the cwd appended).
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (if (string-match "^.:$" name)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 name
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (expand-file-name name)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 filename))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (defun untranslated-file-p (filename)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 "Return t if FILENAME is on a filesystem that does not require
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 CR/LF translation, and nil otherwise."
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (let ((fs (untranslated-canonical-name filename))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (ufs-list untranslated-filesystem-list)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (found nil))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (while (and (not found) ufs-list)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (if (string-match (concat "^" (car ufs-list)) fs)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (setq found t)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (setq ufs-list (cdr ufs-list))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 found))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defun add-untranslated-filesystem (filesystem)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 "Add FILESYSTEM to the list of filesystems that do not require
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 CR/LF translation. FILESYSTEM is a string containing the directory
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 prefix corresponding to the filesystem. For example, for a Unix
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"."
17901
6ea4d90cc76b (add-untranslated-filesystem)
Richard M. Stallman <rms@gnu.org>
parents: 16889
diff changeset
196 (interactive "fUntranslated file system: ")
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (let ((fs (untranslated-canonical-name filesystem)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (if (member fs untranslated-filesystem-list)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 untranslated-filesystem-list
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (setq untranslated-filesystem-list
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (cons fs untranslated-filesystem-list)))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (defun remove-untranslated-filesystem (filesystem)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 "Remove FILESYSTEM from the list of filesystems that do not require
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 CR/LF translation. FILESYSTEM is a string containing the directory
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 prefix corresponding to the filesystem. For example, for a Unix
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"."
17901
6ea4d90cc76b (add-untranslated-filesystem)
Richard M. Stallman <rms@gnu.org>
parents: 16889
diff changeset
208 (interactive "fUntranslated file system: ")
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (setq untranslated-filesystem-list
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (delete (untranslated-canonical-name filesystem)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 untranslated-filesystem-list)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
213 ;; Process I/O decoding and encoding.
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
214
18912
d6d9a466fad2 (find-buffer-file-type-coding-system,
Geoff Voelker <voelker@cs.washington.edu>
parents: 18872
diff changeset
215 (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
216 "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
217 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
218 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
219 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
220 and 'undecided-dos' otherwise."
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
221 (let ((decode 'undecided-dos)
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
222 (encode 'undecided-dos))
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
223 (if binary-process-output
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
224 (setq decode 'no-conversion))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
225 (if binary-process-input
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
226 (setq encode 'no-conversion))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
227 (cons decode encode)))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
228
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
229 (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
230
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
231
16591
afb15f49a0c9 Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents: 16234
diff changeset
232 (provide 'dos-w32)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
16591
afb15f49a0c9 Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents: 16234
diff changeset
234 ;;; dos-w32.el ends here