2 ;;; emu-mule.el --- Mule 2.* emulation module for Mule
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;; $Id: emu-mule.el,v 7.36 1996/07/11 09:03:20 morioka Exp $
10 ;;; Keywords: emulation, compatibility, Mule
12 ;;; This file is part of tl (Tiny Library).
14 ;;; This program is free software; you can redistribute it and/or
15 ;;; modify it under the terms of the GNU General Public License as
16 ;;; published by the Free Software Foundation; either version 2, or
17 ;;; (at your option) any later version.
19 ;;; This program is distributed in the hope that it will be useful,
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;;; General Public License for more details.
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with This program. If not, write to the Free Software
26 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
30 ;;; @ version specific features
33 (cond (running-emacs-19
36 ;; Suggested by SASAKI Osamu <osamu@shuugr.bekkoame.or.jp>
37 ;; (cf. [os2-emacs-ja:78])
38 (defun fontset-pixel-size (fontset)
39 (let* ((font (get-font-info
40 (aref (cdr (get-fontset-info fontset)) 0)))
45 (let ((pat (aref font 1)))
46 (if (string-match "-[0-9]+-" pat)
49 pat (1+ (match-beginning 0)) (1- (match-end 0))))
55 (defun tl:make-overlay (beg end &optional buffer type))
56 (defun tl:overlay-put (overlay prop value))
63 (defalias 'charset-description 'char-description)
64 (defalias 'charset-registry 'char-registry)
65 (defalias 'charset-columns 'char-width)
66 (defalias 'charset-direction 'char-direction)
72 (defun character-encode-string (str coding-system)
73 "Encode the string STR which is encoded in CODING-SYSTEM.
75 (code-convert-string str *internal* coding-system)
78 (defun character-decode-string (str coding-system)
79 "Decode the string STR which is encoded in CODING-SYSTEM.
81 (let ((len (length str))
87 (code-convert-string (substring str 0 len)
88 coding-system *internal*))
92 (concat ret (substring str len))
95 (defun character-encode-region (start end coding-system)
96 "Encode the text between START and END which is
97 encoded in CODING-SYSTEM. [emu-mule.el]"
98 (code-convert start end *internal* coding-system)
101 (defun character-decode-region (start end coding-system)
102 "Decode the text between START and END which is
103 encoded in CODING-SYSTEM. [emu-mule.el]"
104 (code-convert start end coding-system *internal*)
107 (defmacro as-binary-process (&rest body)
108 (` (let (selective-display ; Disable ^M to nl translation.
111 (default-process-coding-system (cons *noconv* *noconv*))
112 program-coding-system-alist)
120 (defvar charsets-mime-charset-alist
122 (cons (list lc-ascii) 'us-ascii)
123 (cons (list lc-ascii lc-ltn1) 'iso-8859-1)
124 (cons (list lc-ascii lc-ltn2) 'iso-8859-2)
125 (cons (list lc-ascii lc-ltn3) 'iso-8859-3)
126 (cons (list lc-ascii lc-ltn4) 'iso-8859-4)
127 ;;;(cons (list lc-ascii lc-crl) 'iso-8859-5)
128 (cons (list lc-ascii lc-crl) 'koi8-r)
129 (cons (list lc-ascii lc-arb) 'iso-8859-6)
130 (cons (list lc-ascii lc-grk) 'iso-8859-7)
131 (cons (list lc-ascii lc-hbw) 'iso-8859-8)
132 (cons (list lc-ascii lc-ltn5) 'iso-8859-9)
133 (cons (list lc-ascii lc-jp) 'iso-2022-jp)
134 (cons (list lc-ascii lc-kr) 'euc-kr)
135 (cons (list lc-ascii lc-big5-1 lc-big5-2) 'big5)
136 (cons (list lc-ascii lc-cn lc-jp lc-kr lc-jp2
137 lc-ltn1 lc-grk) 'iso-2022-jp-2)
138 (cons (list lc-ascii lc-cn lc-jp lc-kr lc-jp2
139 lc-cns1 lc-cns2 lc-ltn1 lc-grk) 'iso-2022-int-1)
142 (defvar default-mime-charset 'iso-2022-int-1)
144 (defvar mime-charset-coding-system-alist
145 '((iso-8859-1 . *ctext*)
146 (gb2312 . *euc-china*)
148 (iso-2022-jp-2 . *iso-2022-ss2-7*)
149 (x-iso-2022-jp-2 . *iso-2022-ss2-7*)
151 (x-shiftjis . *sjis*)
154 (defun mime-charset-to-coding-system (charset)
155 (if (stringp charset)
156 (setq charset (intern (downcase charset)))
158 (or (cdr (assq charset mime-charset-coding-system-alist))
159 (let ((cs (intern (concat "*" (symbol-name charset) "*"))))
160 (and (coding-system-p cs) cs)
163 (defun detect-mime-charset-region (start end)
164 "Return MIME charset for region between START and END.
166 (charsets-to-mime-charset
167 (cons lc-ascii (find-charset-region start end))))
169 (defun encode-mime-charset-region (start end charset)
170 "Encode the text between START and END which is
171 encoded in MIME CHARSET. [emu-mule.el]"
172 (let ((cs (mime-charset-to-coding-system charset)))
174 (code-convert start end *internal* cs)
177 (defun encode-mime-charset-string (string charset)
178 "Encode the STRING which is encoded in MIME CHARSET. [emu-mule.el]"
179 (let ((cs (mime-charset-to-coding-system charset)))
181 (code-convert-string string *internal* cs)
188 (defalias 'char-charset 'char-leading-char)
190 (defalias 'char-length 'char-bytes)
192 (defalias 'char-columns 'char-width)
198 (defalias 'string-columns 'string-width)
200 (defalias 'string-to-int-list 'string-to-char-list)
202 (or (fboundp 'truncate-string)
203 ;;; Imported from Mule-2.3
204 (defun truncate-string (str width &optional start-column)
205 "Truncate STR to fit in WIDTH columns.
206 Optional non-nil arg START-COLUMN specifies the starting column.
207 \[emu-mule.el; Mule 2.3 emulating function]"
209 (setq start-column 0))
210 (let ((max-width (string-width str))
215 (if (>= width max-width)
216 (setq width max-width))
217 (if (>= start-column width)
219 (while (< column start-column)
220 (setq ch (aref str from)
221 column (+ column (char-width ch))
222 from (+ from (char-bytes ch))))
223 (if (< width max-width)
226 (while (<= column width)
227 (setq ch (aref str to)
228 column (+ column (char-width ch))
230 to (+ to (char-bytes ch))))
232 (substring str from to))))
240 (defun regulate-latin-char (chr)
241 (cond ((and (<= ?
\e$B#A
\e(B chr)(<= chr ?
\e$B#Z
\e(B))
242 (+ (- chr ?
\e$B#A
\e(B) ?A)
244 ((and (<= ?
\e$B#a
\e(B chr)(<= chr ?
\e$B#z
\e(B))
245 (+ (- chr ?
\e$B#a
\e(B) ?a)
247 ((eq chr ?
\e$B!%
\e(B) ?.)
248 ((eq chr ?
\e$B!$
\e(B) ?,)
252 (defun regulate-latin-string (str)
253 (let ((len (length str))
257 (setq chr (sref str i))
258 (setq dest (concat dest
259 (char-to-string (regulate-latin-char chr))))
260 (setq i (+ i (char-bytes chr)))
270 ;;; emu-mule.el ends here