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 encode-coding-region (start end coding-system)
114 "Encode the text between START and END to CODING-SYSTEM.
115 \[EMACS 20 emulating function]"
116 ;; If `coding-system' is nil, do nothing.
117 (code-convert-region start end *internal* coding-system))
119 (defun decode-coding-region (start end coding-system)
120 "Decode the text between START and END which is encoded in CODING-SYSTEM.
121 \[EMACS 20 emulating function]"
122 ;; If `coding-system' is nil, do nothing.
123 (code-convert-region start end coding-system *internal*))
125 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
126 (defun encode-coding-string (str coding-system)
127 "Encode the STRING to CODING-SYSTEM.
128 \[EMACS 20 emulating function]"
130 (code-convert-string str *internal* coding-system)
131 ;;(code-convert-string str *internal* nil) returns nil instead of str.
134 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
135 (defun decode-coding-string (str coding-system)
136 "Decode the string STR which is encoded in CODING-SYSTEM.
137 \[EMACS 20 emulating function]"
139 (let ((len (length str))
141 (while (and (< 0 len)
144 (substring str 0 len)
145 coding-system *internal*))))
147 (concat ret (substring str len)))
150 (defalias 'detect-coding-region 'code-detect-region)
152 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
155 ;;; @ with code-conversion
158 (defun insert-file-contents-as-coding-system
159 (coding-system filename &optional visit beg end replace)
160 "Like `insert-file-contents', q.v., but CODING-SYSTEM the first arg will
161 be applied to `file-coding-system-for-read'."
162 (let ((file-coding-system-for-read coding-system))
163 (insert-file-contents filename visit beg end replace)))
166 ((and (>= emacs-major-version 19) (>= emacs-minor-version 29))
167 ;; for MULE 2.3 based on Emacs 19.34.
168 (defun write-region-as-coding-system
169 (coding-system start end filename &optional append visit lockname)
170 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
171 applied to `file-coding-system'."
172 (let ((file-coding-system coding-system)
173 jka-compr-compression-info-list jam-zcat-filename-list)
174 (write-region start end filename append visit lockname)))
176 (defun find-file-noselect-as-coding-system
177 (coding-system filename &optional nowarn rawfile)
178 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
179 be applied to `file-coding-system-for-read'."
180 (let ((file-coding-system-for-read coding-system))
181 (find-file-noselect filename nowarn rawfile)))
184 ;; for MULE 2.3 based on Emacs 19.28 or MULE 1.*.
185 (defun write-region-as-coding-system
186 (coding-system start end filename &optional append visit lockname)
187 "Like `write-region', q.v., but CODING-SYSTEM the first arg will be
188 applied to `file-coding-system'."
189 (let ((file-coding-system coding-system)
190 jka-compr-compression-info-list jam-zcat-filename-list)
191 (write-region start end filename append visit)))
193 (defun find-file-noselect-as-coding-system
194 (coding-system filename &optional nowarn rawfile)
195 "Like `find-file-noselect', q.v., but CODING-SYSTEM the first arg will
196 be applied to `file-coding-system-for-read'."
197 (let ((file-coding-system-for-read coding-system))
198 (find-file-noselect filename nowarn)))
201 (defun save-buffer-as-coding-system (coding-system &optional args)
202 "Like `save-buffer', q.v., but CODING-SYSTEM the first arg will be
203 applied to `coding-system-for-write'."
204 (let ((file-coding-system coding-system))
208 ;;; @ without code-conversion
211 (make-coding-system 'binary nil ?= "No conversion")
213 (defmacro as-binary-process (&rest body)
214 (` (let (selective-display ; Disable ^M to nl translation.
217 (default-process-coding-system (cons *noconv* *noconv*))
218 program-coding-system-alist)
221 (defmacro as-binary-input-file (&rest body)
223 (file-coding-system-for-read *noconv*)
227 (defmacro as-binary-output-file (&rest body)
229 (file-coding-system *noconv*)
233 (defalias 'set-process-input-coding-system 'set-process-coding-system)
235 (defun insert-file-contents-as-binary (filename
236 &optional visit beg end replace)
237 "Like `insert-file-contents', q.v., but don't code and format conversion.
238 Like `insert-file-contents-literary', but it allows find-file-hooks,
239 automatic uncompression, etc.
241 Namely this function ensures that only format decoding and character
242 code conversion will not take place."
243 (as-binary-input-file
244 ;; Returns list absolute file name and length of data inserted.
245 (insert-file-contents filename visit beg end replace)))
247 (defun insert-file-contents-as-raw-text (filename
248 &optional visit beg end replace)
249 "Like `insert-file-contents', q.v., but don't code and format conversion.
250 Like `insert-file-contents-literary', but it allows find-file-hooks,
251 automatic uncompression, etc.
252 Like `insert-file-contents-as-binary', but it converts line-break
254 ;; Returns list absolute file name and length of data inserted.
255 (insert-file-contents-as-coding-system 'raw-text
256 filename visit beg end replace))
258 (defalias 'insert-file-contents-as-raw-text-CRLF
259 'insert-file-contents-as-raw-text)
261 (defun write-region-as-binary (start end filename
262 &optional append visit lockname)
263 "Like `write-region', q.v., but don't code conversion."
264 (write-region-as-coding-system 'binary
265 start end filename append visit lockname))
267 (defun write-region-as-raw-text-CRLF (start end filename
268 &optional append visit lockname)
269 "Like `write-region', q.v., but don't code conversion."
270 (write-region-as-coding-system 'raw-text-dos
271 start end filename append visit lockname))
273 (defun find-file-noselect-as-binary (filename &optional nowarn rawfile)
274 "Like `find-file-noselect', q.v., but don't code and format conversion."
275 (find-file-noselect-as-coding-system 'binary filename nowarn rawfile))
277 (defun find-file-noselect-as-raw-text (filename &optional nowarn rawfile)
278 "Like `find-file-noselect', q.v., but it does not code and format
279 conversion except for line-break code."
280 (find-file-noselect-as-coding-system 'raw-text filename nowarn rawfile))
282 (defalias 'find-file-noselect-as-raw-text-CRLF
283 'find-file-noselect-as-raw-text)
285 (defun save-buffer-as-binary (&optional args)
286 "Like `save-buffer', q.v., but don't encode."
287 (let ((file-coding-system 'binary))
290 (defun save-buffer-as-raw-text-CRLF (&optional args)
291 "Like `save-buffer', q.v., but save as network representation."
292 (let ((file-coding-system 'raw-text-dos))
295 (defun open-network-stream-as-binary (name buffer host service)
296 "Like `open-network-stream', q.v., but don't code conversion."
297 (let ((process (open-network-stream name buffer host service)))
298 (set-process-coding-system process *noconv* *noconv*)
307 ;;; pces-om.el ends here