tm 7.105.2.
[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.52 1997/03/10 11:47:18 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 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
42
43 (defmacro as-binary-process (&rest body)
44   `(let (selective-display      ; Disable ^M to nl translation.
45          (coding-system-for-write 'no-conversion)
46          process-input-coding-system
47          process-output-coding-system)
48      ,@body))
49
50 (defmacro as-binary-input-file (&rest body)
51   `(let ((coding-system-for-read 'no-conversion))
52      ,@body))
53
54 (defmacro as-binary-output-file (&rest body)
55   `(let ((coding-system-for-write 'no-conversion))
56      ,@body))
57
58
59 ;;; @ binary access
60 ;;;
61
62 (defun insert-binary-file-contents-literally
63   (filename &optional visit beg end replace)
64   "Like `insert-file-contents-literally', q.v., but don't code conversion.
65 A buffer may be modified in several ways after reading into the buffer due
66 to advanced Emacs features, such as file-name-handlers, format decoding,
67 find-file-hooks, etc.
68   This function ensures that none of these modifications will take place."
69   (let ((coding-system-for-read 'no-conversion))
70     (insert-file-contents-literally filename visit beg end replace)
71     ))
72
73
74 ;;; @ MIME charset
75 ;;;
76
77 (defvar charsets-mime-charset-alist
78   '(((ascii)                                            . us-ascii)
79     ((ascii latin-iso8859-1)                            . iso-8859-1)
80     ((ascii latin-iso8859-2)                            . iso-8859-2)
81     ((ascii latin-iso8859-3)                            . iso-8859-3)
82     ((ascii latin-iso8859-4)                            . iso-8859-4)
83 ;;; ((ascii cyrillic-iso8859-5)                         . iso-8859-5)
84     ((ascii cyrillic-iso8859-5)                         . koi8-r)
85     ((ascii arabic-iso8859-6)                           . iso-8859-6)
86     ((ascii greek-iso8859-7)                            . iso-8859-7)
87     ((ascii hebrew-iso8859-8)                           . iso-8859-8)
88     ((ascii latin-iso8859-9)                            . iso-8859-9)
89     ((ascii latin-jisx0201
90             japanese-jisx0208-1978 japanese-jisx0208)   . iso-2022-jp)
91     ((ascii korean-ksc5601)                             . euc-kr)
92     ((ascii chinese-gb2312)                             . cn-gb-2312)
93     ((ascii chinese-big5-1 chinese-big5-2)              . cn-big5)
94     ((ascii latin-iso8859-1 greek-iso8859-7
95             latin-jisx0201 japanese-jisx0208-1978
96             chinese-gb2312 japanese-jisx0208
97             korean-ksc5601 japanese-jisx0212)           . iso-2022-jp-2)
98     ((ascii latin-iso8859-1 greek-iso8859-7
99             latin-jisx0201 japanese-jisx0208-1978
100             chinese-gb2312 japanese-jisx0208
101             korean-ksc5601 japanese-jisx0212
102             chinese-cns11643-1 chinese-cns11643-2)      . iso-2022-int-1)
103     ((ascii latin-iso8859-1 latin-iso8859-2
104             cyrillic-iso8859-5 greek-iso8859-7
105             latin-jisx0201 japanese-jisx0208-1978
106             chinese-gb2312 japanese-jisx0208
107             korean-ksc5601 japanese-jisx0212
108             chinese-cns11643-1 chinese-cns11643-2
109             chinese-cns11643-3 chinese-cns11643-4
110             chinese-cns11643-5 chinese-cns11643-6
111             chinese-cns11643-7)                         . iso-2022-int-1)
112     ))
113
114 (defvar default-mime-charset 'x-ctext)
115
116 (defvar mime-charset-coding-system-alist
117   '((iso-8859-1         . ctext)
118     (x-ctext            . ctext)
119     (hz-gb-2312         . hz)
120     (cn-gb-2312         . euc-china)
121     (gb2312             . euc-china)
122     (cn-big5            . big5)
123     (koi8-r             . koi8)
124     (iso-2022-jp-2      . iso-2022-ss2-7)
125     ))
126
127 (defun mime-charset-to-coding-system (charset)
128   "Return coding-system by MIME charset. [emu-x20.el]"
129   (if (stringp charset)
130       (setq charset (intern (downcase charset)))
131     )
132   (or (cdr (assq charset mime-charset-coding-system-alist))
133       (and (memq charset (coding-system-list)) charset)
134       ))
135
136 (defun detect-mime-charset-region (start end)
137   "Return MIME charset for region between START and END.
138 \[emu-x20.el]"
139   (charsets-to-mime-charset (charsets-in-region start end)))
140
141 (defun encode-mime-charset-region (start end charset)
142   "Encode the text between START and END as MIME CHARSET.
143 \[emu-x20.el]"
144   (let ((cs (mime-charset-to-coding-system charset)))
145     (if cs
146         (encode-coding-region start end cs)
147       )))
148
149 (defun decode-mime-charset-region (start end charset)
150   "Decode the text between START and END as MIME CHARSET.
151 \[emu-x20.el]"
152   (let ((cs (mime-charset-to-coding-system charset)))
153     (if cs
154         (decode-coding-region start end cs)
155       )))
156
157 (defun encode-mime-charset-string (string charset)
158   "Encode the STRING as MIME CHARSET. [emu-x20.el]"
159   (let ((cs (mime-charset-to-coding-system charset)))
160     (if cs
161         (encode-coding-string string cs)
162       string)))
163
164 (defun decode-mime-charset-string (string charset)
165   "Decode the STRING as MIME CHARSET. [emu-x20.el]"
166   (let ((cs (mime-charset-to-coding-system charset)))
167     (if cs
168         (decode-coding-string string cs)
169       string)))
170
171
172 ;;; @ character
173 ;;;
174
175 ;;; @@ Mule emulating aliases
176 ;;;
177 ;;; You should not use them.
178
179 (defalias 'char-leading-char 'char-charset)
180
181 (defun char-category (character)
182   "Return string of category mnemonics for CHAR in TABLE.
183 CHAR can be any multilingual character
184 TABLE defaults to the current buffer's category table.
185 \[emu-x20.el; Mule emulating function]"
186   (mapconcat (lambda (chr)
187                (char-to-string (int-char chr))
188                )
189              (char-category-list character)
190              ""))
191
192
193 ;;; @ string
194 ;;;
195
196 (defun string-to-int-list (str)
197   (mapcar #'char-int str)
198   )
199
200
201 ;;; @ end
202 ;;;
203
204 (provide 'emu-x20)
205
206 ;;; emu-x20.el ends here