(insert-file-contents-as-binary): Renamed from
[elisp/apel.git] / emu-e19.el
1 ;;; emu-e19.el --- emu module for Emacs 19 and XEmacs without MULE
2
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, mule, Latin-1
7
8 ;; This file is part of emu.
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 ;;; @ version and variant specific features
28 ;;;
29
30 (cond (running-xemacs
31        (require 'emu-xemacs))
32       (running-emacs-19
33        (require 'emu-19)
34        ))
35
36
37 ;;; @ character set
38 ;;;
39
40 (defconst charset-ascii 0 "Character set of ASCII")
41 (defconst charset-latin-iso8859-1 129 "Character set of ISO-8859-1")
42
43 (defun charset-description (charset)
44   "Return description of CHARSET. [emu-e19.el]"
45   (if (< charset 128)
46       (documentation-property 'charset-ascii 'variable-documentation)
47     (documentation-property 'charset-latin-iso8859-1 'variable-documentation)
48     ))
49
50 (defun charset-registry (charset)
51   "Return registry name of CHARSET. [emu-e19.el]"
52   (if (< charset 128)
53       "ASCII"
54     "ISO8859-1"))
55
56 (defun charset-columns (charset)
57   "Return number of columns a CHARSET occupies when displayed.
58 \[emu-e19.el]"
59   1)
60
61 (defun charset-direction (charset)
62   "Return the direction of a character of CHARSET by
63   0 (left-to-right) or 1 (right-to-left). [emu-e19.el]"
64   0)
65
66 (defun find-charset-string (str)
67   "Return a list of charsets in the string.
68 \[emu-e19.el; Mule emulating function]"
69   (if (string-match "[\200-\377]" str)
70       (list charset-latin-iso8859-1)
71     ))
72
73 (defalias 'find-non-ascii-charset-string 'find-charset-string)
74
75 (defun find-charset-region (start end)
76   "Return a list of charsets in the region between START and END.
77 \[emu-e19.el; Mule emulating function]"
78   (if (save-excursion
79         (save-restriction
80           (narrow-to-region start end)
81           (goto-char start)
82           (re-search-forward "[\200-\377]" nil t)
83           ))
84       (list charset-latin-iso8859-1)
85     ))
86
87 (defalias 'find-non-ascii-charset-region 'find-charset-region)
88
89
90 ;;; @ coding-system
91 ;;;
92
93 (defconst *internal* nil)
94 (defconst *ctext* nil)
95 (defconst *noconv* nil)
96
97 (defun decode-coding-string (string coding-system)
98   "Decode the STRING which is encoded in CODING-SYSTEM.
99 \[emu-e19.el; Emacs 20 emulating function]"
100   string)
101
102 (defun encode-coding-string (string coding-system)
103   "Encode the STRING as CODING-SYSTEM.
104 \[emu-e19.el; Emacs 20 emulating function]"
105   string)
106
107 (defun decode-coding-region (start end coding-system)
108   "Decode the text between START and END which is encoded in CODING-SYSTEM.
109 \[emu-e19.el; Emacs 20 emulating function]"
110   0)
111
112 (defun encode-coding-region (start end coding-system)
113   "Encode the text between START and END to CODING-SYSTEM.
114 \[emu-e19.el; Emacs 20 emulating function]"
115   0)
116
117 (defun detect-coding-region (start end)
118   "Detect coding-system of the text in the region between START and END.
119 \[emu-e19.el; Emacs 20 emulating function]"
120   )
121
122 (defun set-buffer-file-coding-system (coding-system &optional force)
123   "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM.
124 \[emu-e19.el; Emacs 20 emulating function]"
125   )
126
127 (defmacro as-binary-process (&rest body)
128   (` (let (selective-display)   ; Disable ^M to nl translation.
129        (,@ body)
130        )))
131
132 (defmacro as-binary-input-file (&rest body)
133   (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
134        (,@ body)
135        )))
136
137 (defmacro as-binary-output-file (&rest body)
138   (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
139        (,@ body)
140        )))
141
142
143 ;;; @@ for old MULE emulation
144 ;;;
145
146 (defun code-convert-string (str ic oc)
147   "Convert code in STRING from SOURCE code to TARGET code,
148 On successful converion, returns the result string,
149 else returns nil. [emu-e19.el; old MULE emulating function]"
150   str)
151
152 (defun code-convert-region (beg end ic oc)
153   "Convert code of the text between BEGIN and END from SOURCE
154 to TARGET. On successful conversion returns t,
155 else returns nil. [emu-e19.el; old MULE emulating function]"
156   t)
157
158
159 ;;; @ binary access
160 ;;;
161
162 (defun insert-file-contents-as-binary (filename
163                                        &optional visit beg end replace)
164   "Like `insert-file-contents', q.v., but don't code and format conversion.
165 Like `insert-file-contents-literary', but it allows find-file-hooks,
166 automatic uncompression, etc.
167
168 Namely this function ensures that only format decoding and character
169 code conversion will not take place."
170   (let ((emx-binary-mode t))
171     (insert-file-contents filename visit beg end replace)
172     ))
173
174 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
175 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
176
177 (defun insert-binary-file-contents-literally (filename
178                                               &optional visit beg end replace)
179   "Like `insert-file-contents-literally', q.v., but don't code conversion.
180 A buffer may be modified in several ways after reading into the buffer due
181 to advanced Emacs features, such as file-name-handlers, format decoding,
182 find-file-hooks, etc.
183   This function ensures that none of these modifications will take place."
184   (let ((emx-binary-mode t))
185     (insert-file-contents-literally filename visit beg end replace)
186     ))
187
188 (defun write-region-as-binary (start end filename
189                                      &optional append visit lockname)
190   "Like `write-region', q.v., but don't code conversion."
191   (let ((emx-binary-mode t))
192     (write-region start end filename append visit lockname)
193     ))
194
195
196 ;;; @ MIME charset
197 ;;;
198
199 (defvar charsets-mime-charset-alist
200   (list (cons (list charset-ascii) 'us-ascii)))
201
202 (defvar default-mime-charset 'iso-8859-1)
203
204 (defun mime-charset-to-coding-system (charset)
205   (if (stringp charset)
206       (setq charset (intern (downcase charset)))
207     )
208   (and (memq charset (list 'us-ascii default-mime-charset))
209        charset)
210   )
211
212 (defun detect-mime-charset-region (start end)
213   "Return MIME charset for region between START and END.
214 \[emu-e19.el]"
215   (if (save-excursion
216         (save-restriction
217           (narrow-to-region start end)
218           (goto-char start)
219           (re-search-forward "[\200-\377]" nil t)
220           ))
221       default-mime-charset
222     'us-ascii))
223
224 (defun encode-mime-charset-region (start end charset)
225   "Encode the text between START and END as MIME CHARSET.
226 \[emu-e19.el]"
227   )
228
229 (defun decode-mime-charset-region (start end charset)
230   "Decode the text between START and END as MIME CHARSET.
231 \[emu-e19.el]"
232   )
233
234 (defun encode-mime-charset-string (string charset)
235   "Encode the STRING as MIME CHARSET. [emu-e19.el]"
236   string)
237
238 (defun decode-mime-charset-string (string charset)
239   "Decode the STRING as MIME CHARSET. [emu-e19.el]"
240   string)
241
242
243 ;;; @ character
244 ;;;
245
246 (defun char-charset (chr)
247   "Return the character set of char CHR.
248 \[emu-e19.el; XEmacs 20 emulating function]"
249   (if (< chr 128)
250       charset-ascii
251     charset-latin-iso8859-1))
252
253 (defun char-bytes (char)
254   "Return number of bytes a character in CHAR occupies in a buffer.
255 \[emu-e19.el; MULE emulating function]"
256   1)
257
258 (defalias 'char-length 'char-bytes)
259
260 (defun char-columns (character)
261   "Return number of columns a CHARACTER occupies when displayed.
262 \[emu-e19.el]"
263   1)
264
265 ;;; @@ for old MULE emulation
266 ;;;
267
268 (defalias 'char-width 'char-columns)
269
270 (defalias 'char-leading-char 'char-charset)
271
272
273 ;;; @ string
274 ;;;
275
276 (defalias 'string-columns 'length)
277
278 (defun string-to-char-list (str)
279   (mapcar (function identity) str)
280   )
281
282 (defalias 'string-to-int-list 'string-to-char-list)
283
284 (defalias 'sref 'aref)
285
286 (defun truncate-string (str width &optional start-column)
287   "Truncate STR to fit in WIDTH columns.
288 Optional non-nil arg START-COLUMN specifies the starting column.
289 \[emu-e19.el; MULE 2.3 emulating function]"
290   (or start-column
291       (setq start-column 0))
292   (substring str start-column width)
293   )
294
295 ;;; @@ for old MULE emulation
296 ;;;
297
298 (defalias 'string-width 'length)
299
300
301 ;;; @ end
302 ;;;
303
304 (provide 'emu-e19)
305
306 ;;; emu-e19.el ends here