1 ;;; emu-mule.el --- emu module for Mule 1.* and Mule 2.*
3 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Mule
8 ;; This file is part of emu.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;;; @ version specific features
30 (cond (running-emacs-19
33 ;; Suggested by SASAKI Osamu <osamu@shuugr.bekkoame.or.jp>
34 ;; (cf. [os2-emacs-ja:78])
35 (defun fontset-pixel-size (fontset)
36 (let* ((font (get-font-info
37 (aref (cdr (get-fontset-info fontset)) 0)))
42 (let ((pat (aref font 1)))
43 (if (string-match "-[0-9]+-" pat)
46 pat (1+ (match-beginning 0)) (1- (match-end 0))))
52 (defun make-overlay (beg end &optional buffer type))
53 (defun overlay-put (overlay prop value))
60 (defalias 'make-char 'make-character)
62 (defalias 'find-non-ascii-charset-string 'find-charset-string)
63 (defalias 'find-non-ascii-charset-region 'find-charset-region)
65 (defalias 'charset-bytes 'char-bytes)
66 (defalias 'charset-description 'char-description)
67 (defalias 'charset-registry 'char-registry)
68 (defalias 'charset-columns 'char-width)
69 (defalias 'charset-direction 'char-direction)
75 (defun encode-coding-region (start end coding-system)
76 "Encode the text between START and END to CODING-SYSTEM.
77 \[EMACS 20 emulating function]"
78 (code-convert-region start end *internal* coding-system)
81 (defun decode-coding-region (start end coding-system)
82 "Decode the text between START and END which is encoded in CODING-SYSTEM.
83 \[EMACS 20 emulating function]"
84 (code-convert-region start end coding-system *internal*)
87 (defun encode-coding-string (str coding-system)
88 "Encode the STRING to CODING-SYSTEM.
89 \[EMACS 20 emulating function]"
90 (code-convert-string str *internal* coding-system)
93 (defun decode-coding-string (str coding-system)
94 "Decode the string STR which is encoded in CODING-SYSTEM.
95 \[EMACS 20 emulating function]"
96 (let ((len (length str))
102 (code-convert-string (substring str 0 len)
103 coding-system *internal*))
107 (concat ret (substring str len))
110 (defalias 'detect-coding-region 'code-detect-region)
112 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
114 (defmacro as-binary-process (&rest body)
115 (` (let (selective-display ; Disable ^M to nl translation.
118 (default-process-coding-system (cons *noconv* *noconv*))
119 program-coding-system-alist)
123 (defmacro as-binary-input-file (&rest body)
125 (file-coding-system-for-read *noconv*)
130 (defmacro as-binary-output-file (&rest body)
132 (file-coding-system *noconv*)
137 (defalias 'set-process-input-coding-system 'set-process-coding-system)
143 (defun insert-binary-file-contents-literally
144 (filename &optional visit beg end replace)
145 "Like `insert-file-contents-literally', q.v., but don't code conversion.
146 A buffer may be modified in several ways after reading into the buffer due
147 to advanced Emacs features, such as file-name-handlers, format decoding,
148 find-file-hooks, etc.
149 This function ensures that none of these modifications will take place."
151 (file-coding-system *noconv*))
152 (insert-file-contents-literally filename visit beg end replace)
155 (defun insert-binary-file-contents
156 (filename &optional visit beg end replace)
157 "Like `insert-file-contents', q.v., but don't code and format conversion."
159 (file-coding-system *noconv*))
160 (insert-file-contents filename visit beg end replace)
167 (defun encode-mime-charset-region (start end charset)
168 "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."
176 (let ((cs (mime-charset-to-coding-system charset)))
178 (code-convert start end cs *internal*)
181 (defun encode-mime-charset-string (string charset)
182 "Encode the STRING as MIME CHARSET."
183 (let ((cs (mime-charset-to-coding-system charset)))
185 (code-convert-string string *internal* cs)
188 (defun decode-mime-charset-string (string charset)
189 "Decode the STRING which is encoded in MIME CHARSET."
190 (let ((cs (mime-charset-to-coding-system charset)))
192 (decode-coding-string string cs)
196 ;;; @@ to coding-system
199 (defvar mime-charset-coding-system-alist
200 '((iso-8859-1 . *ctext*)
202 (gb2312 . *euc-china*)
204 (iso-2022-jp-2 . *iso-2022-ss2-7*)
205 (x-iso-2022-jp-2 . *iso-2022-ss2-7*)
207 (x-shiftjis . *sjis*)
210 (defun mime-charset-to-coding-system (charset &optional lbt)
211 (if (stringp charset)
212 (setq charset (intern (downcase charset)))
215 (or (cdr (assq charset mime-charset-coding-system-alist))
216 (let ((cs (intern (concat "*" (symbol-name charset) "*"))))
217 (and (coding-system-p cs) cs)
222 (intern (concat (symbol-name cs) (symbol-name lbt)))
229 (defvar charsets-mime-charset-alist
231 '(((lc-ascii) . 'us-ascii)
232 ((lc-ascii lc-ltn1) . 'iso-8859-1)
233 ((lc-ascii lc-ltn2) . 'iso-8859-2)
234 ((lc-ascii lc-ltn3) . 'iso-8859-3)
235 ((lc-ascii lc-ltn4) . 'iso-8859-4)
236 ;;; ((lc-ascii lc-crl) . 'iso-8859-5)
237 ((lc-ascii lc-crl) . 'koi8-r)
238 ((lc-ascii lc-arb) . 'iso-8859-6)
239 ((lc-ascii lc-grk) . 'iso-8859-7)
240 ((lc-ascii lc-hbw) . 'iso-8859-8)
241 ((lc-ascii lc-ltn5) . 'iso-8859-9)
242 ((lc-ascii lc-roman lc-jpold lc-jp) . 'iso-2022-jp)
243 ((lc-ascii lc-kr) . 'euc-kr)
244 ((lc-ascii lc-cn) . 'gb2312)
245 ((lc-ascii lc-big5-1 lc-big5-2) . 'big5)
246 ((lc-ascii lc-roman lc-ltn1 lc-grk
247 lc-jpold lc-cn lc-jp lc-kr
248 lc-jp2) . 'iso-2022-jp-2)
249 ((lc-ascii lc-roman lc-ltn1 lc-grk
250 lc-jpold lc-cn lc-jp lc-kr lc-jp2
251 lc-cns1 lc-cns2) . 'iso-2022-int-1)
253 lc-ltn1 lc-ltn2 lc-crl lc-grk
254 lc-jpold lc-cn lc-jp lc-kr lc-jp2
255 lc-cns1 lc-cns2 lc-cns3 lc-cns4
256 lc-cns5 lc-cns6 lc-cns7) . 'iso-2022-int-1)
261 (let ((pair (car alist)))
263 (cons (mapcar (function
267 (throw 'not-found nil)
271 (setq alist (cdr alist))))
274 (defvar default-mime-charset 'x-ctext
275 "Default value of MIME-charset.
276 It is used when MIME-charset is not specified.
279 (defun detect-mime-charset-region (start end)
280 "Return MIME charset for region between START and END."
281 (charsets-to-mime-charset
282 (cons lc-ascii (find-charset-region start end))))
288 (defalias 'char-charset 'char-leading-char)
290 (defalias 'char-length 'char-bytes)
292 (defalias 'char-columns 'char-width)
298 (defalias 'string-columns 'string-width)
300 (defalias 'string-to-int-list 'string-to-char-list)
302 (or (fboundp 'truncate-string)
303 ;;; Imported from Mule-2.3
304 (defun truncate-string (str width &optional start-column)
305 "Truncate STR to fit in WIDTH columns.
306 Optional non-nil arg START-COLUMN specifies the starting column.
307 \[emu-mule.el; Mule 2.3 emulating function]"
309 (setq start-column 0))
310 (let ((max-width (string-width str))
315 (if (>= width max-width)
316 (setq width max-width))
317 (if (>= start-column width)
319 (while (< column start-column)
320 (setq ch (aref str from)
321 column (+ column (char-width ch))
322 from (+ from (char-bytes ch))))
323 (if (< width max-width)
326 (while (<= column width)
327 (setq ch (aref str to)
328 column (+ column (char-width ch))
330 to (+ to (char-bytes ch))))
332 (substring str from to))))
340 (defun regulate-latin-char (chr)
341 (cond ((and (<= ?
\e$B#A
\e(B chr)(<= chr ?
\e$B#Z
\e(B))
342 (+ (- chr ?
\e$B#A
\e(B) ?A)
344 ((and (<= ?
\e$B#a
\e(B chr)(<= chr ?
\e$B#z
\e(B))
345 (+ (- chr ?
\e$B#a
\e(B) ?a)
347 ((eq chr ?
\e$B!%
\e(B) ?.)
348 ((eq chr ?
\e$B!$
\e(B) ?,)
352 (defun regulate-latin-string (str)
353 (let ((len (length str))
357 (setq chr (sref str i))
358 (setq dest (concat dest
359 (char-to-string (regulate-latin-char chr))))
360 (setq i (+ i (char-bytes chr)))
370 ;;; emu-mule.el ends here