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 ;; Katsumi Yamaoka <yamaoka@jpl.org>
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 make-overlay (beg end &optional buffer type))
54 (defun overlay-put (overlay prop value))
61 (defalias 'make-char 'make-character)
63 (defalias 'find-non-ascii-charset-string 'find-charset-string)
64 (defalias 'find-non-ascii-charset-region 'find-charset-region)
66 (defalias 'charset-bytes 'char-bytes)
67 (defalias 'charset-description 'char-description)
68 (defalias 'charset-registry 'char-registry)
69 (defalias 'charset-columns 'char-width)
70 (defalias 'charset-direction 'char-direction)
76 (defun encode-coding-region (start end coding-system)
77 "Encode the text between START and END to CODING-SYSTEM.
78 \[EMACS 20 emulating function]"
79 (code-convert-region start end *internal* coding-system)
82 (defun decode-coding-region (start end coding-system)
83 "Decode the text between START and END which is encoded in CODING-SYSTEM.
84 \[EMACS 20 emulating function]"
85 (code-convert-region start end coding-system *internal*)
88 (defun encode-coding-string (str coding-system)
89 "Encode the STRING to CODING-SYSTEM.
90 \[EMACS 20 emulating function]"
91 (code-convert-string str *internal* coding-system)
94 (defun decode-coding-string (str coding-system)
95 "Decode the string STR which is encoded in CODING-SYSTEM.
96 \[EMACS 20 emulating function]"
97 (let ((len (length str))
103 (code-convert-string (substring str 0 len)
104 coding-system *internal*))
108 (concat ret (substring str len))
111 (defalias 'detect-coding-region 'code-detect-region)
113 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
115 (defmacro as-binary-process (&rest body)
116 (` (let (selective-display ; Disable ^M to nl translation.
119 (default-process-coding-system (cons *noconv* *noconv*))
120 program-coding-system-alist)
124 (defmacro as-binary-input-file (&rest body)
126 (file-coding-system-for-read *noconv*)
131 (defmacro as-binary-output-file (&rest body)
133 (file-coding-system *noconv*)
138 (defalias 'set-process-input-coding-system 'set-process-coding-system)
144 (defun insert-file-contents-as-binary (filename
145 &optional visit beg end replace)
146 "Like `insert-file-contents', q.v., but don't code and format conversion.
147 Like `insert-file-contents-literary', but it allows find-file-hooks,
148 automatic uncompression, etc.
150 Namely this function ensures that only format decoding and character
151 code conversion will not take place."
153 (file-coding-system *noconv*))
154 (insert-file-contents filename visit beg end replace)
157 (defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
158 (make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
160 (defun insert-binary-file-contents-literally (filename
161 &optional visit beg end replace)
162 "Like `insert-file-contents-literally', q.v., but don't code conversion.
163 A buffer may be modified in several ways after reading into the buffer due
164 to advanced Emacs features, such as file-name-handlers, format decoding,
165 find-file-hooks, etc.
166 This function ensures that none of these modifications will take place."
168 (file-coding-system *noconv*))
169 (insert-file-contents-literally filename visit beg end replace)
172 (if running-emacs-19_29-or-later
173 ;; for MULE 2.3 based on Emacs 19.34.
174 (defun write-region-as-binary (start end filename
175 &optional append visit lockname)
176 "Like `write-region', q.v., but don't code conversion."
178 (file-coding-system *noconv*))
179 (write-region start end filename append visit lockname)
181 ;; for MULE 2.3 based on Emacs 19.28.
182 (defun write-region-as-binary (start end filename
183 &optional append visit lockname)
184 "Like `write-region', q.v., but don't code conversion."
186 (file-coding-system *noconv*))
187 (write-region start end filename append visit)
195 (defun encode-mime-charset-region (start end charset)
196 "Encode the text between START and END as MIME CHARSET."
197 (let ((cs (mime-charset-to-coding-system charset)))
199 (code-convert start end *internal* cs)
202 (defun decode-mime-charset-region (start end charset)
203 "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."
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."
218 (let ((cs (mime-charset-to-coding-system charset)))
220 (decode-coding-string string cs)
223 (defun write-region-as-mime-charset (charset start end filename)
224 "Like `write-region', q.v., but code-convert by MIME CHARSET."
225 (let ((file-coding-system
226 (or (mime-charset-to-coding-system charset)
228 (write-region start end filename append visit)
232 ;;; @@ to coding-system
235 (defvar mime-charset-coding-system-alist
236 '((iso-8859-1 . *ctext*)
238 (gb2312 . *euc-china*)
240 (iso-2022-jp-2 . *iso-2022-ss2-7*)
241 (x-iso-2022-jp-2 . *iso-2022-ss2-7*)
243 (x-shiftjis . *sjis*)
246 (defun mime-charset-to-coding-system (charset &optional lbt)
247 (if (stringp charset)
248 (setq charset (intern (downcase charset)))
251 (or (cdr (assq charset mime-charset-coding-system-alist))
252 (let ((cs (intern (concat "*" (symbol-name charset) "*"))))
253 (and (coding-system-p cs) cs)
258 (intern (concat (symbol-name cs) (symbol-name lbt)))
265 (defvar charsets-mime-charset-alist
267 '(((lc-ascii) . us-ascii)
268 ((lc-ascii lc-ltn1) . iso-8859-1)
269 ((lc-ascii lc-ltn2) . iso-8859-2)
270 ((lc-ascii lc-ltn3) . iso-8859-3)
271 ((lc-ascii lc-ltn4) . iso-8859-4)
272 ;;; ((lc-ascii lc-crl) . iso-8859-5)
273 ((lc-ascii lc-crl) . koi8-r)
274 ((lc-ascii lc-arb) . iso-8859-6)
275 ((lc-ascii lc-grk) . iso-8859-7)
276 ((lc-ascii lc-hbw) . iso-8859-8)
277 ((lc-ascii lc-ltn5) . iso-8859-9)
278 ((lc-ascii lc-roman lc-jpold lc-jp) . iso-2022-jp)
279 ((lc-ascii lc-kr) . euc-kr)
280 ((lc-ascii lc-cn) . gb2312)
281 ((lc-ascii lc-big5-1 lc-big5-2) . big5)
282 ((lc-ascii lc-roman lc-ltn1 lc-grk
283 lc-jpold lc-cn lc-jp lc-kr
284 lc-jp2) . iso-2022-jp-2)
285 ((lc-ascii lc-roman lc-ltn1 lc-grk
286 lc-jpold lc-cn lc-jp lc-kr lc-jp2
287 lc-cns1 lc-cns2) . iso-2022-int-1)
289 lc-ltn1 lc-ltn2 lc-crl lc-grk
290 lc-jpold lc-cn lc-jp lc-kr lc-jp2
291 lc-cns1 lc-cns2 lc-cns3 lc-cns4
292 lc-cns5 lc-cns6 lc-cns7) . iso-2022-int-1)
297 (let ((pair (car alist)))
301 (cons (mapcar (function
305 (throw 'not-found nil)
309 (setq alist (cdr alist)))
312 (defvar default-mime-charset 'x-ctext
313 "Default value of MIME-charset.
314 It is used when MIME-charset is not specified.
317 (defun detect-mime-charset-region (start end)
318 "Return MIME charset for region between START and END."
319 (charsets-to-mime-charset
320 (cons lc-ascii (find-charset-region start end))))
326 (defalias 'char-charset 'char-leading-char)
328 (defmacro char-next-index (char index)
329 "Return index of character succeeding CHAR whose index is INDEX."
330 (` (+ (, index) (char-bytes (, char)))))
332 ;;; @@ obsoleted aliases
334 ;;; You should not use them.
336 (defalias 'char-length 'char-bytes)
337 ;;(defalias 'char-columns 'char-width)
343 (defalias 'string-columns 'string-width)
345 (defalias 'string-to-int-list 'string-to-char-list)
347 (or (fboundp 'truncate-string)
348 ;;; Imported from Mule-2.3
349 (defun truncate-string (str width &optional start-column)
350 "Truncate STR to fit in WIDTH columns.
351 Optional non-nil arg START-COLUMN specifies the starting column.
352 \[emu-mule.el; Mule 2.3 emulating function]"
354 (setq start-column 0))
355 (let ((max-width (string-width str))
360 (if (>= width max-width)
361 (setq width max-width))
362 (if (>= start-column width)
364 (while (< column start-column)
365 (setq ch (aref str from)
366 column (+ column (char-width ch))
367 from (+ from (char-bytes ch))))
368 (if (< width max-width)
371 (while (<= column width)
372 (setq ch (aref str to)
373 column (+ column (char-width ch))
375 to (+ to (char-bytes ch))))
377 (substring str from to))))
381 (defalias 'looking-at-as-unibyte 'looking-at)
387 (defun regulate-latin-char (chr)
388 (cond ((and (<= ?
\e$B#A
\e(B chr)(<= chr ?
\e$B#Z
\e(B))
389 (+ (- chr ?
\e$B#A
\e(B) ?A)
391 ((and (<= ?
\e$B#a
\e(B chr)(<= chr ?
\e$B#z
\e(B))
392 (+ (- chr ?
\e$B#a
\e(B) ?a)
394 ((eq chr ?
\e$B!%
\e(B) ?.)
395 ((eq chr ?
\e$B!$
\e(B) ?,)
399 (defun regulate-latin-string (str)
400 (let ((len (length str))
404 (setq chr (sref str i))
405 (setq dest (concat dest
406 (char-to-string (regulate-latin-char chr))))
407 (setq i (+ i (char-bytes chr)))
417 ;;; emu-mule.el ends here