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.44 1996/08/05 15:15:18 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-decode-string (str coding-system)
73 "Decode the string STR which is encoded in CODING-SYSTEM.
75 (let ((len (length str))
81 (code-convert-string (substring str 0 len)
82 coding-system *internal*))
86 (concat ret (substring str len))
89 (defmacro as-binary-process (&rest body)
90 (` (let (selective-display ; Disable ^M to nl translation.
93 (default-process-coding-system (cons *noconv* *noconv*))
94 program-coding-system-alist)
102 (defvar charsets-mime-charset-alist
104 (cons (list lc-ascii) 'us-ascii)
105 (cons (list lc-ascii lc-ltn1) 'iso-8859-1)
106 (cons (list lc-ascii lc-ltn2) 'iso-8859-2)
107 (cons (list lc-ascii lc-ltn3) 'iso-8859-3)
108 (cons (list lc-ascii lc-ltn4) 'iso-8859-4)
109 ;;;(cons (list lc-ascii lc-crl) 'iso-8859-5)
110 (cons (list lc-ascii lc-crl) 'koi8-r)
111 (cons (list lc-ascii lc-arb) 'iso-8859-6)
112 (cons (list lc-ascii lc-grk) 'iso-8859-7)
113 (cons (list lc-ascii lc-hbw) 'iso-8859-8)
114 (cons (list lc-ascii lc-ltn5) 'iso-8859-9)
115 (cons (list lc-ascii lc-jp) 'iso-2022-jp)
116 (cons (list lc-ascii lc-kr) 'euc-kr)
117 (cons (list lc-ascii lc-big5-1 lc-big5-2) 'big5)
118 (cons (list lc-ascii lc-cn lc-jp lc-kr lc-jp2
119 lc-ltn1 lc-grk) 'iso-2022-jp-2)
120 (cons (list lc-ascii lc-cn lc-jp lc-kr lc-jp2
121 lc-cns1 lc-cns2 lc-ltn1 lc-grk) 'iso-2022-int-1)
124 (defvar default-mime-charset 'x-ctext)
126 (defvar mime-charset-coding-system-alist
127 '((iso-8859-1 . *ctext*)
129 (gb2312 . *euc-china*)
131 (iso-2022-jp-2 . *iso-2022-ss2-7*)
132 (x-iso-2022-jp-2 . *iso-2022-ss2-7*)
134 (x-shiftjis . *sjis*)
137 (defun mime-charset-to-coding-system (charset)
138 (if (stringp charset)
139 (setq charset (intern (downcase charset)))
141 (or (cdr (assq charset mime-charset-coding-system-alist))
142 (let ((cs (intern (concat "*" (symbol-name charset) "*"))))
143 (and (coding-system-p cs) cs)
146 (defun detect-mime-charset-region (start end)
147 "Return MIME charset for region between START and END.
149 (charsets-to-mime-charset
150 (cons lc-ascii (find-charset-region start end))))
152 (defun encode-mime-charset-region (start end charset)
153 "Encode the text between START and END as MIME CHARSET.
155 (let ((cs (mime-charset-to-coding-system charset)))
157 (code-convert start end *internal* cs)
160 (defun decode-mime-charset-region (start end charset)
161 "Decode the text between START and END as MIME CHARSET.
163 (let ((cs (mime-charset-to-coding-system charset)))
165 (code-convert start end cs *internal*)
168 (defun encode-mime-charset-string (string charset)
169 "Encode the STRING as MIME CHARSET. [emu-mule.el]"
170 (let ((cs (mime-charset-to-coding-system charset)))
172 (code-convert-string string *internal* cs)
175 (defun decode-mime-charset-string (string charset)
176 "Decode the STRING which is encoded in MIME CHARSET. [emu-mule.el]"
177 (let ((cs (mime-charset-to-coding-system charset)))
179 (character-decode-string string cs)
186 (defalias 'char-charset 'char-leading-char)
188 (defalias 'char-length 'char-bytes)
190 (defalias 'char-columns 'char-width)
196 (defalias 'string-columns 'string-width)
198 (defalias 'string-to-int-list 'string-to-char-list)
200 (or (fboundp 'truncate-string)
201 ;;; Imported from Mule-2.3
202 (defun truncate-string (str width &optional start-column)
203 "Truncate STR to fit in WIDTH columns.
204 Optional non-nil arg START-COLUMN specifies the starting column.
205 \[emu-mule.el; Mule 2.3 emulating function]"
207 (setq start-column 0))
208 (let ((max-width (string-width str))
213 (if (>= width max-width)
214 (setq width max-width))
215 (if (>= start-column width)
217 (while (< column start-column)
218 (setq ch (aref str from)
219 column (+ column (char-width ch))
220 from (+ from (char-bytes ch))))
221 (if (< width max-width)
224 (while (<= column width)
225 (setq ch (aref str to)
226 column (+ column (char-width ch))
228 to (+ to (char-bytes ch))))
230 (substring str from to))))
238 (defun regulate-latin-char (chr)
239 (cond ((and (<= ?
\e$B#A
\e(B chr)(<= chr ?
\e$B#Z
\e(B))
240 (+ (- chr ?
\e$B#A
\e(B) ?A)
242 ((and (<= ?
\e$B#a
\e(B chr)(<= chr ?
\e$B#z
\e(B))
243 (+ (- chr ?
\e$B#a
\e(B) ?a)
245 ((eq chr ?
\e$B!%
\e(B) ?.)
246 ((eq chr ?
\e$B!$
\e(B) ?,)
250 (defun regulate-latin-string (str)
251 (let ((len (length str))
255 (setq chr (sref str i))
256 (setq dest (concat dest
257 (char-to-string (regulate-latin-char chr))))
258 (setq i (+ i (char-bytes chr)))
268 ;;; emu-mule.el ends here