1 ;;; emu-mule.el --- emu module for Mule 1.* and Mule 2.*
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-mule.el,v 7.56 1996/09/23 20:34:34 morioka Exp $
7 ;; Keywords: emulation, compatibility, Mule
9 ;; This file is part of tl (Tiny Library).
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.
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.
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.
28 ;;; @ version specific features
31 (cond (running-emacs-19
34 ;; Suggested by SASAKI Osamu <osamu@shuugr.bekkoame.or.jp>
35 ;; (cf. [os2-emacs-ja:78])
36 (defun fontset-pixel-size (fontset)
37 (let* ((font (get-font-info
38 (aref (cdr (get-fontset-info fontset)) 0)))
43 (let ((pat (aref font 1)))
44 (if (string-match "-[0-9]+-" pat)
47 pat (1+ (match-beginning 0)) (1- (match-end 0))))
53 (defun tl:make-overlay (beg end &optional buffer type))
54 (defun tl:overlay-put (overlay prop value))
61 (defalias 'charset-bytes 'char-bytes)
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 (defalias 'detect-coding-region 'code-detect-region)
96 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
98 (defmacro as-binary-process (&rest body)
99 (` (let (selective-display ; Disable ^M to nl translation.
102 (default-process-coding-system (cons *noconv* *noconv*))
103 program-coding-system-alist)
107 (defmacro as-binary-input-file (&rest body)
109 (file-coding-system-for-read *noconv*)
114 (defalias 'set-process-input-coding-system 'set-process-coding-system)
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-roman lc-jpold lc-jp) 'iso-2022-jp)
134 (cons (list lc-ascii lc-kr) 'euc-kr)
135 (cons (list lc-ascii lc-cn) 'gb2312)
136 (cons (list lc-ascii lc-big5-1 lc-big5-2) 'big5)
137 (cons (list lc-ascii lc-roman lc-ltn1 lc-grk
138 lc-jpold lc-cn lc-jp lc-kr lc-jp2) 'iso-2022-jp-2)
139 (cons (list lc-ascii lc-roman lc-ltn1 lc-grk
140 lc-jpold lc-cn lc-jp lc-kr lc-jp2
141 lc-cns1 lc-cns2) 'iso-2022-int-1)
142 (cons (list lc-ascii lc-roman
143 lc-ltn1 lc-ltn2 lc-crl lc-grk
144 lc-jpold lc-cn lc-jp lc-kr lc-jp2
145 lc-cns1 lc-cns2 lc-cns3 lc-cns4
146 lc-cns5 lc-cns6 lc-cns7) 'iso-2022-int-1)
149 (defvar default-mime-charset 'x-ctext)
151 (defvar mime-charset-coding-system-alist
152 '((iso-8859-1 . *ctext*)
154 (gb2312 . *euc-china*)
156 (iso-2022-jp-2 . *iso-2022-ss2-7*)
157 (x-iso-2022-jp-2 . *iso-2022-ss2-7*)
159 (x-shiftjis . *sjis*)
162 (defun mime-charset-to-coding-system (charset)
163 (if (stringp charset)
164 (setq charset (intern (downcase charset)))
166 (or (cdr (assq charset mime-charset-coding-system-alist))
167 (let ((cs (intern (concat "*" (symbol-name charset) "*"))))
168 (and (coding-system-p cs) cs)
171 (defun detect-mime-charset-region (start end)
172 "Return MIME charset for region between START and END.
174 (charsets-to-mime-charset
175 (cons lc-ascii (find-charset-region start end))))
177 (defun encode-mime-charset-region (start end charset)
178 "Encode the text between START and END as MIME CHARSET.
180 (let ((cs (mime-charset-to-coding-system charset)))
182 (code-convert start end *internal* cs)
185 (defun decode-mime-charset-region (start end charset)
186 "Decode the text between START and END as MIME CHARSET.
188 (let ((cs (mime-charset-to-coding-system charset)))
190 (code-convert start end cs *internal*)
193 (defun encode-mime-charset-string (string charset)
194 "Encode the STRING as MIME CHARSET. [emu-mule.el]"
195 (let ((cs (mime-charset-to-coding-system charset)))
197 (code-convert-string string *internal* cs)
200 (defun decode-mime-charset-string (string charset)
201 "Decode the STRING which is encoded in MIME CHARSET. [emu-mule.el]"
202 (let ((cs (mime-charset-to-coding-system charset)))
204 (decode-coding-string string cs)
211 (defalias 'char-charset 'char-leading-char)
213 (defalias 'char-length 'char-bytes)
215 (defalias 'char-columns 'char-width)
221 (defalias 'string-columns 'string-width)
223 (defalias 'string-to-int-list 'string-to-char-list)
225 (or (fboundp 'truncate-string)
226 ;;; Imported from Mule-2.3
227 (defun truncate-string (str width &optional start-column)
228 "Truncate STR to fit in WIDTH columns.
229 Optional non-nil arg START-COLUMN specifies the starting column.
230 \[emu-mule.el; Mule 2.3 emulating function]"
232 (setq start-column 0))
233 (let ((max-width (string-width str))
238 (if (>= width max-width)
239 (setq width max-width))
240 (if (>= start-column width)
242 (while (< column start-column)
243 (setq ch (aref str from)
244 column (+ column (char-width ch))
245 from (+ from (char-bytes ch))))
246 (if (< width max-width)
249 (while (<= column width)
250 (setq ch (aref str to)
251 column (+ column (char-width ch))
253 to (+ to (char-bytes ch))))
255 (substring str from to))))
263 (defun regulate-latin-char (chr)
264 (cond ((and (<= ?
\e$B#A
\e(B chr)(<= chr ?
\e$B#Z
\e(B))
265 (+ (- chr ?
\e$B#A
\e(B) ?A)
267 ((and (<= ?
\e$B#a
\e(B chr)(<= chr ?
\e$B#z
\e(B))
268 (+ (- chr ?
\e$B#a
\e(B) ?a)
270 ((eq chr ?
\e$B!%
\e(B) ?.)
271 ((eq chr ?
\e$B!$
\e(B) ?,)
275 (defun regulate-latin-string (str)
276 (let ((len (length str))
280 (setq chr (sref str i))
281 (setq dest (concat dest
282 (char-to-string (regulate-latin-char chr))))
283 (setq i (+ i (char-bytes chr)))
293 ;;; emu-mule.el ends here