1 ;;; emu-mule.el --- emu module for Mule 1.* and Mule 2.*
3 ;; Copyright (C) 1995,1996,1997 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-mule.el,v 7.60 1997/01/29 15:48:26 morioka Exp $
7 ;; Keywords: emulation, compatibility, Mule
9 ;; This file is part of emu.
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 'find-non-ascii-charset-string 'find-charset-string)
62 (defalias 'find-non-ascii-charset-region 'find-charset-region)
64 (defalias 'charset-bytes 'char-bytes)
65 (defalias 'charset-description 'char-description)
66 (defalias 'charset-registry 'char-registry)
67 (defalias 'charset-columns 'char-width)
68 (defalias 'charset-direction 'char-direction)
74 (defun encode-coding-region (start end coding-system)
75 "Encode the text between START and END to CODING-SYSTEM.
76 \[emu-mule.el; EMACS 20 emulating function]"
77 (code-convert-region start end *internal* coding-system)
80 (defun decode-coding-string (str coding-system)
81 "Decode the string STR which is encoded in CODING-SYSTEM.
83 (let ((len (length str))
89 (code-convert-string (substring str 0 len)
90 coding-system *internal*))
94 (concat ret (substring str len))
97 (defalias 'detect-coding-region 'code-detect-region)
99 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
101 (defmacro as-binary-process (&rest body)
102 (` (let (selective-display ; Disable ^M to nl translation.
105 (default-process-coding-system (cons *noconv* *noconv*))
106 program-coding-system-alist)
110 (defmacro as-binary-input-file (&rest body)
112 (file-coding-system-for-read *noconv*)
117 (defmacro as-binary-output-file (&rest body)
119 (file-coding-system *noconv*)
124 (defalias 'set-process-input-coding-system 'set-process-coding-system)
130 (defvar charsets-mime-charset-alist
132 (cons (list lc-ascii) 'us-ascii)
133 (cons (list lc-ascii lc-ltn1) 'iso-8859-1)
134 (cons (list lc-ascii lc-ltn2) 'iso-8859-2)
135 (cons (list lc-ascii lc-ltn3) 'iso-8859-3)
136 (cons (list lc-ascii lc-ltn4) 'iso-8859-4)
137 ;;;(cons (list lc-ascii lc-crl) 'iso-8859-5)
138 (cons (list lc-ascii lc-crl) 'koi8-r)
139 (cons (list lc-ascii lc-arb) 'iso-8859-6)
140 (cons (list lc-ascii lc-grk) 'iso-8859-7)
141 (cons (list lc-ascii lc-hbw) 'iso-8859-8)
142 (cons (list lc-ascii lc-ltn5) 'iso-8859-9)
143 (cons (list lc-ascii lc-roman lc-jpold lc-jp) 'iso-2022-jp)
144 (cons (list lc-ascii lc-kr) 'euc-kr)
145 (cons (list lc-ascii lc-cn) 'gb2312)
146 (cons (list lc-ascii lc-big5-1 lc-big5-2) 'big5)
147 (cons (list lc-ascii lc-roman lc-ltn1 lc-grk
148 lc-jpold lc-cn lc-jp lc-kr lc-jp2) 'iso-2022-jp-2)
149 (cons (list lc-ascii lc-roman lc-ltn1 lc-grk
150 lc-jpold lc-cn lc-jp lc-kr lc-jp2
151 lc-cns1 lc-cns2) 'iso-2022-int-1)
152 (cons (list lc-ascii lc-roman
153 lc-ltn1 lc-ltn2 lc-crl lc-grk
154 lc-jpold lc-cn lc-jp lc-kr lc-jp2
155 lc-cns1 lc-cns2 lc-cns3 lc-cns4
156 lc-cns5 lc-cns6 lc-cns7) 'iso-2022-int-1)
159 (defvar default-mime-charset 'x-ctext)
161 (defvar mime-charset-coding-system-alist
162 '((iso-8859-1 . *ctext*)
164 (gb2312 . *euc-china*)
166 (iso-2022-jp-2 . *iso-2022-ss2-7*)
167 (x-iso-2022-jp-2 . *iso-2022-ss2-7*)
169 (x-shiftjis . *sjis*)
172 (defun mime-charset-to-coding-system (charset &optional lbt)
173 (if (stringp charset)
174 (setq charset (intern (downcase charset)))
177 (or (cdr (assq charset mime-charset-coding-system-alist))
178 (let ((cs (intern (concat "*" (symbol-name charset) "*"))))
179 (and (coding-system-p cs) cs)
184 (intern (concat (symbol-name cs) (symbol-name lbt)))
187 (defun detect-mime-charset-region (start end)
188 "Return MIME charset for region between START and END.
190 (charsets-to-mime-charset
191 (cons lc-ascii (find-charset-region start end))))
193 (defun encode-mime-charset-region (start end charset)
194 "Encode the text between START and END as MIME CHARSET.
196 (let ((cs (mime-charset-to-coding-system charset)))
198 (code-convert start end *internal* cs)
201 (defun decode-mime-charset-region (start end charset)
202 "Decode the text between START and END as MIME CHARSET.
204 (let ((cs (mime-charset-to-coding-system charset)))
206 (code-convert start end cs *internal*)
209 (defun encode-mime-charset-string (string charset)
210 "Encode the STRING as MIME CHARSET. [emu-mule.el]"
211 (let ((cs (mime-charset-to-coding-system charset)))
213 (code-convert-string string *internal* cs)
216 (defun decode-mime-charset-string (string charset)
217 "Decode the STRING which is encoded in MIME CHARSET. [emu-mule.el]"
218 (let ((cs (mime-charset-to-coding-system charset)))
220 (decode-coding-string string cs)
227 (defalias 'char-charset 'char-leading-char)
229 (defalias 'char-length 'char-bytes)
231 (defalias 'char-columns 'char-width)
237 (defalias 'string-columns 'string-width)
239 (defalias 'string-to-int-list 'string-to-char-list)
241 (or (fboundp 'truncate-string)
242 ;;; Imported from Mule-2.3
243 (defun truncate-string (str width &optional start-column)
244 "Truncate STR to fit in WIDTH columns.
245 Optional non-nil arg START-COLUMN specifies the starting column.
246 \[emu-mule.el; Mule 2.3 emulating function]"
248 (setq start-column 0))
249 (let ((max-width (string-width str))
254 (if (>= width max-width)
255 (setq width max-width))
256 (if (>= start-column width)
258 (while (< column start-column)
259 (setq ch (aref str from)
260 column (+ column (char-width ch))
261 from (+ from (char-bytes ch))))
262 (if (< width max-width)
265 (while (<= column width)
266 (setq ch (aref str to)
267 column (+ column (char-width ch))
269 to (+ to (char-bytes ch))))
271 (substring str from to))))
279 (defun regulate-latin-char (chr)
280 (cond ((and (<= ?
\e$B#A
\e(B chr)(<= chr ?
\e$B#Z
\e(B))
281 (+ (- chr ?
\e$B#A
\e(B) ?A)
283 ((and (<= ?
\e$B#a
\e(B chr)(<= chr ?
\e$B#z
\e(B))
284 (+ (- chr ?
\e$B#a
\e(B) ?a)
286 ((eq chr ?
\e$B!%
\e(B) ?.)
287 ((eq chr ?
\e$B!$
\e(B) ?,)
291 (defun regulate-latin-string (str)
292 (let ((len (length str))
296 (setq chr (sref str i))
297 (setq dest (concat dest
298 (char-to-string (regulate-latin-char chr))))
299 (setq i (+ i (char-bytes chr)))
309 ;;; emu-mule.el ends here