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