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.48 1996/08/22 16:21:21 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 decode-coding-string (str coding-system)
72 "Decode the string STR which is encoded in CODING-SYSTEM.
74 (let ((len (length str))
80 (code-convert-string (substring str 0 len)
81 coding-system *internal*))
85 (concat ret (substring str len))
88 (defmacro as-binary-process (&rest body)
89 (` (let (selective-display ; Disable ^M to nl translation.
92 (default-process-coding-system (cons *noconv* *noconv*))
93 program-coding-system-alist)
97 (defalias 'set-process-input-coding-system 'set-process-coding-system)
103 (defvar charsets-mime-charset-alist
105 (cons (list lc-ascii) 'us-ascii)
106 (cons (list lc-ascii lc-ltn1) 'iso-8859-1)
107 (cons (list lc-ascii lc-ltn2) 'iso-8859-2)
108 (cons (list lc-ascii lc-ltn3) 'iso-8859-3)
109 (cons (list lc-ascii lc-ltn4) 'iso-8859-4)
110 ;;;(cons (list lc-ascii lc-crl) 'iso-8859-5)
111 (cons (list lc-ascii lc-crl) 'koi8-r)
112 (cons (list lc-ascii lc-arb) 'iso-8859-6)
113 (cons (list lc-ascii lc-grk) 'iso-8859-7)
114 (cons (list lc-ascii lc-hbw) 'iso-8859-8)
115 (cons (list lc-ascii lc-ltn5) 'iso-8859-9)
116 (cons (list lc-ascii lc-roman lc-jpold lc-jp) 'iso-2022-jp)
117 (cons (list lc-ascii lc-kr) 'euc-kr)
118 (cons (list lc-ascii lc-big5-1 lc-big5-2) 'big5)
119 (cons (list lc-ascii lc-roman lc-ltn1 lc-grk
120 lc-jpold lc-cn lc-jp lc-kr lc-jp2) 'iso-2022-jp-2)
121 (cons (list lc-ascii lc-roman lc-ltn1 lc-grk
122 lc-jpold lc-cn lc-jp lc-kr lc-jp2
123 lc-cns1 lc-cns2) 'iso-2022-int-1)
124 (cons (list lc-ascii lc-roman
125 lc-ltn1 lc-ltn2 lc-crl lc-grk
126 lc-jpold lc-cn lc-jp lc-kr lc-jp2
127 lc-cns1 lc-cns2 lc-cns3 lc-cns4
128 lc-cns5 lc-cns6 lc-cns7) 'iso-2022-int-1)
131 (defvar default-mime-charset 'x-ctext)
133 (defvar mime-charset-coding-system-alist
134 '((iso-8859-1 . *ctext*)
136 (gb2312 . *euc-china*)
138 (iso-2022-jp-2 . *iso-2022-ss2-7*)
139 (x-iso-2022-jp-2 . *iso-2022-ss2-7*)
141 (x-shiftjis . *sjis*)
144 (defun mime-charset-to-coding-system (charset)
145 (if (stringp charset)
146 (setq charset (intern (downcase charset)))
148 (or (cdr (assq charset mime-charset-coding-system-alist))
149 (let ((cs (intern (concat "*" (symbol-name charset) "*"))))
150 (and (coding-system-p cs) cs)
153 (defun detect-mime-charset-region (start end)
154 "Return MIME charset for region between START and END.
156 (charsets-to-mime-charset
157 (cons lc-ascii (find-charset-region start end))))
159 (defun encode-mime-charset-region (start end charset)
160 "Encode the text between START and END as MIME CHARSET.
162 (let ((cs (mime-charset-to-coding-system charset)))
164 (code-convert start end *internal* cs)
167 (defun decode-mime-charset-region (start end charset)
168 "Decode the text between START and END as MIME CHARSET.
170 (let ((cs (mime-charset-to-coding-system charset)))
172 (code-convert start end cs *internal*)
175 (defun encode-mime-charset-string (string charset)
176 "Encode the STRING as MIME CHARSET. [emu-mule.el]"
177 (let ((cs (mime-charset-to-coding-system charset)))
179 (code-convert-string string *internal* cs)
182 (defun decode-mime-charset-string (string charset)
183 "Decode the STRING which is encoded in MIME CHARSET. [emu-mule.el]"
184 (let ((cs (mime-charset-to-coding-system charset)))
186 (decode-coding-string string cs)
193 (defalias 'char-charset 'char-leading-char)
195 (defalias 'char-length 'char-bytes)
197 (defalias 'char-columns 'char-width)
203 (defalias 'string-columns 'string-width)
205 (defalias 'string-to-int-list 'string-to-char-list)
207 (or (fboundp 'truncate-string)
208 ;;; Imported from Mule-2.3
209 (defun truncate-string (str width &optional start-column)
210 "Truncate STR to fit in WIDTH columns.
211 Optional non-nil arg START-COLUMN specifies the starting column.
212 \[emu-mule.el; Mule 2.3 emulating function]"
214 (setq start-column 0))
215 (let ((max-width (string-width str))
220 (if (>= width max-width)
221 (setq width max-width))
222 (if (>= start-column width)
224 (while (< column start-column)
225 (setq ch (aref str from)
226 column (+ column (char-width ch))
227 from (+ from (char-bytes ch))))
228 (if (< width max-width)
231 (while (<= column width)
232 (setq ch (aref str to)
233 column (+ column (char-width ch))
235 to (+ to (char-bytes ch))))
237 (substring str from to))))
245 (defun regulate-latin-char (chr)
246 (cond ((and (<= ?
\e$B#A
\e(B chr)(<= chr ?
\e$B#Z
\e(B))
247 (+ (- chr ?
\e$B#A
\e(B) ?A)
249 ((and (<= ?
\e$B#a
\e(B chr)(<= chr ?
\e$B#z
\e(B))
250 (+ (- chr ?
\e$B#a
\e(B) ?a)
252 ((eq chr ?
\e$B!%
\e(B) ?.)
253 ((eq chr ?
\e$B!$
\e(B) ?,)
257 (defun regulate-latin-string (str)
258 (let ((len (length str))
262 (setq chr (sref str i))
263 (setq dest (concat dest
264 (char-to-string (regulate-latin-char chr))))
265 (setq i (+ i (char-bytes chr)))
275 ;;; emu-mule.el ends here