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