This commit was manufactured by cvs2svn to create branch 'emu-unify'.
[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 (put 'ascii 'charset-description "Character set of ASCII")
41 (put 'ascii 'charset-registry "ASCII")
42
43 (put 'latin-iso8859-1 'charset-description "Character set of ISO-8859-1")
44 (put 'latin-iso8859-1 'charset-registry "ISO8859-1")
45
46 (defun charset-description (charset)
47   "Return description of CHARSET."
48   (get charset 'charset-description)
49   )
50
51 (defun charset-registry (charset)
52   "Return registry name of CHARSET."
53   (get charset 'charset-registry)
54   )
55
56 (defun charset-width (charset)
57   "Return number of columns a CHARSET occupies when displayed."
58   1)
59
60 (defun charset-direction (charset)
61   "Return the direction of a character of CHARSET by
62   0 (left-to-right) or 1 (right-to-left)."
63   0)
64
65 (defun find-charset-string (str)
66   "Return a list of charsets in the string."
67   (if (string-match "[\200-\377]" str)
68       '(latin-iso8859-1)
69     ))
70
71 (defalias 'find-non-ascii-charset-string 'find-charset-string)
72
73 (defun find-charset-region (start end)
74   "Return a list of charsets in the region between START and END.
75 \[emu-e19.el; Mule emulating function]"
76   (if (save-excursion
77         (goto-char start)
78         (re-search-forward "[\200-\377]" end t)
79         )
80       '(latin-iso8859-1)
81     ))
82
83 (defalias 'find-non-ascii-charset-region 'find-charset-region)
84
85
86 ;;; @ coding-system
87 ;;;
88
89 (defconst *internal* nil)
90 (defconst *ctext* nil)
91 (defconst *noconv* nil)
92
93 (defun decode-coding-string (string coding-system)
94   "Decode the STRING which is encoded in CODING-SYSTEM.
95 \[emu-e19.el; Emacs 20 emulating function]"
96   string)
97
98 (defun encode-coding-string (string coding-system)
99   "Encode the STRING as CODING-SYSTEM.
100 \[emu-e19.el; Emacs 20 emulating function]"
101   string)
102
103 (defun decode-coding-region (start end coding-system)
104   "Decode the text between START and END which is encoded in CODING-SYSTEM.
105 \[emu-e19.el; Emacs 20 emulating function]"
106   0)
107
108 (defun encode-coding-region (start end coding-system)
109   "Encode the text between START and END to CODING-SYSTEM.
110 \[emu-e19.el; Emacs 20 emulating function]"
111   0)
112
113 (defun detect-coding-region (start end)
114   "Detect coding-system of the text in the region between START and END.
115 \[emu-e19.el; Emacs 20 emulating function]"
116   )
117
118 (defun set-buffer-file-coding-system (coding-system &optional force)
119   "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM.
120 \[emu-e19.el; Emacs 20 emulating function]"
121   )
122
123 (defmacro as-binary-process (&rest body)
124   (` (let (selective-display)   ; Disable ^M to nl translation.
125        (,@ body)
126        )))
127
128 (defmacro as-binary-input-file (&rest body)
129   (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
130        (,@ body)
131        )))
132
133 (defmacro as-binary-output-file (&rest body)
134   (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
135        (,@ body)
136        )))
137
138
139 ;;; @@ for old MULE emulation
140 ;;;
141
142 (defun code-convert-string (str ic oc)
143   "Convert code in STRING from SOURCE code to TARGET code,
144 On successful converion, returns the result string,
145 else returns nil. [emu-e19.el; old MULE emulating function]"
146   str)
147
148 (defun code-convert-region (beg end ic oc)
149   "Convert code of the text between BEGIN and END from SOURCE
150 to TARGET. On successful conversion returns t,
151 else returns nil. [emu-e19.el; old MULE emulating function]"
152   t)
153
154
155 ;;; @ binary access
156 ;;;
157
158 (defun insert-file-contents-as-binary (filename
159                                        &optional visit beg end replace)
160   "Like `insert-file-contents', q.v., but don't code and format conversion.
161 Like `insert-file-contents-literary', but it allows find-file-hooks,
162 automatic uncompression, etc.
163
164 Namely this function ensures that only format decoding and character
165 code conversion will not take place."
166   (let ((emx-binary-mode t))
167     (insert-file-contents filename visit beg end replace)
168     ))
169
170 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
171 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
172
173 (defun insert-binary-file-contents-literally (filename
174                                               &optional visit beg end replace)
175   "Like `insert-file-contents-literally', q.v., but don't code conversion.
176 A buffer may be modified in several ways after reading into the buffer due
177 to advanced Emacs features, such as file-name-handlers, format decoding,
178 find-file-hooks, etc.
179   This function ensures that none of these modifications will take place."
180   (let ((emx-binary-mode t))
181     (insert-file-contents-literally filename visit beg end replace)
182     ))
183
184 (defun write-region-as-binary (start end filename
185                                      &optional append visit lockname)
186   "Like `write-region', q.v., but don't code conversion."
187   (let ((emx-binary-mode t))
188     (write-region start end filename append visit lockname)
189     ))
190
191
192 ;;; @ MIME charset
193 ;;;
194
195 (defvar charsets-mime-charset-alist
196   '(((ascii) . us-ascii)))
197
198 (defvar default-mime-charset 'iso-8859-1)
199
200 (defun mime-charset-to-coding-system (charset)
201   (if (stringp charset)
202       (setq charset (intern (downcase charset)))
203     )
204   (and (memq charset (list 'us-ascii default-mime-charset))
205        charset)
206   )
207
208 (defun detect-mime-charset-region (start end)
209   "Return MIME charset for region between START and END."
210   (if (save-excursion
211         (goto-char start)
212         (re-search-forward "[\200-\377]" end t)
213         )
214       default-mime-charset
215     'us-ascii))
216
217 (defun encode-mime-charset-region (start end charset)
218   "Encode the text between START and END as MIME CHARSET."
219   )
220
221 (defun decode-mime-charset-region (start end charset)
222   "Decode the text between START and END as MIME CHARSET."
223   )
224
225 (defun encode-mime-charset-string (string charset)
226   "Encode the STRING as MIME CHARSET."
227   string)
228
229 (defun decode-mime-charset-string (string charset)
230   "Decode the STRING as MIME CHARSET."
231   string)
232
233
234 ;;; @ character
235 ;;;
236
237 (defun char-charset (char)
238   "Return the character set of char CHAR."
239   (if (< chr 128)
240       'ascii
241     'latin-iso8859-1))
242
243 (defun char-bytes (char)
244   "Return number of bytes a character in CHAR occupies in a buffer."
245   1)
246
247 (defun char-width (char)
248   "Return number of columns a CHAR occupies when displayed."
249   1)
250
251 (defalias 'char-length 'char-bytes)
252
253 (defmacro char-next-index (char index)
254   "Return index of character succeeding CHAR whose index is INDEX."
255   (` (1+ index)))
256
257
258 ;;; @ string
259 ;;;
260
261 (defalias 'string-width 'length)
262
263 (defun string-to-char-list (str)
264   (mapcar (function identity) str)
265   )
266
267 (defalias 'string-to-int-list 'string-to-char-list)
268
269 (defalias 'sref 'aref)
270
271 (defun truncate-string (str width &optional start-column)
272   "Truncate STR to fit in WIDTH columns.
273 Optional non-nil arg START-COLUMN specifies the starting column.
274 \[emu-e19.el; MULE 2.3 emulating function]"
275   (or start-column
276       (setq start-column 0))
277   (substring str start-column width)
278   )
279
280 ;;; @@ obsoleted aliases
281 ;;;
282 ;;; You should not use them.
283
284 (defalias 'string-columns 'length)
285 (make-obsolete 'string-columns 'string-width)
286
287
288 ;;; @ end
289 ;;;
290
291 (provide 'emu-e19)
292
293 ;;; emu-e19.el ends here