1 ;;; pces-om.el --- pces implementation for Mule 1.* and Mule 2.*
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Katsumi Yamaoka <yamaoka@jpl.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.
31 ;;; @ version specific features
34 (cond ((= emacs-major-version 19)
35 (define-ccl-program poem-ccl-decode-raw-text
42 (read-if (r1 == ?\x0a)
45 (write-read-repeat r0))
50 (write-read-repeat r0)))))
51 ;; This EOF BLOCK won't work out in practice. So the last datum
52 ;; might be lost if it's value is ?\x0d.
56 "Convert line-break code from CRLF to LF.")
58 (define-ccl-program poem-ccl-encode-raw-text
61 (loop (write-read-repeat r0))))
62 "Pass through without any conversions.")
64 (define-ccl-program poem-ccl-encode-raw-text-CRLF
67 (read-if (r0 == ?\x0a)
71 "Convert line-break code from LF to CRLF.")
77 (cons poem-ccl-decode-raw-text poem-ccl-encode-raw-text))
83 (cons poem-ccl-decode-raw-text poem-ccl-encode-raw-text-CRLF))
86 (defun poem-decode-raw-text (from to)
88 (narrow-to-region from to)
89 (goto-char (point-min))
90 (while (re-search-forward "\r$" nil t)
93 (defun poem-encode-raw-text-CRLF (from to)
95 (narrow-to-region from to)
96 (goto-char (point-min))
97 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
98 (replace-match "\\1\r\n")
101 (make-coding-system 'raw-text nil ?= "No conversion")
102 (put 'raw-text 'post-read-conversion 'poem-decode-raw-text)
104 (make-coding-system 'raw-text-dos nil ?= "No conversion")
105 (put 'raw-text-dos 'post-read-conversion 'poem-decode-raw-text)
106 (put 'raw-text-dos 'pre-write-conversion 'poem-encode-raw-text-CRLF)
113 (defun-maybe find-coding-system (obj)
114 "Return OBJ if it is a coding-system."
115 (if (coding-system-p obj)
118 (defun encode-coding-region (start end coding-system)
119 "Encode the text between START and END to CODING-SYSTEM.
120 \[EMACS 20 emulating function]"
121 ;; If `coding-system' is nil, do nothing.
122 (code-convert-region start end *internal* coding-system))
124 (defun decode-coding-region (start end coding-system)
125 "Decode the text between START and END which is encoded in CODING-SYSTEM.
126 \[EMACS 20 emulating function]"
127 ;; If `coding-system' is nil, do nothing.
128 (code-convert-region start end coding-system *internal*))
130 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
131 (defun encode-coding-string (str coding-system)
132 "Encode the STRING to CODING-SYSTEM.
133 \[EMACS 20 emulating function]"
135 (code-convert-string str *internal* coding-system)
136 ;;(code-convert-string str *internal* nil) returns nil instead of str.
139 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
140 (defun decode-coding-string (str coding-system)
141 "Decode the string STR which is encoded in CODING-SYSTEM.
142 \[EMACS 20 emulating function]"
144 (let ((len (length str))
146 (while (and (< 0 len)
149 (substring str 0 len)
150 coding-system *internal*))))
152 (concat ret (substring str len)))
155 (defalias 'detect-coding-region 'code-detect-region)
157 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
160 ;;; @ with code-conversion
164 ((and (>= emacs-major-version 19) (>= emacs-minor-version 23))
165 ;; Mule 2.0 or later.
166 (defun insert-file-contents-as-coding-system
167 (coding-system filename &optional visit beg end replace)
168 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
169 be applied to `file-coding-system-for-read'."
170 (let ((file-coding-system-for-read coding-system))
171 (insert-file-contents filename visit beg end replace))))
173 ;; Mule 1.1 or earlier.
174 (defun insert-file-contents-as-coding-system
175 (coding-system filename &optional visit beg end replace)
176 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
177 be applied to `file-coding-system-for-read'."
178 (let ((file-coding-system-for-read coding-system))
179 (insert-file-contents filename visit)))))
182 ((and (>= emacs-major-version 19) (>= emacs-minor-version 29))
183 ;; for MULE 2.3 based on Emacs 19.34.
184 (defun write-region-as-coding-system
185 (coding-system start end filename &optional append visit lockname)
186 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
187 applied to `file-coding-system'."
188 (let ((file-coding-system coding-system)
189 jka-compr-compression-info-list jam-zcat-filename-list)
190 (write-region start end filename append visit lockname)))
192 (defun find-file-noselect-as-coding-system
193 (coding-system filename &optional nowarn rawfile)
194 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
195 be applied to `file-coding-system-for-read'."
196 (let ((file-coding-system-for-read coding-system))
197 (find-file-noselect filename nowarn rawfile)))
200 ;; for MULE 2.3 based on Emacs 19.28 or MULE 1.*.
201 (defun write-region-as-coding-system
202 (coding-system start end filename &optional append visit lockname)
203 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
204 applied to `file-coding-system'."
205 (let ((file-coding-system coding-system)
206 jka-compr-compression-info-list jam-zcat-filename-list)
207 (write-region start end filename append visit)))
209 (defun find-file-noselect-as-coding-system
210 (coding-system filename &optional nowarn rawfile)
211 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
212 be applied to `file-coding-system-for-read'."
213 (let ((file-coding-system-for-read coding-system))
214 (find-file-noselect filename nowarn)))
217 (defun save-buffer-as-coding-system (coding-system &optional args)
218 "Like `save-buffer', q.v., but CODING-SYSTEM the first arg will be
219 applied to `coding-system-for-write'."
220 (let ((file-coding-system coding-system))
224 ;;; @ without code-conversion
227 (make-coding-system 'binary nil ?= "No conversion")
229 (defmacro as-binary-process (&rest body)
230 (` (let (selective-display ; Disable ^M to nl translation.
233 (default-process-coding-system (cons *noconv* *noconv*))
234 program-coding-system-alist)
237 (defmacro as-binary-input-file (&rest body)
239 (file-coding-system-for-read *noconv*)
243 (defmacro as-binary-output-file (&rest body)
245 (file-coding-system *noconv*)
249 (defalias 'set-process-input-coding-system 'set-process-coding-system)
252 ((and (>= emacs-major-version 19) (>= emacs-minor-version 23))
253 ;; Mule 2.0 or later.
254 (defun insert-file-contents-as-binary (filename
255 &optional visit beg end replace)
256 "Like `insert-file-contents', q.v., but don't code and format conversion.
257 Like `insert-file-contents-literary', but it allows find-file-hooks,
258 automatic uncompression, etc.
260 Namely this function ensures that only format decoding and character
261 code conversion will not take place."
262 (as-binary-input-file
263 ;; Returns list absolute file name and length of data inserted.
264 (insert-file-contents filename visit beg end replace))))
266 ;; Mule 1.1 or earlier.
267 (defun insert-file-contents-as-binary (filename
268 &optional visit beg end replace)
269 "Like `insert-file-contents', q.v., but don't code and format conversion.
270 Like `insert-file-contents-literary', but it allows find-file-hooks,
271 automatic uncompression, etc.
273 Namely this function ensures that only format decoding and character
274 code conversion will not take place."
275 (as-binary-input-file
276 ;; Returns list absolute file name and length of data inserted.
277 (insert-file-contents filename visit)))))
279 (defun insert-file-contents-as-raw-text (filename
280 &optional visit beg end replace)
281 "Like `insert-file-contents', q.v., but don't code and format conversion.
282 Like `insert-file-contents-literary', but it allows find-file-hooks,
283 automatic uncompression, etc.
284 Like `insert-file-contents-as-binary', but it converts line-break
286 ;; Returns list absolute file name and length of data inserted.
287 (insert-file-contents-as-coding-system 'raw-text
288 filename visit beg end replace))
290 (defalias 'insert-file-contents-as-raw-text-CRLF
291 'insert-file-contents-as-raw-text)
293 (defun write-region-as-binary (start end filename
294 &optional append visit lockname)
295 "Like `write-region', q.v., but don't code conversion."
296 (write-region-as-coding-system 'binary
297 start end filename append visit lockname))
299 (defun write-region-as-raw-text-CRLF (start end filename
300 &optional append visit lockname)
301 "Like `write-region', q.v., but don't code conversion."
302 (write-region-as-coding-system 'raw-text-dos
303 start end filename append visit lockname))
305 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
306 "Like `find-file-noselect', q.v., but don't code and format conversion."
307 (find-file-noselect-as-coding-system 'binary filename nowarn rawfile))
309 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
310 "Like `find-file-noselect', q.v., but it does not code and format
311 conversion except for line-break code."
312 (find-file-noselect-as-coding-system 'raw-text filename nowarn rawfile))
314 (defalias 'find-file-noselect-as-raw-text-CRLF
315 'find-file-noselect-as-raw-text)
317 (defun save-buffer-as-binary (&optional args)
318 "Like `save-buffer', q.v., but don't encode."
319 (let ((file-coding-system 'binary))
322 (defun save-buffer-as-raw-text-CRLF (&optional args)
323 "Like `save-buffer', q.v., but save as network representation."
324 (let ((file-coding-system 'raw-text-dos))
327 (defun open-network-stream-as-binary (name buffer host service)
328 "Like `open-network-stream', q.v., but don't code conversion."
329 (let ((process (open-network-stream name buffer host service)))
330 (set-process-coding-system process *noconv* *noconv*)
338 (product-provide (provide 'pces-om) (require 'apel-ver))
340 ;;; pces-om.el ends here