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
163 (defun insert-file-contents-as-coding-system
164 (coding-system filename &optional visit beg end replace)
165 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
166 be applied to `file-coding-system-for-read'."
167 (let ((file-coding-system-for-read coding-system))
168 (insert-file-contents filename visit beg end replace)))
171 ((and (>= emacs-major-version 19) (>= emacs-minor-version 29))
172 ;; for MULE 2.3 based on Emacs 19.34.
173 (defun write-region-as-coding-system
174 (coding-system start end filename &optional append visit lockname)
175 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
176 applied to `file-coding-system'."
177 (let ((file-coding-system coding-system)
178 jka-compr-compression-info-list jam-zcat-filename-list)
179 (write-region start end filename append visit lockname)))
181 (defun find-file-noselect-as-coding-system
182 (coding-system filename &optional nowarn rawfile)
183 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
184 be applied to `file-coding-system-for-read'."
185 (let ((file-coding-system-for-read coding-system))
186 (find-file-noselect filename nowarn rawfile)))
189 ;; for MULE 2.3 based on Emacs 19.28 or MULE 1.*.
190 (defun write-region-as-coding-system
191 (coding-system start end filename &optional append visit lockname)
192 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
193 applied to `file-coding-system'."
194 (let ((file-coding-system coding-system)
195 jka-compr-compression-info-list jam-zcat-filename-list)
196 (write-region start end filename append visit)))
198 (defun find-file-noselect-as-coding-system
199 (coding-system filename &optional nowarn rawfile)
200 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
201 be applied to `file-coding-system-for-read'."
202 (let ((file-coding-system-for-read coding-system))
203 (find-file-noselect filename nowarn)))
206 (defun save-buffer-as-coding-system (coding-system &optional args)
207 "Like `save-buffer', q.v., but CODING-SYSTEM the first arg will be
208 applied to `coding-system-for-write'."
209 (let ((file-coding-system coding-system))
213 ;;; @ without code-conversion
216 (make-coding-system 'binary nil ?= "No conversion")
218 (defmacro as-binary-process (&rest body)
219 (` (let (selective-display ; Disable ^M to nl translation.
222 (default-process-coding-system (cons *noconv* *noconv*))
223 program-coding-system-alist)
226 (defmacro as-binary-input-file (&rest body)
228 (file-coding-system-for-read *noconv*)
232 (defmacro as-binary-output-file (&rest body)
234 (file-coding-system *noconv*)
238 (defalias 'set-process-input-coding-system 'set-process-coding-system)
240 (defun insert-file-contents-as-binary (filename
241 &optional visit beg end replace)
242 "Like `insert-file-contents', q.v., but don't code and format conversion.
243 Like `insert-file-contents-literary', but it allows find-file-hooks,
244 automatic uncompression, etc.
246 Namely this function ensures that only format decoding and character
247 code conversion will not take place."
248 (as-binary-input-file
249 ;; Returns list absolute file name and length of data inserted.
250 (insert-file-contents filename visit beg end replace)))
252 (defun insert-file-contents-as-raw-text (filename
253 &optional visit beg end replace)
254 "Like `insert-file-contents', q.v., but don't code and format conversion.
255 Like `insert-file-contents-literary', but it allows find-file-hooks,
256 automatic uncompression, etc.
257 Like `insert-file-contents-as-binary', but it converts line-break
259 ;; Returns list absolute file name and length of data inserted.
260 (insert-file-contents-as-coding-system 'raw-text
261 filename visit beg end replace))
263 (defalias 'insert-file-contents-as-raw-text-CRLF
264 'insert-file-contents-as-raw-text)
266 (defun write-region-as-binary (start end filename
267 &optional append visit lockname)
268 "Like `write-region', q.v., but don't code conversion."
269 (write-region-as-coding-system 'binary
270 start end filename append visit lockname))
272 (defun write-region-as-raw-text-CRLF (start end filename
273 &optional append visit lockname)
274 "Like `write-region', q.v., but don't code conversion."
275 (write-region-as-coding-system 'raw-text-dos
276 start end filename append visit lockname))
278 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
279 "Like `find-file-noselect', q.v., but don't code and format conversion."
280 (find-file-noselect-as-coding-system 'binary filename nowarn rawfile))
282 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
283 "Like `find-file-noselect', q.v., but it does not code and format
284 conversion except for line-break code."
285 (find-file-noselect-as-coding-system 'raw-text filename nowarn rawfile))
287 (defalias 'find-file-noselect-as-raw-text-CRLF
288 'find-file-noselect-as-raw-text)
290 (defun save-buffer-as-binary (&optional args)
291 "Like `save-buffer', q.v., but don't encode."
292 (let ((file-coding-system 'binary))
295 (defun save-buffer-as-raw-text-CRLF (&optional args)
296 "Like `save-buffer', q.v., but save as network representation."
297 (let ((file-coding-system 'raw-text-dos))
300 (defun open-network-stream-as-binary (name buffer host service)
301 "Like `open-network-stream', q.v., but don't code conversion."
302 (let ((process (open-network-stream name buffer host service)))
303 (set-process-coding-system process *noconv* *noconv*)
311 (product-provide (provide 'pces-om) (require 'apel-ver))
313 ;;; pces-om.el ends here