1 ;;; -*-byte-compile-dynamic: t;-*-
2 ;;; pces-20.el --- pces submodule for Emacs 20 and XEmacs with coding-system
4 ;; Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
6 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
7 ;; Keywords: emulation, compatibility, Mule
9 ;; This file is part of APEL (A Portable Emacs Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This module requires Emacs 20.0.93, XEmacs 20.3-b5 (with mule)
33 ;; (defun-maybe-cond multibyte-string-p (object)
34 ;; "Return t if OBJECT is a multibyte string."
35 ;; ((featurep 'mule) (stringp object))
39 ;;; @ without code-conversion
42 (defmacro as-binary-process (&rest body)
43 `(let (selective-display ; Disable ^M to nl translation.
44 (coding-system-for-read 'binary)
45 (coding-system-for-write 'binary))
48 (defmacro as-binary-input-file (&rest body)
49 `(let ((coding-system-for-read 'binary))
52 (defmacro as-binary-output-file (&rest body)
53 `(let ((coding-system-for-write 'binary))
56 (defun write-region-as-binary (start end filename
57 &optional append visit lockname)
58 "Like `write-region', q.v., but don't encode."
59 (let ((coding-system-for-write 'binary)
60 jka-compr-compression-info-list jam-zcat-filename-list)
61 (write-region start end filename append visit lockname)))
65 (broken-facility insert-file-contents-literally-treats-binary
66 "Function `insert-file-contents-literally' decodes text."
68 (coding-system-for-write 'binary)
69 (coding-system-for-read 'raw-text-dos)
70 ;; (default-enable-multibyte-characters (multibyte-string-p str))
74 (write-region (point-min)(point-max) "literal-test-file")
78 (let (file-name-handler-alist)
79 (insert-file-contents-literally "literal-test-file")
85 (broken-facility insert-file-contents-literally-treats-file-name-handler
86 "Function `insert-file-contents' doesn't call file-name-handler."
89 (let ((file-name-handler-alist
90 '(("literal-test-file" . (lambda (operation &rest args)
92 (let (file-name-handler-alist)
93 (apply operation args)
95 (insert-file-contents-literally "literal-test-file")
97 (delete-file "literal-test-file")
102 (or (broken-p 'insert-file-contents-literally-treats-binary)
103 (broken-p 'insert-file-contents-literally-treats-file-name-handler))
104 (defun insert-file-contents-as-binary (filename
105 &optional visit beg end replace)
106 "Like `insert-file-contents', but only reads in the file literally.
107 A buffer may be modified in several ways after reading into the buffer,
108 to Emacs features such as format decoding, character code
109 conversion, find-file-hooks, automatic uncompression, etc.
111 This function ensures that none of these modifications will take place."
112 (let ((format-alist nil)
113 (after-insert-file-functions nil)
114 (coding-system-for-read 'binary)
115 (coding-system-for-write 'binary)
116 (jka-compr-compression-info-list nil)
117 (jam-zcat-filename-list nil)
118 (find-buffer-file-type-function
119 (if (fboundp 'find-buffer-file-type)
120 (symbol-function 'find-buffer-file-type)
124 (fset 'find-buffer-file-type (lambda (filename) t))
125 (insert-file-contents filename visit beg end replace))
126 (if find-buffer-file-type-function
127 (fset 'find-buffer-file-type find-buffer-file-type-function)
128 (fmakunbound 'find-buffer-file-type)))))
129 (defalias 'insert-file-contents-as-binary 'insert-file-contents-literally)
132 (defun insert-file-contents-as-raw-text (filename
133 &optional visit beg end replace)
134 "Like `insert-file-contents', q.v., but don't code and format conversion.
135 Like `insert-file-contents-literary', but it allows find-file-hooks,
136 automatic uncompression, etc.
137 Like `insert-file-contents-as-binary', but it converts line-break
139 (let ((coding-system-for-read 'raw-text)
141 ;; Returns list of absolute file name and length of data inserted.
142 (insert-file-contents filename visit beg end replace)))
144 (defun insert-file-contents-as-raw-text-CRLF (filename
145 &optional visit beg end replace)
146 "Like `insert-file-contents', q.v., but don't code and format conversion.
147 Like `insert-file-contents-literary', but it allows find-file-hooks,
148 automatic uncompression, etc.
149 Like `insert-file-contents-as-binary', but it converts line-break code
151 (let ((coding-system-for-read 'raw-text-dos)
153 ;; Returns list of absolute file name and length of data inserted.
154 (insert-file-contents filename visit beg end replace)))
156 (defun write-region-as-raw-text-CRLF (start end filename
157 &optional append visit lockname)
158 "Like `write-region', q.v., but write as network representation."
159 (let ((coding-system-for-write 'raw-text-dos))
160 (write-region start end filename append visit lockname)))
162 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
163 "Like `find-file-noselect', q.v., but don't code and format conversion."
164 (let ((coding-system-for-read 'binary)
166 (find-file-noselect filename nowarn rawfile)))
168 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
169 "Like `find-file-noselect', q.v., but it does not code and format conversion
170 except for line-break code."
171 (let ((coding-system-for-read 'raw-text)
173 (find-file-noselect filename nowarn rawfile)))
175 (defun find-file-noselect-as-raw-text-CRLF (filename &optional nowarn rawfile)
176 "Like `find-file-noselect', q.v., but it does not code and format conversion
177 except for line-break code."
178 (let ((coding-system-for-read 'raw-text-dos)
180 (find-file-noselect filename nowarn rawfile)))
182 (defun save-buffer-as-binary (&optional args)
183 "Like `save-buffer', q.v., but don't encode."
184 (let ((coding-system-for-write 'binary))
187 (defun save-buffer-as-raw-text-CRLF (&optional args)
188 "Like `save-buffer', q.v., but save as network representation."
189 (let ((coding-system-for-write 'raw-text-dos))
192 (defun open-network-stream-as-binary (name buffer host service)
193 "Like `open-network-stream', q.v., but don't code conversion."
194 (let ((coding-system-for-read 'binary)
195 (coding-system-for-write 'binary))
196 (open-network-stream name buffer host service)))
199 ;;; @ with code-conversion
202 (defun insert-file-contents-as-coding-system
203 (coding-system filename &optional visit beg end replace)
204 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
205 be applied to `coding-system-for-read'."
206 (let ((coding-system-for-read coding-system)
208 (insert-file-contents filename visit beg end replace)))
210 (defun write-region-as-coding-system
211 (coding-system start end filename &optional append visit lockname)
212 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
213 applied to `coding-system-for-write'."
214 (let ((coding-system-for-write coding-system)
215 jka-compr-compression-info-list jam-zcat-filename-list)
216 (write-region start end filename append visit lockname)))
218 (defun find-file-noselect-as-coding-system
219 (coding-system filename &optional nowarn rawfile)
220 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
221 be applied to `coding-system-for-read'."
222 (let ((coding-system-for-read coding-system)
224 (find-file-noselect filename nowarn rawfile)))
226 (defun save-buffer-as-coding-system (coding-system &optional args)
227 "Like `save-buffer', q.v., but CODING-SYSTEM the first arg will be
228 applied to `coding-system-for-write'."
229 (let ((coding-system-for-write coding-system))
237 (product-provide (provide 'pces-20) (require 'apel-ver))
239 ;;; pces-20.el ends here