(insert-binary-file-contents): Moved from emu-20.el.
[elisp/apel.git] / emu-x20.el
1 ;;; emu-x20.el --- emu API implementation for XEmacs with mule
2
3 ;; Copyright (C) 1994,1995,1996,1997,1998 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-x20.el,v 7.69 1998/01/10 18:00:57 morioka Exp $
7 ;; Keywords: emulation, compatibility, Mule, XEmacs
8
9 ;; This file is part of emu.
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 Emacs; 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.3-b5 or later with mule.
29
30 ;;; Code:
31
32 (require 'emu-xemacs)
33 (require 'emu-20)
34
35
36 (and (coding-system-property 'iso-2022-jp 'input-charset-conversion)
37      (copy-coding-system 'iso-2022-7bit 'iso-2022-jp))
38
39
40 ;;; @ binary access
41 ;;;
42
43 (defun insert-binary-file-contents (filename &optional visit beg end replace)
44   "Like `insert-file-contents', q.v., but don't code and format conversion."
45   (let ((coding-system-for-read 'binary)
46         format-alist)
47     (insert-file-contents filename visit beg end replace)
48     ))
49
50     
51 ;;; @ MIME charset
52 ;;;
53
54 (defsubst encode-mime-charset-region (start end charset)
55   "Encode the text between START and END as MIME CHARSET."
56   (let ((cs (mime-charset-to-coding-system charset)))
57     (if cs
58         (encode-coding-region start end cs)
59       )))
60
61 (defsubst decode-mime-charset-region (start end charset)
62   "Decode the text between START and END as MIME CHARSET."
63   (let ((cs (mime-charset-to-coding-system charset)))
64     (if cs
65         (decode-coding-region start end cs)
66       )))
67
68 (defsubst encode-mime-charset-string (string charset)
69   "Encode the STRING as MIME CHARSET."
70   (let ((cs (mime-charset-to-coding-system charset)))
71     (if cs
72         (encode-coding-string string cs)
73       string)))
74
75 (defsubst decode-mime-charset-string (string charset)
76   "Decode the STRING as MIME CHARSET."
77   (let ((cs (mime-charset-to-coding-system charset)))
78     (if cs
79         (decode-coding-string string cs)
80       string)))
81
82
83 (defvar charsets-mime-charset-alist
84   '(((ascii)                                            . us-ascii)
85     ((ascii latin-iso8859-1)                            . iso-8859-1)
86     ((ascii latin-iso8859-2)                            . iso-8859-2)
87     ((ascii latin-iso8859-3)                            . iso-8859-3)
88     ((ascii latin-iso8859-4)                            . iso-8859-4)
89     ((ascii cyrillic-iso8859-5)                         . iso-8859-5)
90 ;;; ((ascii cyrillic-iso8859-5)                         . koi8-r)
91     ((ascii arabic-iso8859-6)                           . iso-8859-6)
92     ((ascii greek-iso8859-7)                            . iso-8859-7)
93     ((ascii hebrew-iso8859-8)                           . iso-8859-8)
94     ((ascii latin-iso8859-9)                            . iso-8859-9)
95     ((ascii latin-jisx0201
96             japanese-jisx0208-1978 japanese-jisx0208)   . iso-2022-jp)
97     ((ascii korean-ksc5601)                             . euc-kr)
98     ((ascii chinese-gb2312)                             . cn-gb-2312)
99     ((ascii chinese-big5-1 chinese-big5-2)              . cn-big5)
100     ((ascii latin-iso8859-1 greek-iso8859-7
101             latin-jisx0201 japanese-jisx0208-1978
102             chinese-gb2312 japanese-jisx0208
103             korean-ksc5601 japanese-jisx0212)           . iso-2022-jp-2)
104     ((ascii latin-iso8859-1 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)      . iso-2022-int-1)
109     ((ascii latin-iso8859-1 latin-iso8859-2
110             cyrillic-iso8859-5 greek-iso8859-7
111             latin-jisx0201 japanese-jisx0208-1978
112             chinese-gb2312 japanese-jisx0208
113             korean-ksc5601 japanese-jisx0212
114             chinese-cns11643-1 chinese-cns11643-2
115             chinese-cns11643-3 chinese-cns11643-4
116             chinese-cns11643-5 chinese-cns11643-6
117             chinese-cns11643-7)                         . iso-2022-int-1)
118     ))
119
120 (defun detect-mime-charset-region (start end)
121   "Return MIME charset for region between START and END."
122   (charsets-to-mime-charset (charsets-in-region start end)))
123
124
125 ;;; @ character
126 ;;;
127
128 ;;; @@ Mule emulating aliases
129 ;;;
130 ;;; You should not use them.
131
132 (defalias 'char-leading-char 'char-charset)
133
134 (defun char-category (character)
135   "Return string of category mnemonics for CHAR in TABLE.
136 CHAR can be any multilingual character
137 TABLE defaults to the current buffer's category table."
138   (mapconcat (lambda (chr)
139                (char-to-string (int-char chr))
140                )
141              (char-category-list character)
142              ""))
143
144
145 ;;; @ string
146 ;;;
147
148 (defun string-to-int-list (str)
149   (mapcar #'char-int str)
150   )
151
152
153 ;;; @ end
154 ;;;
155
156 (provide 'emu-x20)
157
158 ;;; emu-x20.el ends here