1 ;;; emu-mule.el --- Mule 2.* emulation module for Mule
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; $Id: emu-mule.el,v 7.50 1996/09/05 08:58:28 morioka Exp $
8 ;; Keywords: emulation, compatibility, Mule
10 ;; This file is part of tl (Tiny Library).
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with This program; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;;; @ version specific features
32 (cond (running-emacs-19
35 ;; Suggested by SASAKI Osamu <osamu@shuugr.bekkoame.or.jp>
36 ;; (cf. [os2-emacs-ja:78])
37 (defun fontset-pixel-size (fontset)
38 (let* ((font (get-font-info
39 (aref (cdr (get-fontset-info fontset)) 0)))
44 (let ((pat (aref font 1)))
45 (if (string-match "-[0-9]+-" pat)
48 pat (1+ (match-beginning 0)) (1- (match-end 0))))
54 (defun tl:make-overlay (beg end &optional buffer type))
55 (defun tl:overlay-put (overlay prop value))
62 (defalias 'charset-description 'char-description)
63 (defalias 'charset-registry 'char-registry)
64 (defalias 'charset-columns 'char-width)
65 (defalias 'charset-direction 'char-direction)
71 (defun encode-coding-region (start end coding-system)
72 "Encode the text between START and END to CODING-SYSTEM.
73 \[emu-mule.el; EMACS 20 emulating function]"
74 (code-convert-region start end *internal* coding-system)
77 (defun decode-coding-string (str coding-system)
78 "Decode the string STR which is encoded in CODING-SYSTEM.
80 (let ((len (length str))
86 (code-convert-string (substring str 0 len)
87 coding-system *internal*))
91 (concat ret (substring str len))
94 (defmacro as-binary-process (&rest body)
95 (` (let (selective-display ; Disable ^M to nl translation.
98 (default-process-coding-system (cons *noconv* *noconv*))
99 program-coding-system-alist)
103 (defalias 'set-process-input-coding-system 'set-process-coding-system)
109 (defvar charsets-mime-charset-alist
111 (cons (list lc-ascii) 'us-ascii)
112 (cons (list lc-ascii lc-ltn1) 'iso-8859-1)
113 (cons (list lc-ascii lc-ltn2) 'iso-8859-2)
114 (cons (list lc-ascii lc-ltn3) 'iso-8859-3)
115 (cons (list lc-ascii lc-ltn4) 'iso-8859-4)
116 ;;;(cons (list lc-ascii lc-crl) 'iso-8859-5)
117 (cons (list lc-ascii lc-crl) 'koi8-r)
118 (cons (list lc-ascii lc-arb) 'iso-8859-6)
119 (cons (list lc-ascii lc-grk) 'iso-8859-7)
120 (cons (list lc-ascii lc-hbw) 'iso-8859-8)
121 (cons (list lc-ascii lc-ltn5) 'iso-8859-9)
122 (cons (list lc-ascii lc-roman lc-jpold lc-jp) 'iso-2022-jp)
123 (cons (list lc-ascii lc-kr) 'euc-kr)
124 (cons (list lc-ascii lc-cn) 'gb2312)
125 (cons (list lc-ascii lc-big5-1 lc-big5-2) 'big5)
126 (cons (list lc-ascii lc-roman lc-ltn1 lc-grk
127 lc-jpold lc-cn lc-jp lc-kr lc-jp2) 'iso-2022-jp-2)
128 (cons (list lc-ascii lc-roman lc-ltn1 lc-grk
129 lc-jpold lc-cn lc-jp lc-kr lc-jp2
130 lc-cns1 lc-cns2) 'iso-2022-int-1)
131 (cons (list lc-ascii lc-roman
132 lc-ltn1 lc-ltn2 lc-crl lc-grk
133 lc-jpold lc-cn lc-jp lc-kr lc-jp2
134 lc-cns1 lc-cns2 lc-cns3 lc-cns4
135 lc-cns5 lc-cns6 lc-cns7) 'iso-2022-int-1)
138 (defvar default-mime-charset 'x-ctext)
140 (defvar mime-charset-coding-system-alist
141 '((iso-8859-1 . *ctext*)
143 (gb2312 . *euc-china*)
145 (iso-2022-jp-2 . *iso-2022-ss2-7*)
146 (x-iso-2022-jp-2 . *iso-2022-ss2-7*)
148 (x-shiftjis . *sjis*)
151 (defun mime-charset-to-coding-system (charset)
152 (if (stringp charset)
153 (setq charset (intern (downcase charset)))
155 (or (cdr (assq charset mime-charset-coding-system-alist))
156 (let ((cs (intern (concat "*" (symbol-name charset) "*"))))
157 (and (coding-system-p cs) cs)
160 (defun detect-mime-charset-region (start end)
161 "Return MIME charset for region between START and END.
163 (charsets-to-mime-charset
164 (cons lc-ascii (find-charset-region start end))))
166 (defun encode-mime-charset-region (start end charset)
167 "Encode the text between START and END as MIME CHARSET.
169 (let ((cs (mime-charset-to-coding-system charset)))
171 (code-convert start end *internal* cs)
174 (defun decode-mime-charset-region (start end charset)
175 "Decode the text between START and END as MIME CHARSET.
177 (let ((cs (mime-charset-to-coding-system charset)))
179 (code-convert start end cs *internal*)
182 (defun encode-mime-charset-string (string charset)
183 "Encode the STRING as MIME CHARSET. [emu-mule.el]"
184 (let ((cs (mime-charset-to-coding-system charset)))
186 (code-convert-string string *internal* cs)
189 (defun decode-mime-charset-string (string charset)
190 "Decode the STRING which is encoded in MIME CHARSET. [emu-mule.el]"
191 (let ((cs (mime-charset-to-coding-system charset)))
193 (decode-coding-string string cs)
200 (defalias 'char-charset 'char-leading-char)
202 (defalias 'char-length 'char-bytes)
204 (defalias 'char-columns 'char-width)
210 (defalias 'string-columns 'string-width)
212 (defalias 'string-to-int-list 'string-to-char-list)
214 (or (fboundp 'truncate-string)
215 ;;; Imported from Mule-2.3
216 (defun truncate-string (str width &optional start-column)
217 "Truncate STR to fit in WIDTH columns.
218 Optional non-nil arg START-COLUMN specifies the starting column.
219 \[emu-mule.el; Mule 2.3 emulating function]"
221 (setq start-column 0))
222 (let ((max-width (string-width str))
227 (if (>= width max-width)
228 (setq width max-width))
229 (if (>= start-column width)
231 (while (< column start-column)
232 (setq ch (aref str from)
233 column (+ column (char-width ch))
234 from (+ from (char-bytes ch))))
235 (if (< width max-width)
238 (while (<= column width)
239 (setq ch (aref str to)
240 column (+ column (char-width ch))
242 to (+ to (char-bytes ch))))
244 (substring str from to))))
252 (defun regulate-latin-char (chr)
253 (cond ((and (<= ?
\e$B#A
\e(B chr)(<= chr ?
\e$B#Z
\e(B))
254 (+ (- chr ?
\e$B#A
\e(B) ?A)
256 ((and (<= ?
\e$B#a
\e(B chr)(<= chr ?
\e$B#z
\e(B))
257 (+ (- chr ?
\e$B#a
\e(B) ?a)
259 ((eq chr ?
\e$B!%
\e(B) ?.)
260 ((eq chr ?
\e$B!$
\e(B) ?,)
264 (defun regulate-latin-string (str)
265 (let ((len (length str))
269 (setq chr (sref str i))
270 (setq dest (concat dest
271 (char-to-string (regulate-latin-char chr))))
272 (setq i (+ i (char-bytes chr)))
282 ;;; emu-mule.el ends here