Mercurial > emacs
annotate lisp/dos-w32.el @ 24127:250719d2b13b
Initial revision
author | Dave Love <fx@gnu.org> |
---|---|
date | Tue, 19 Jan 1999 19:58:31 +0000 |
parents | d98712ec1252 |
children | 3c29f6165eca |
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 | |
21059 | 5 ;; Maintainer: Geoff Voelker <voelker@cs.washington.edu> |
16026 | 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 | |
22256
9f422336200e
(minibuffer-history-case-insensitive-variables):
Richard M. Stallman <rms@gnu.org>
parents:
21567
diff
changeset
|
35 (setq minibuffer-history-case-insensitive-variables |
9f422336200e
(minibuffer-history-case-insensitive-variables):
Richard M. Stallman <rms@gnu.org>
parents:
21567
diff
changeset
|
36 (cons 'file-name-history minibuffer-history-case-insensitive-variables)) |
9f422336200e
(minibuffer-history-case-insensitive-variables):
Richard M. Stallman <rms@gnu.org>
parents:
21567
diff
changeset
|
37 |
16026 | 38 ;; Set the null device (for compile.el). |
22607
3c91c17a1a0f
(null-device): Renamed from grep-null-device.
Andrew Innes <andrewi@gnu.org>
parents:
22256
diff
changeset
|
39 (setq null-device "NUL") |
16026 | 40 |
41 ;; Set the grep regexp to match entries with drive letters. | |
42 (setq grep-regexp-alist | |
43 '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3))) | |
44 | |
45 ;; For distinguishing file types based upon suffixes. | |
46 (defvar file-name-buffer-file-type-alist | |
47 '( | |
48 ("[:/].*config.sys$" . nil) ; config.sys text | |
49 ("\\.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
|
50 ("\\.\\(obj\\|exe\\|com\\|lib\\|sym\\|sys\\|chk\\|out\\|bin\\|ico\\|pif\\|class\\)$" . t) |
16026 | 51 ; MS-Dos stuff |
19690
ceed5706d45e
(file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents:
19656
diff
changeset
|
52 ("\\.\\(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
|
53 ; Windows stuff |
23393
bcac7111042a
(file-name-buffer-file-type-alist): Fix typo in regexp.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22743
diff
changeset
|
54 ("\\.\\(hlp\\|bmp\\|wav\\|avi\\|mpg\\|jpg\\|tif\\|mov\\|au\\)" . t) |
19690
ceed5706d45e
(file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents:
19656
diff
changeset
|
55 ; known binary data files |
16026 | 56 ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t) |
57 ; Packers | |
19690
ceed5706d45e
(file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents:
19656
diff
changeset
|
58 ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\|jar\\)$" . t) |
16026 | 59 ; Unix stuff |
60 ("\\.tp[ulpw]$" . t) | |
61 ; Borland Pascal stuff | |
22743
ea36144e7977
dos-w32.el (file-name-buffer-file-type-alist): Force tags files to be
Andrew Innes <andrewi@gnu.org>
parents:
22678
diff
changeset
|
62 ("[:/]tags$" . nil) |
16026 | 63 ; Emacs TAGS file |
64 ) | |
65 "*Alist for distinguishing text files from binary files. | |
66 Each element has the form (REGEXP . TYPE), where REGEXP is matched | |
67 against the file name, and TYPE is nil for text, t for binary.") | |
68 | |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
69 ;; 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
|
70 ;; or nil otherwise. |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
71 (defun find-buffer-file-type-match (filename) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
72 (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
|
73 (found nil)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
74 (let ((case-fold-search t)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
75 (setq filename (file-name-sans-versions filename)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
76 (while (and (not found) alist) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
77 (if (string-match (car (car alist)) filename) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
78 (setq found (car alist))) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
79 (setq alist (cdr alist))) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
80 found))) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
81 |
19656
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
82 ;; Don't check for untranslated file systems here. |
16026 | 83 (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
|
84 (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
|
85 (code)) |
98e7893f8679
(find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents:
19400
diff
changeset
|
86 (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
|
87 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
|
88 (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
|
89 (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
|
90 ((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
|
91 (funcall code filename)))))) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
92 |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
93 (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
|
94 |
18912
d6d9a466fad2
(find-buffer-file-type-coding-system,
Geoff Voelker <voelker@cs.washington.edu>
parents:
18872
diff
changeset
|
95 (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
|
96 "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
|
97 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
|
98 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
|
99 `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
|
100 |
18872
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
101 If it matches in `untranslated-filesystem-list': |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
102 If the file exists: `no-conversion' |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
103 If the file does not exist: `undecided' |
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 Otherwise: |
18872
8c7bcffd7327
(find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents:
18863
diff
changeset
|
108 If the file exists: `undecided' |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
109 If the file does not exist: default-buffer-file-coding-system |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
110 |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
111 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
|
112 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
|
113 `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
|
114 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
|
115 Otherwise, it is `undecided-dos'. |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
116 |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
117 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
|
118 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
|
119 `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
|
120 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
|
121 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
|
122 `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
|
123 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
|
124 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
|
125 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
|
126 `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
|
127 |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
128 (let ((op (nth 0 command)) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
129 (target) |
18863
62090ffa4583
(find-buffer-file-type-coding-system):
Richard M. Stallman <rms@gnu.org>
parents:
18858
diff
changeset
|
130 (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
|
131 (undecided nil) (undecided-unix nil)) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
132 (cond ((eq op 'insert-file-contents) |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
133 (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
|
134 ;; 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
|
135 ;; 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
|
136 (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
|
137 (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
|
138 ;; 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
|
139 ((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
|
140 (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
|
141 ;; 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
|
142 ((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
|
143 (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
|
144 ;; 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
|
145 ((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
|
146 (setq undecided-unix t))) |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
147 (cond (binary '(no-conversion . no-conversion)) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
148 (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
|
149 (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
|
150 (undecided '(undecided . undecided)) |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
151 (t (cons default-buffer-file-coding-system |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
152 default-buffer-file-coding-system)))) |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
153 ((eq op 'write-region) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
154 (if buffer-file-coding-system |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
155 (cons buffer-file-coding-system |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
156 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
|
157 ;; 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
|
158 ;; 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
|
159 ;; in a file-visiting buffer. |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
160 (if buffer-file-type |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
161 '(no-conversion . no-conversion) |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
162 '(undecided-dos . undecided-dos))))))) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
163 |
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
164 (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system) |
16026 | 165 |
166 (defun find-file-binary (filename) | |
167 "Visit file FILENAME and treat it as binary." | |
168 (interactive "FFind file binary: ") | |
169 (let ((file-name-buffer-file-type-alist '(("" . t)))) | |
170 (find-file filename))) | |
171 | |
172 (defun find-file-text (filename) | |
173 "Visit file FILENAME and treat it as a text file." | |
174 (interactive "FFind file text: ") | |
175 (let ((file-name-buffer-file-type-alist '(("" . nil)))) | |
176 (find-file filename))) | |
177 | |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
178 (defun find-file-not-found-set-buffer-file-coding-system () |
16026 | 179 (save-excursion |
180 (set-buffer (current-buffer)) | |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
181 (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
|
182 (coding-system-pair |
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
183 (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
|
184 (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
|
185 (setq buffer-file-type (eq buffer-file-coding-system 'no-conversion))))) |
16026 | 186 |
19400
95183e63d1dd
Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents:
18912
diff
changeset
|
187 ;;; 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
|
188 (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
|
189 'find-file-not-found-set-buffer-file-coding-system) |
16026 | 190 |
191 ;;; To accomodate filesystems that do not require CR/LF translation. | |
192 (defvar untranslated-filesystem-list nil | |
193 "List of filesystems that require no CR/LF translation when reading | |
194 and writing files. Each filesystem in the list is a string naming | |
195 the directory prefix corresponding to the filesystem.") | |
196 | |
197 (defun untranslated-canonical-name (filename) | |
198 "Return FILENAME in a canonicalized form for use with the functions | |
199 dealing with untranslated filesystems." | |
200 (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
|
201 ;; The canonical form for DOS/W32 is with A-Z downcased and all |
16026 | 202 ;; directory separators changed to directory-sep-char. |
203 (let ((name nil)) | |
204 (setq name (mapconcat | |
205 '(lambda (char) | |
206 (if (and (<= ?A char) (<= char ?Z)) | |
207 (char-to-string (+ (- char ?A) ?a)) | |
208 (char-to-string char))) | |
209 filename nil)) | |
210 ;; Use expand-file-name to canonicalize directory separators, except | |
211 ;; with bare drive letters (which would have the cwd appended). | |
212 (if (string-match "^.:$" name) | |
213 name | |
214 (expand-file-name name))) | |
215 filename)) | |
216 | |
217 (defun untranslated-file-p (filename) | |
218 "Return t if FILENAME is on a filesystem that does not require | |
219 CR/LF translation, and nil otherwise." | |
220 (let ((fs (untranslated-canonical-name filename)) | |
221 (ufs-list untranslated-filesystem-list) | |
222 (found nil)) | |
223 (while (and (not found) ufs-list) | |
224 (if (string-match (concat "^" (car ufs-list)) fs) | |
225 (setq found t) | |
226 (setq ufs-list (cdr ufs-list)))) | |
227 found)) | |
228 | |
229 (defun add-untranslated-filesystem (filesystem) | |
230 "Add FILESYSTEM to the list of filesystems that do not require | |
231 CR/LF translation. FILESYSTEM is a string containing the directory | |
232 prefix corresponding to the filesystem. For example, for a Unix | |
233 filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"." | |
17901
6ea4d90cc76b
(add-untranslated-filesystem)
Richard M. Stallman <rms@gnu.org>
parents:
16889
diff
changeset
|
234 (interactive "fUntranslated file system: ") |
16026 | 235 (let ((fs (untranslated-canonical-name filesystem))) |
236 (if (member fs untranslated-filesystem-list) | |
237 untranslated-filesystem-list | |
238 (setq untranslated-filesystem-list | |
239 (cons fs untranslated-filesystem-list))))) | |
240 | |
241 (defun remove-untranslated-filesystem (filesystem) | |
242 "Remove FILESYSTEM from the list of filesystems that do not require | |
243 CR/LF translation. FILESYSTEM is a string containing the directory | |
244 prefix corresponding to the filesystem. For example, for a Unix | |
245 filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"." | |
17901
6ea4d90cc76b
(add-untranslated-filesystem)
Richard M. Stallman <rms@gnu.org>
parents:
16889
diff
changeset
|
246 (interactive "fUntranslated file system: ") |
16026 | 247 (setq untranslated-filesystem-list |
248 (delete (untranslated-canonical-name filesystem) | |
249 untranslated-filesystem-list))) | |
250 | |
23682
8d1cbb6f0fb9
(set-default-process-coding-system): Use function on
Geoff Voelker <voelker@cs.washington.edu>
parents:
23393
diff
changeset
|
251 ;;; Override setting chosen at startup. |
8d1cbb6f0fb9
(set-default-process-coding-system): Use function on
Geoff Voelker <voelker@cs.washington.edu>
parents:
23393
diff
changeset
|
252 (defun set-default-process-coding-system () |
8d1cbb6f0fb9
(set-default-process-coding-system): Use function on
Geoff Voelker <voelker@cs.washington.edu>
parents:
23393
diff
changeset
|
253 (setq default-process-coding-system |
8d1cbb6f0fb9
(set-default-process-coding-system): Use function on
Geoff Voelker <voelker@cs.washington.edu>
parents:
23393
diff
changeset
|
254 (if default-enable-multibyte-characters |
8d1cbb6f0fb9
(set-default-process-coding-system): Use function on
Geoff Voelker <voelker@cs.washington.edu>
parents:
23393
diff
changeset
|
255 '(undecided-dos . undecided-dos) |
8d1cbb6f0fb9
(set-default-process-coding-system): Use function on
Geoff Voelker <voelker@cs.washington.edu>
parents:
23393
diff
changeset
|
256 '(raw-text-dos . raw-text-dos)))) |
8d1cbb6f0fb9
(set-default-process-coding-system): Use function on
Geoff Voelker <voelker@cs.washington.edu>
parents:
23393
diff
changeset
|
257 |
8d1cbb6f0fb9
(set-default-process-coding-system): Use function on
Geoff Voelker <voelker@cs.washington.edu>
parents:
23393
diff
changeset
|
258 (add-hook 'before-init-hook 'set-default-process-coding-system) |
18858
ad717015a2de
(find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents:
17901
diff
changeset
|
259 |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
260 ;;; Support for printing under DOS/Windows, see lpr.el and ps-print.el. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
261 |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
262 ;; Function to actually send data to the printer port. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
263 ;; Supports writing directly, and using various programs. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
264 (defun direct-print-region-helper (printer |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
265 start end |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
266 lpr-prog |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
267 delete-text buf display |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
268 rest) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
269 (let* ((directory-sep-char ?\\) ; expand file names in DOS format |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
270 ;; Ignore case when matching known external program names. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
271 (case-fold-search t) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
272 ;; Convert / to \ in printer name, for sake of external programs. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
273 (printer |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
274 (if (stringp printer) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
275 (subst-char-in-string ?/ ?\\ printer) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
276 printer)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
277 ;; Find a directory that is local, to work-around Windows bug. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
278 (safe-dir |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
279 (let ((safe-dirs (list "c:/" (getenv "windir") (getenv "TMPDIR")))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
280 (while (not (file-attributes (car safe-dirs))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
281 (setq safe-dirs (cdr safe-dirs))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
282 (car safe-dirs))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
283 (tempfile |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
284 (make-temp-name |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
285 (expand-file-name "EP" (getenv "TMPDIR")))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
286 ;; capture output for diagnosis |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
287 (errbuf (list (get-buffer-create " *print-region-helper*") t))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
288 ;; It seems that we must be careful about the directory name that |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
289 ;; gets added to the printer port name by write-region when using |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
290 ;; the standard "PRN" or "LPTx" ports, because the write can fail if |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
291 ;; the directory is on a network drive. The same is true when |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
292 ;; asking command.com to copy the file. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
293 ;; No action is needed for UNC printer names, which is just as well |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
294 ;; because `expand-file-name' doesn't support UNC names on MS-DOS. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
295 (if (not (string-match "^\\\\" printer)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
296 (setq printer (expand-file-name printer safe-dir))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
297 ;; Handle known programs specially where necessary. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
298 (unwind-protect |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
299 (cond |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
300 ;; nprint.exe is the standard print command on Netware |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
301 ((string-match "^nprint\\(\\.exe\\)?$" (file-name-nondirectory lpr-prog)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
302 (write-region start end tempfile nil 0) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
303 (call-process lpr-prog nil errbuf nil |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
304 tempfile (concat "P=" printer))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
305 ;; print.exe is a standard command on NT |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
306 ((string-match "^print\\(\\.exe\\)?$" (file-name-nondirectory lpr-prog)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
307 ;; Be careful not to invoke print.exe on MS-DOS or Windows 9x |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
308 ;; though, because it is a TSR program there (hangs Emacs). |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
309 (or (and (eq system-type 'windows-nt) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
310 (null (getenv "winbootdir"))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
311 (error "Printing via print.exe is not supported on MS-DOS or Windows 9x")) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
312 ;; It seems that print.exe always appends a form-feed so we |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
313 ;; should make sure to omit the last FF in the data. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
314 (if (and (> end start) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
315 (char-equal (char-before end) ?\C-l)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
316 (setq end (1- end))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
317 ;; cancel out annotate function for non-PS case |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
318 (let ((write-region-annotate-functions nil)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
319 (write-region start end tempfile nil 0)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
320 (call-process lpr-prog nil errbuf nil |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
321 (concat "/D:" printer) tempfile)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
322 ;; support lpr and similar programs for convenience, but |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
323 ;; supply an explicit filename because the NT version of lpr |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
324 ;; can't read from stdin. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
325 ((> (length lpr-prog) 0) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
326 (write-region start end tempfile nil 0) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
327 (setq rest (append rest (list tempfile))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
328 (apply 'call-process lpr-prog nil errbuf nil rest)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
329 ;; Run command.com to access printer port on Windows 9x, unless |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
330 ;; we are supposed to append to an existing (non-empty) file, |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
331 ;; to work around a bug in Windows 9x that prevents Win32 |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
332 ;; programs from accessing LPT ports reliably. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
333 ((and (eq system-type 'windows-nt) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
334 (getenv "winbootdir") |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
335 ;; file-attributes fails on LPT ports on Windows 9x but |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
336 ;; not on NT, so handle both cases for safety. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
337 (eq (or (nth 7 (file-attributes printer)) 0) 0)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
338 (write-region start end tempfile nil 0) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
339 (let ((w32-quote-process-args nil)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
340 (call-process "command.com" nil errbuf nil "/c" |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
341 (format "copy /b %s %s" tempfile printer)))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
342 ;; write directly to the printer port |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
343 (t |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
344 (write-region start end printer t 0))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
345 ;; ensure we remove the tempfile if created |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
346 (if (file-exists-p tempfile) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
347 (delete-file tempfile))))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
348 |
22678
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
349 (defvar printer-name) |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
350 |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
351 (defun direct-print-region-function (start end |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
352 &optional lpr-prog |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
353 delete-text buf display |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
354 &rest rest) |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
355 "DOS/Windows-specific function to print the region on a printer. |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
356 Writes the region to the device or file which is a value of |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
357 `printer-name' \(which see\), unless the value of `lpr-command' |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
358 indicates a specific program should be invoked." |
22678
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
359 |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
360 ;; DOS printers need the lines to end with CR-LF pairs, so make |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
361 ;; sure it always happens that way, unless the buffer is binary. |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
362 (let* ((coding coding-system-for-write) |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
363 (coding-base |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
364 (if (null coding) 'undecided (coding-system-base coding))) |
23802
4052a2875390
(direct-print-region-function): Try to ensure that
Geoff Voelker <voelker@cs.washington.edu>
parents:
23682
diff
changeset
|
365 (eol-type (coding-system-eol-type coding-base)) |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
366 ;; Make each print-out eject the final page, but don't waste |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
367 ;; paper if the file ends with a form-feed already. |
23802
4052a2875390
(direct-print-region-function): Try to ensure that
Geoff Voelker <voelker@cs.washington.edu>
parents:
23682
diff
changeset
|
368 (write-region-annotate-functions |
4052a2875390
(direct-print-region-function): Try to ensure that
Geoff Voelker <voelker@cs.washington.edu>
parents:
23682
diff
changeset
|
369 (cons |
4052a2875390
(direct-print-region-function): Try to ensure that
Geoff Voelker <voelker@cs.washington.edu>
parents:
23682
diff
changeset
|
370 (lambda (start end) |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
371 (if (not (char-equal (char-before end) ?\C-l)) |
23802
4052a2875390
(direct-print-region-function): Try to ensure that
Geoff Voelker <voelker@cs.washington.edu>
parents:
23682
diff
changeset
|
372 `((,end . "\f")))) |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
373 write-region-annotate-functions)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
374 (printer (or (and (boundp 'dos-printer) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
375 (stringp (symbol-value 'dos-printer)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
376 (symbol-value 'dos-printer)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
377 printer-name))) |
22678
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
378 (or (eq coding-system-for-write 'no-conversion) |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
379 (setq coding-system-for-write |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
380 (aref eol-type 1))) ; force conversion to DOS EOLs |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
381 (direct-print-region-helper printer start end lpr-prog |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
382 delete-text buf display rest))) |
22678
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
383 |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
384 (setq print-region-function 'direct-print-region-function) |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
385 |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
386 ;; Set this to nil if you have a port of the `pr' program |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
387 ;; (e.g., from GNU Textutils), or if you have an `lpr' |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
388 ;; program (see above) that can print page headers. |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
389 ;; If `lpr-headers-switches' is non-nil (the default) and |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
390 ;; `print-region-function' is set to `dos-print-region-function', |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
391 ;; then requests to print page headers will be silently |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
392 ;; ignored, and `print-buffer' and `print-region' produce |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
393 ;; the same output as `lpr-buffer' and `lpr-region', accordingly. |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
394 (setq lpr-headers-switches "(page headers are not supported)") |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
395 |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
396 (defvar ps-printer-name) |
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
397 |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
398 (defun direct-ps-print-region-function (start end |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
399 &optional lpr-prog |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
400 delete-text buf display |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
401 &rest rest) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
402 "DOS/Windows-specific function to print the region on a PostScript printer. |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
403 Writes the region to the device or file which is a value of |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
404 `ps-printer-name' \(which see\), unless the value of `ps-lpr-command' |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
405 indicates a specific program should be invoked." |
22678
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
406 |
24092
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
407 (let ((printer (or (and (boundp 'dos-ps-printer) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
408 (stringp (symbol-value 'dos-ps-printer)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
409 (symbol-value 'dos-ps-printer)) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
410 ps-printer-name))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
411 (direct-print-region-helper printer start end lpr-prog |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
412 delete-text buf display rest))) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
413 |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
414 (setq ps-print-region-function 'direct-ps-print-region-function) |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
415 |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
416 ;(setq ps-lpr-command "gs") |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
417 |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
418 ;(setq ps-lpr-switches '("-q" "-dNOPAUSE" "-sDEVICE=epson" "-r240x60" |
d98712ec1252
(find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents:
23802
diff
changeset
|
419 ; "-sOutputFile=LPT1")) |
22678
e3fe83134880
(direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
22607
diff
changeset
|
420 |
16591
afb15f49a0c9
Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents:
16234
diff
changeset
|
421 (provide 'dos-w32) |
16026 | 422 |
16591
afb15f49a0c9
Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents:
16234
diff
changeset
|
423 ;;; dos-w32.el ends here |