tm 7.106.
[elisp/apel.git] / emu-x20.el
1 ;;; emu-x20.el --- emu API implementation for XEmacs 20 with mule
2
3 ;; Copyright (C) 1994,1995,1996,1997 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-x20.el,v 7.53 1997/03/12 14:18:27 morioka Exp $
7 ;; Keywords: emulation, compatibility, Mule, XEmacs
8
9 ;; This file is part of XEmacs.
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU XEmacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; This module requires XEmacs 20.1 b6 or later with mule.
29
30 ;;; Code:
31
32 (require 'cyrillic)
33 (require 'emu-xemacs)
34
35
36 ;;; @ coding-system
37 ;;;
38
39 (defconst *noconv* 'no-conversion)
40
41 (defmacro as-binary-process (&rest body)
42   `(let (selective-display      ; Disable ^M to nl translation.
43          (coding-system-for-write 'no-conversion)
44          process-input-coding-system
45          process-output-coding-system)
46      ,@body))
47
48 (defmacro as-binary-input-file (&rest body)
49   `(let ((coding-system-for-read 'no-conversion))
50      ,@body))
51
52 (defmacro as-binary-output-file (&rest body)
53   `(let ((coding-system-for-write 'no-conversion))
54      ,@body))
55
56
57 ;;; @ binary access
58 ;;;
59
60 (defun insert-binary-file-contents-literally
61   (filename &optional visit beg end replace)
62   "Like `insert-file-contents-literally', q.v., but don't code conversion.
63 A buffer may be modified in several ways after reading into the buffer due
64 to advanced Emacs features, such as file-name-handlers, format decoding,
65 find-file-hooks, etc.
66   This function ensures that none of these modifications will take place."
67   (let ((coding-system-for-read 'no-conversion))
68     (insert-file-contents-literally filename visit beg end replace)
69     ))
70
71
72 ;;; @ MIME charset
73 ;;;
74
75 (defvar charsets-mime-charset-alist
76   '(((ascii)                                            . us-ascii)
77     ((ascii latin-iso8859-1)                            . iso-8859-1)
78     ((ascii latin-iso8859-2)                            . iso-8859-2)
79     ((ascii latin-iso8859-3)                            . iso-8859-3)
80     ((ascii latin-iso8859-4)                            . iso-8859-4)
81 ;;; ((ascii cyrillic-iso8859-5)                         . iso-8859-5)
82     ((ascii cyrillic-iso8859-5)                         . koi8-r)
83     ((ascii arabic-iso8859-6)                           . iso-8859-6)
84     ((ascii greek-iso8859-7)                            . iso-8859-7)
85     ((ascii hebrew-iso8859-8)                           . iso-8859-8)
86     ((ascii latin-iso8859-9)                            . iso-8859-9)
87     ((ascii latin-jisx0201
88             japanese-jisx0208-1978 japanese-jisx0208)   . iso-2022-jp)
89     ((ascii korean-ksc5601)                             . euc-kr)
90     ((ascii chinese-gb2312)                             . cn-gb-2312)
91     ((ascii chinese-big5-1 chinese-big5-2)              . cn-big5)
92     ((ascii latin-iso8859-1 greek-iso8859-7
93             latin-jisx0201 japanese-jisx0208-1978
94             chinese-gb2312 japanese-jisx0208
95             korean-ksc5601 japanese-jisx0212)           . iso-2022-jp-2)
96     ((ascii latin-iso8859-1 greek-iso8859-7
97             latin-jisx0201 japanese-jisx0208-1978
98             chinese-gb2312 japanese-jisx0208
99             korean-ksc5601 japanese-jisx0212
100             chinese-cns11643-1 chinese-cns11643-2)      . iso-2022-int-1)
101     ((ascii latin-iso8859-1 latin-iso8859-2
102             cyrillic-iso8859-5 greek-iso8859-7
103             latin-jisx0201 japanese-jisx0208-1978
104             chinese-gb2312 japanese-jisx0208
105             korean-ksc5601 japanese-jisx0212
106             chinese-cns11643-1 chinese-cns11643-2
107             chinese-cns11643-3 chinese-cns11643-4
108             chinese-cns11643-5 chinese-cns11643-6
109             chinese-cns11643-7)                         . iso-2022-int-1)
110     ))
111
112 (defvar default-mime-charset 'x-ctext)
113
114 (defvar mime-charset-coding-system-alist
115   '((iso-8859-1         . ctext)
116     (x-ctext            . ctext)
117     (hz-gb-2312         . hz)
118     (cn-gb-2312         . euc-china)
119     (gb2312             . euc-china)
120     (cn-big5            . big5)
121     (koi8-r             . koi8)
122     (iso-2022-jp-2      . iso-2022-ss2-7)
123     ))
124
125 (defun mime-charset-to-coding-system (charset)
126   "Return coding-system by MIME charset. [emu-x20.el]"
127   (if (stringp charset)
128       (setq charset (intern (downcase charset)))
129     )
130   (or (cdr (assq charset mime-charset-coding-system-alist))
131       (and (memq charset (coding-system-list)) charset)
132       ))
133
134 (defun detect-mime-charset-region (start end)
135   "Return MIME charset for region between START and END.
136 \[emu-x20.el]"
137   (charsets-to-mime-charset (charsets-in-region start end)))
138
139 (defun encode-mime-charset-region (start end charset)
140   "Encode the text between START and END as MIME CHARSET.
141 \[emu-x20.el]"
142   (let ((cs (mime-charset-to-coding-system charset)))
143     (if cs
144         (encode-coding-region start end cs)
145       )))
146
147 (defun decode-mime-charset-region (start end charset)
148   "Decode the text between START and END as MIME CHARSET.
149 \[emu-x20.el]"
150   (let ((cs (mime-charset-to-coding-system charset)))
151     (if cs
152         (decode-coding-region start end cs)
153       )))
154
155 (defun encode-mime-charset-string (string charset)
156   "Encode the STRING as MIME CHARSET. [emu-x20.el]"
157   (let ((cs (mime-charset-to-coding-system charset)))
158     (if cs
159         (encode-coding-string string cs)
160       string)))
161
162 (defun decode-mime-charset-string (string charset)
163   "Decode the STRING as MIME CHARSET. [emu-x20.el]"
164   (let ((cs (mime-charset-to-coding-system charset)))
165     (if cs
166         (decode-coding-string string cs)
167       string)))
168
169
170 ;;; @ character
171 ;;;
172
173 ;;; @@ Mule emulating aliases
174 ;;;
175 ;;; You should not use them.
176
177 (defalias 'char-leading-char 'char-charset)
178
179 (defun char-category (character)
180   "Return string of category mnemonics for CHAR in TABLE.
181 CHAR can be any multilingual character
182 TABLE defaults to the current buffer's category table.
183 \[emu-x20.el; Mule emulating function]"
184   (mapconcat (lambda (chr)
185                (char-to-string (int-char chr))
186                )
187              (char-category-list character)
188              ""))
189
190
191 ;;; @ string
192 ;;;
193
194 (defun string-to-int-list (str)
195   (mapcar #'char-int str)
196   )
197
198
199 ;;; @ end
200 ;;;
201
202 (provide 'emu-x20)
203
204 ;;; emu-x20.el ends here