annotate lisp/dos-w32.el @ 74439:ddcbd2c1b70d

Update copyright years.
author Glenn Morris <rgm@gnu.org>
date Tue, 05 Dec 2006 06:15:26 +0000
parents d317c5ea9079
children e3694f1cb928 f1d13e615070
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
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
74439
ddcbd2c1b70d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 72052
diff changeset
3 ;; Copyright (C) 1996, 2001, 2002, 2003, 2004, 2005,
68651
3bd95f4f2941 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64762
diff changeset
4 ;; 2006 Free Software Foundation, Inc.
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
21059
cbd9e55a6cdc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 19970
diff changeset
6 ;; Maintainer: Geoff Voelker <voelker@cs.washington.edu>
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: internal
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; 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
13 ;; the Free Software Foundation; either version 2, or (at your option)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 53740
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 53740
diff changeset
24 ;; Boston, MA 02110-1301, USA.
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Parts of this code are duplicated functions taken from dos-fns.el
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; and winnt.el.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; Code:
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; Use ";" instead of ":" as a path separator (from files.el).
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (setq path-separator ";")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
22256
9f422336200e (minibuffer-history-case-insensitive-variables):
Richard M. Stallman <rms@gnu.org>
parents: 21567
diff changeset
36 (setq minibuffer-history-case-insensitive-variables
9f422336200e (minibuffer-history-case-insensitive-variables):
Richard M. Stallman <rms@gnu.org>
parents: 21567
diff changeset
37 (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
38
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; 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
40 (setq null-device "NUL")
16026
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
24658
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
46 ("\\.\\(obj\\|exe\\|com\\|lib\\|sys\\|bin\\|ico\\|pif\\|class\\)$" . t)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ; MS-Dos stuff
24658
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
48 ("\\.\\(dll\\|drv\\|386\\|vxd\\|fon\\|fnt\\|fot\\|ttf\\|grp\\)$" . t)
19690
ceed5706d45e (file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents: 19656
diff changeset
49 ; Windows stuff
26798
89a8ac5aa753 (file-name-buffer-file-type-alist): Add `$' at end of
Gerd Moellmann <gerd@gnu.org>
parents: 25482
diff changeset
50 ("\\.\\(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
51 ; known binary data files
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ; Packers
19690
ceed5706d45e (file-name-buffer-file-type-alist): Add more
Geoff Voelker <voelker@cs.washington.edu>
parents: 19656
diff changeset
54 ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\|jar\\)$" . t)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ; Unix stuff
46300
7fb1d661f610 *** empty log message ***
Pavel Janík <Pavel@Janik.cz>
parents: 46188
diff changeset
56 ("\\.sx[dmicw]$" . t) ; OpenOffice.org
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
57 ("\\.tp[ulpw]$" . t) ; borland Pascal stuff
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
58 ("[:/]tags$" . nil) ; emacs TAGS file
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 )
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 "*Alist for distinguishing text files from binary files.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 Each element has the form (REGEXP . TYPE), where REGEXP is matched
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 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
63
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
64 ;; 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
65 ;; or nil otherwise.
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
66 (defun find-buffer-file-type-match (filename)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
67 (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
68 (found nil))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
69 (let ((case-fold-search t))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
70 (setq filename (file-name-sans-versions filename))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
71 (while (and (not found) alist)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
72 (if (string-match (car (car alist)) filename)
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
73 (setq found (car alist)))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
74 (setq alist (cdr alist)))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
75 found)))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
76
19656
98e7893f8679 (find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents: 19400
diff changeset
77 ;; Don't check for untranslated file systems here.
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (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
79 (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
80 (code))
98e7893f8679 (find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents: 19400
diff changeset
81 (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
82 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
83 (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
84 (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
85 ((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
86 (funcall code filename))))))
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
87
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
88 (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
89
18912
d6d9a466fad2 (find-buffer-file-type-coding-system,
Geoff Voelker <voelker@cs.washington.edu>
parents: 18872
diff changeset
90 (defun find-buffer-file-type-coding-system (command)
72052
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
91 "Choose a coding system for a file operation in COMMAND.
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
92 COMMAND is a list that specifies the operation, and I/O primitive as its
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
93 CAR, and the arguments that might be given to that operation as its CDR.
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
94 If operation is `insert-file-contents', the coding system is chosen based
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
95 upon the filename (the CAR of the arguments beyond the operation), the contents
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
96 of `untranslated-filesystem-list' and `file-name-buffer-file-type-alist',
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
97 and whether the file exists:
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
98
18872
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
99 If it matches in `untranslated-filesystem-list':
34110
a47622945cee (find-buffer-file-type-coding-system): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 32983
diff changeset
100 If the file exists: `undecided'
a47622945cee (find-buffer-file-type-coding-system): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 32983
diff changeset
101 If the file does not exist: `undecided-unix'
18872
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
102 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
103 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
104 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
105 Otherwise:
18872
8c7bcffd7327 (find-buffer-file-type-coding-system):
Geoff Voelker <voelker@cs.washington.edu>
parents: 18863
diff changeset
106 If the file exists: `undecided'
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
107 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
108
72052
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
109 If operation is `write-region', the coding system is chosen based upon
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
110 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
111 `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
112 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
113 Otherwise, it is `undecided-dos'.
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
114
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
115 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
116 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
117 `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
118 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
119 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
120 `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
121 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
122 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
123 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
124 `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
125
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
126 (let ((op (nth 0 command))
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
127 (target)
18863
62090ffa4583 (find-buffer-file-type-coding-system):
Richard M. Stallman <rms@gnu.org>
parents: 18858
diff changeset
128 (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
129 (undecided nil) (undecided-unix nil))
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
130 (cond ((eq op 'insert-file-contents)
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
131 (setq target (nth 1 command))
72052
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
132 ;; If TARGET is a cons cell, it has the form (FILENAME . BUFFER),
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
133 ;; where BUFFER is a buffer into which the file was already read,
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
134 ;; but its contents were not yet decoded. (This form of the
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
135 ;; arguments is used, e.g., in arc-mode.el.) This function
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
136 ;; doesn't care about the contents, it only looks at the file's
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
137 ;; name, which is the CAR of the cons cell.
d317c5ea9079 (find-buffer-file-type-coding-system): Support calls where `(nth 1 command)'
Eli Zaretskii <eliz@gnu.org>
parents: 71428
diff changeset
138 (if (consp target) (setq target (car target)))
19656
98e7893f8679 (find-buffer-file-type): Don't check for untranslated file systems here.
Richard M. Stallman <rms@gnu.org>
parents: 19400
diff changeset
139 ;; 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
140 ;; 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
141 (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
142 (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
143 ;; 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
144 ((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
145 (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
146 ;; 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
147 ((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
148 (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
149 ;; 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
150 ((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
151 (setq undecided-unix t)))
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
152 (cond (binary '(no-conversion . no-conversion))
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
153 (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
154 (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
155 (undecided '(undecided . undecided))
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
156 (t (cons default-buffer-file-coding-system
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
157 default-buffer-file-coding-system))))
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
158 ((eq op 'write-region)
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
159 (if buffer-file-coding-system
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
160 (cons buffer-file-coding-system
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
161 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
162 ;; 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
163 ;; 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
164 ;; in a file-visiting buffer.
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
165 (if buffer-file-type
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
166 '(no-conversion . no-conversion)
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
167 '(undecided-dos . undecided-dos)))))))
18858
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
168
ad717015a2de (find-buffer-file-type-coding-system)
Richard M. Stallman <rms@gnu.org>
parents: 17901
diff changeset
169 (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
171 (defun find-file-binary (filename)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 "Visit file FILENAME and treat it as binary."
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (interactive "FFind file binary: ")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (let ((file-name-buffer-file-type-alist '(("" . t))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (find-file filename)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
177 (defun find-file-text (filename)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 "Visit file FILENAME and treat it as a text file."
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (interactive "FFind file text: ")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (let ((file-name-buffer-file-type-alist '(("" . nil))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (find-file filename)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
183 (defun find-file-not-found-set-buffer-file-coding-system ()
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (save-excursion
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (set-buffer (current-buffer))
32983
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
186 (let ((coding buffer-file-coding-system))
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
187 ;; buffer-file-coding-system is already set by
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
188 ;; find-operation-coding-system, which was called from
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
189 ;; insert-file-contents. All that's left is to change
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
190 ;; the EOL conversion, if required by the user.
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
191 (when (and (null coding-system-for-read)
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
192 (or inhibit-eol-conversion
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
193 (untranslated-file-p (buffer-file-name))))
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
194 (setq coding (coding-system-change-eol-conversion coding 0))
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
195 (setq buffer-file-coding-system coding))
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
196 (setq buffer-file-type (eq buffer-file-coding-system 'no-conversion)))))
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
198 ;;; To set the default coding system on new files.
71428
4dc3f74ad23f (top level): Use find-file-not-found-functions instead of the obsolete
Eli Zaretskii <eliz@gnu.org>
parents: 68651
diff changeset
199 (add-hook 'find-file-not-found-functions
19400
95183e63d1dd Set default coding system to undecided-dos.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18912
diff changeset
200 'find-file-not-found-set-buffer-file-coding-system)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 ;;; To accomodate filesystems that do not require CR/LF translation.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (defvar untranslated-filesystem-list nil
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
204 "List of filesystems that require no CR/LF translation when reading
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 and writing files. Each filesystem in the list is a string naming
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 the directory prefix corresponding to the filesystem.")
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (defun untranslated-canonical-name (filename)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 "Return FILENAME in a canonicalized form for use with the functions
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 dealing with untranslated filesystems."
49549
99be3a1e2589 Cygwin support patch.
Juanma Barranquero <lekktu@gmail.com>
parents: 46300
diff changeset
211 (if (memq system-type '(ms-dos windows-nt cygwin))
16889
8de32e992e4d Change uses of win32 to w32.
Geoff Voelker <voelker@cs.washington.edu>
parents: 16591
diff changeset
212 ;; 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
213 ;; directory separators changed to directory-sep-char.
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (let ((name nil))
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
215 (setq name (mapconcat
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
216 '(lambda (char)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (if (and (<= ?A char) (<= char ?Z))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (char-to-string (+ (- char ?A) ?a))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (char-to-string char)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 filename nil))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ;; Use expand-file-name to canonicalize directory separators, except
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;; with bare drive letters (which would have the cwd appended).
24913
76764b2157af (untranslated-canonical-name): Avoid expanding
Andrew Innes <andrewi@gnu.org>
parents: 24658
diff changeset
223 ;; Avoid expanding names that could trigger ange-ftp to prompt
76764b2157af (untranslated-canonical-name): Avoid expanding
Andrew Innes <andrewi@gnu.org>
parents: 24658
diff changeset
224 ;; for passwords, though.
76764b2157af (untranslated-canonical-name): Avoid expanding
Andrew Innes <andrewi@gnu.org>
parents: 24658
diff changeset
225 (if (or (string-match "^.:$" name)
76764b2157af (untranslated-canonical-name): Avoid expanding
Andrew Innes <andrewi@gnu.org>
parents: 24658
diff changeset
226 (string-match "^/[^/:]+:" name))
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 name
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (expand-file-name name)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 filename))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (defun untranslated-file-p (filename)
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
232 "Return t if FILENAME is on a filesystem that does not require
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 CR/LF translation, and nil otherwise."
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (let ((fs (untranslated-canonical-name filename))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (ufs-list untranslated-filesystem-list)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (found nil))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (while (and (not found) ufs-list)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (if (string-match (concat "^" (car ufs-list)) fs)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (setq found t)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (setq ufs-list (cdr ufs-list))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 found))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (defun add-untranslated-filesystem (filesystem)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 "Add FILESYSTEM to the list of filesystems that do not require
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 CR/LF translation. FILESYSTEM is a string containing the directory
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
246 prefix corresponding to the filesystem. For example, for a Unix
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"."
32983
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
248 ;; We use "D", not "f", to avoid confusing the user: "f" prompts
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
249 ;; with a directory, but RET returns the current buffer's file, not
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
250 ;; its directory.
a7eb5c4fe0ba (find-file-not-found-set-buffer-file-coding-system):
Eli Zaretskii <eliz@gnu.org>
parents: 26798
diff changeset
251 (interactive "DUntranslated file system: ")
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (let ((fs (untranslated-canonical-name filesystem)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (if (member fs untranslated-filesystem-list)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 untranslated-filesystem-list
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (setq untranslated-filesystem-list
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (cons fs untranslated-filesystem-list)))))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defun remove-untranslated-filesystem (filesystem)
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
259 "Remove FILESYSTEM from the list of filesystems that do not require
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 CR/LF translation. FILESYSTEM is a string containing the directory
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
261 prefix corresponding to the filesystem. For example, for a Unix
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"."
17901
6ea4d90cc76b (add-untranslated-filesystem)
Richard M. Stallman <rms@gnu.org>
parents: 16889
diff changeset
263 (interactive "fUntranslated file system: ")
46188
7864bcf48126 (file-name-buffer-file-type-alist): Add knowledge of .sx[dmicw] file
Francesco Potortì <pot@gnu.org>
parents: 38001
diff changeset
264 (setq untranslated-filesystem-list
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (delete (untranslated-canonical-name filesystem)
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 untranslated-filesystem-list)))
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
268 ;;; 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
269
24658
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
270 (defvar direct-print-region-use-command-dot-com t
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
271 "*Control whether command.com is used to print on Windows 9x.")
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
272
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
273 ;; 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
274 ;; Supports writing directly, and using various programs.
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
275 (defun direct-print-region-helper (printer
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
276 start end
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
277 lpr-prog
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
278 delete-text buf display
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
279 rest)
24658
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
280 (let* (;; Ignore case when matching known external program names.
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
281 (case-fold-search t)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
282 ;; 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
283 (printer
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
284 (if (stringp printer)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
285 (subst-char-in-string ?/ ?\\ printer)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
286 printer))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
287 ;; 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
288 (safe-dir
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
289 (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
290 (while (not (file-attributes (car safe-dirs)))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
291 (setq safe-dirs (cdr safe-dirs)))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
292 (car safe-dirs)))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
293 (tempfile
24658
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
294 (subst-char-in-string
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
295 ?/ ?\\
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
296 (make-temp-name
25482
f1d437596538 (direct-print-region-helper): Use temporary-file-directory.
Eli Zaretskii <eliz@gnu.org>
parents: 24913
diff changeset
297 (expand-file-name "EP" temporary-file-directory))))
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
298 ;; capture output for diagnosis
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
299 (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
300 ;; 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
301 ;; 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
302 ;; 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
303 ;; 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
304 ;; asking command.com to copy the file.
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
305 ;; 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
306 ;; because `expand-file-name' doesn't support UNC names on MS-DOS.
24213
3c29f6165eca (direct-print-region-helper): Check for printer
Geoff Voelker <voelker@cs.washington.edu>
parents: 24092
diff changeset
307 (if (and (stringp printer) (not (string-match "^\\\\" printer)))
24658
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
308 (setq printer
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
309 (subst-char-in-string ?/ ?\\ (expand-file-name printer safe-dir))))
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
310 ;; Handle known programs specially where necessary.
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
311 (unwind-protect
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
312 (cond
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
313 ;; 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
314 ((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
315 (write-region start end tempfile nil 0)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
316 (call-process lpr-prog nil errbuf nil
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
317 tempfile (concat "P=" printer)))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
318 ;; 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
319 ((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
320 ;; 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
321 ;; 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
322 (or (and (eq system-type 'windows-nt)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
323 (null (getenv "winbootdir")))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
324 (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
325 ;; 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
326 ;; 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
327 (if (and (> end start)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
328 (char-equal (char-before end) ?\C-l))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
329 (setq end (1- end)))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
330 ;; 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
331 (let ((write-region-annotate-functions nil))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
332 (write-region start end tempfile nil 0))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
333 (call-process lpr-prog nil errbuf nil
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
334 (concat "/D:" printer) tempfile))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
335 ;; 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
336 ;; 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
337 ;; can't read from stdin.
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
338 ((> (length lpr-prog) 0)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
339 (write-region start end tempfile nil 0)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
340 (setq rest (append rest (list tempfile)))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
341 (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
342 ;; 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
343 ;; 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
344 ;; 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
345 ;; programs from accessing LPT ports reliably.
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
346 ((and (eq system-type 'windows-nt)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
347 (getenv "winbootdir")
24658
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
348 ;; Allow cop-out so command.com isn't invoked
7de5cc79a8b4 (file-name-buffer-file-type-alist): Remove various
Andrew Innes <andrewi@gnu.org>
parents: 24515
diff changeset
349 direct-print-region-use-command-dot-com
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
350 ;; 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
351 ;; 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
352 (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
353 (write-region start end tempfile nil 0)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
354 (let ((w32-quote-process-args nil))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
355 (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
356 (format "copy /b %s %s" tempfile printer))))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
357 ;; write directly to the printer port
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
358 (t
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
359 (write-region start end printer t 0)))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
360 ;; ensure we remove the tempfile if created
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
361 (if (file-exists-p tempfile)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
362 (delete-file tempfile)))))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
363
22678
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
364 (defvar printer-name)
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
365
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
366 (defun direct-print-region-function (start end
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
367 &optional lpr-prog
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
368 delete-text buf display
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
369 &rest rest)
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
370 "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
371 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
372 `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
373 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
374
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
375 ;; 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
376 ;; 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
377 (let* ((coding coding-system-for-write)
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
378 (coding-base
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
379 (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
380 (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
381 ;; 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
382 ;; 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
383 (write-region-annotate-functions
4052a2875390 (direct-print-region-function): Try to ensure that
Geoff Voelker <voelker@cs.washington.edu>
parents: 23682
diff changeset
384 (cons
4052a2875390 (direct-print-region-function): Try to ensure that
Geoff Voelker <voelker@cs.washington.edu>
parents: 23682
diff changeset
385 (lambda (start end)
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
386 (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
387 `((,end . "\f"))))
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
388 write-region-annotate-functions))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
389 (printer (or (and (boundp 'dos-printer)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
390 (stringp (symbol-value 'dos-printer))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
391 (symbol-value 'dos-printer))
53740
19655fe347ec Added support for the `default-printer-name' function.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
392 printer-name
19655fe347ec Added support for the `default-printer-name' function.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
393 (default-printer-name))))
22678
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
394 (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
395 (setq coding-system-for-write
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
396 (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
397 (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
398 delete-text buf display rest)))
22678
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
399
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
400 (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
401
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
402 ;; 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
403 ;; (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
404 ;; 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
405 ;; 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
406 ;; `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
407 ;; 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
408 ;; 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
409 ;; 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
410 (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
411
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
412 (defvar ps-printer-name)
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
413
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
414 (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
415 &optional lpr-prog
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
416 delete-text buf display
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
417 &rest rest)
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
418 "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
419 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
420 `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
421 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
422
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
423 (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
424 (stringp (symbol-value 'dos-ps-printer))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
425 (symbol-value 'dos-ps-printer))
53740
19655fe347ec Added support for the `default-printer-name' function.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
426 ps-printer-name
19655fe347ec Added support for the `default-printer-name' function.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
427 (default-printer-name))))
24092
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
428 (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
429 delete-text buf display rest)))
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
430
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
431 (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
432
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
433 ;(setq ps-lpr-command "gs")
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
434
d98712ec1252 (find-buffer-file-type-coding-system): Use
Andrew Innes <andrewi@gnu.org>
parents: 23802
diff changeset
435 ;(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
436 ; "-sOutputFile=LPT1"))
22678
e3fe83134880 (direct-print-region-function): Renamed from
Richard M. Stallman <rms@gnu.org>
parents: 22607
diff changeset
437
16591
afb15f49a0c9 Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents: 16234
diff changeset
438 (provide 'dos-w32)
16026
9e883e873c01 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49549
diff changeset
440 ;;; arch-tag: dcfefdd2-362f-4fbc-9141-9634f5f4d6a7
16591
afb15f49a0c9 Use new file name dos-w32.el
Geoff Voelker <voelker@cs.washington.edu>
parents: 16234
diff changeset
441 ;;; dos-w32.el ends here