(insert-binary-file-contents): New function.
[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-binary-file-contents-literally
163   (filename &optional visit beg end replace)
164   "Like `insert-file-contents-literally', q.v., but don't code conversion.
165 A buffer may be modified in several ways after reading into the buffer due
166 to advanced Emacs features, such as file-name-handlers, format decoding,
167 find-file-hooks, etc.
168   This function ensures that none of these modifications will take place."
169   (let ((emx-binary-mode t))
170     (insert-file-contents-literally filename visit beg end replace)
171     ))
172
173 (defun insert-binary-file-contents
174   (filename &optional visit beg end replace)
175   "Like `insert-file-contents', q.v., but don't code and format conversion."
176   (let ((emx-binary-mode t))
177     (insert-file-contents filename visit beg end replace)
178     ))
179
180
181
182 ;;; @ MIME charset
183 ;;;
184
185 (defvar charsets-mime-charset-alist
186   (list (cons (list charset-ascii) 'us-ascii)))
187
188 (defvar default-mime-charset 'iso-8859-1)
189
190 (defun mime-charset-to-coding-system (charset)
191   (if (stringp charset)
192       (setq charset (intern (downcase charset)))
193     )
194   (and (memq charset (list 'us-ascii default-mime-charset))
195        charset)
196   )
197
198 (defun detect-mime-charset-region (start end)
199   "Return MIME charset for region between START and END.
200 \[emu-e19.el]"
201   (if (save-excursion
202         (save-restriction
203           (narrow-to-region start end)
204           (goto-char start)
205           (re-search-forward "[\200-\377]" nil t)
206           ))
207       default-mime-charset
208     'us-ascii))
209
210 (defun encode-mime-charset-region (start end charset)
211   "Encode the text between START and END as MIME CHARSET.
212 \[emu-e19.el]"
213   )
214
215 (defun decode-mime-charset-region (start end charset)
216   "Decode the text between START and END as MIME CHARSET.
217 \[emu-e19.el]"
218   )
219
220 (defun encode-mime-charset-string (string charset)
221   "Encode the STRING as MIME CHARSET. [emu-e19.el]"
222   string)
223
224 (defun decode-mime-charset-string (string charset)
225   "Decode the STRING as MIME CHARSET. [emu-e19.el]"
226   string)
227
228
229 ;;; @ character
230 ;;;
231
232 (defun char-charset (chr)
233   "Return the character set of char CHR.
234 \[emu-e19.el; XEmacs 20 emulating function]"
235   (if (< chr 128)
236       charset-ascii
237     charset-latin-iso8859-1))
238
239 (defun char-bytes (char)
240   "Return number of bytes a character in CHAR occupies in a buffer.
241 \[emu-e19.el; MULE emulating function]"
242   1)
243
244 (defalias 'char-length 'char-bytes)
245
246 (defun char-columns (character)
247   "Return number of columns a CHARACTER occupies when displayed.
248 \[emu-e19.el]"
249   1)
250
251 ;;; @@ for old MULE emulation
252 ;;;
253
254 (defalias 'char-width 'char-columns)
255
256 (defalias 'char-leading-char 'char-charset)
257
258
259 ;;; @ string
260 ;;;
261
262 (defalias 'string-columns 'length)
263
264 (defun string-to-char-list (str)
265   (mapcar (function identity) str)
266   )
267
268 (defalias 'string-to-int-list 'string-to-char-list)
269
270 (defalias 'sref 'aref)
271
272 (defun truncate-string (str width &optional start-column)
273   "Truncate STR to fit in WIDTH columns.
274 Optional non-nil arg START-COLUMN specifies the starting column.
275 \[emu-e19.el; MULE 2.3 emulating function]"
276   (or start-column
277       (setq start-column 0))
278   (substring str start-column width)
279   )
280
281 ;;; @@ for old MULE emulation
282 ;;;
283
284 (defalias 'string-width 'length)
285
286
287 ;;; @ end
288 ;;;
289
290 (provide 'emu-e19)
291
292 ;;; emu-e19.el ends here