APEL 3.4.2.
[elisp/apel.git] / emu-20.el
1 ;;; emu-20.el --- emu API implementation for Emacs 20 and XEmacs/mule
2
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-20.el,v 7.15 1997/09/07 02:57:51 morioka Exp $
7 ;; Keywords: emulation, compatibility, Mule
8
9 ;; This file is part of emu.
10
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.
15
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.
20
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.
25
26 ;;; Commentary:
27
28 ;;    This module requires Emacs 20.0.93, XEmacs 20.3-b5 (with mule)
29 ;;    or later.
30
31 ;;; Code:
32
33 ;;; @ binary access
34 ;;;
35
36 (defmacro as-binary-process (&rest body)
37   `(let (selective-display      ; Disable ^M to nl translation.
38          (coding-system-for-read  'binary)
39          (coding-system-for-write 'binary))
40      ,@body))
41
42 (defmacro as-binary-input-file (&rest body)
43   `(let ((coding-system-for-read 'binary))
44      ,@body))
45
46 (defmacro as-binary-output-file (&rest body)
47   `(let ((coding-system-for-write 'binary))
48      ,@body))
49
50 (defun insert-binary-file-contents-literally
51   (filename &optional visit beg end replace)
52   "Like `insert-file-contents-literally', q.v., but don't code conversion.
53 A buffer may be modified in several ways after reading into the buffer due
54 to advanced Emacs features, such as file-name-handlers, format decoding,
55 find-file-hooks, etc.
56   This function ensures that none of these modifications will take place."
57   (let ((coding-system-for-read 'binary))
58     (insert-file-contents-literally filename visit beg end replace)
59     ))
60
61 ;;; @@ Mule emulating aliases
62 ;;;
63 ;;; You should not use it.
64
65 (defconst *noconv* 'binary
66   "Coding-system for binary.
67 This constant is defined to emulate old MULE anything older than MULE
68 2.3.  It is obsolete, so don't use it.")
69
70
71 ;;; @ MIME charset
72 ;;;
73
74 (defvar mime-charset-coding-system-alist
75   `,(let ((rest
76            '((us-ascii      . iso-8859-1)
77              (gb2312        . cn-gb-2312)
78              (iso-2022-jp-2 . iso-2022-7bit-ss2)
79              (x-ctext       . ctext)
80              ))
81           dest)
82       (while rest
83         (let ((pair (car rest)))
84           (or (find-coding-system (car pair))
85               (setq dest (cons pair dest))
86               ))
87         (setq rest (cdr rest))
88         )
89       dest)
90   "Alist MIME CHARSET vs CODING-SYSTEM.
91 MIME CHARSET and CODING-SYSTEM must be symbol.")
92
93 (defsubst mime-charset-to-coding-system (charset &optional lbt)
94   "Return coding-system corresponding with CHARSET.
95 CHARSET is a symbol whose name is MIME charset.
96 If optional argument LBT (`unix', `dos' or `mac') is specified, it is
97 used as line break code type of coding-system."
98   (if (stringp charset)
99       (setq charset (intern (downcase charset)))
100     )
101   (let ((ret (assq charset mime-charset-coding-system-alist)))
102     (if ret
103         (setq charset (cdr ret))
104       ))
105   (if lbt
106       (setq charset (intern (format "%s-%s" charset lbt)))
107     )
108   (if (find-coding-system charset)
109       charset))
110
111 (defsubst encode-mime-charset-region (start end charset)
112   "Encode the text between START and END as MIME CHARSET."
113   (let ((cs (mime-charset-to-coding-system charset)))
114     (if cs
115         (encode-coding-region start end cs)
116       )))
117
118 (defsubst decode-mime-charset-region (start end charset)
119   "Decode the text between START and END as MIME CHARSET."
120   (let ((cs (mime-charset-to-coding-system charset)))
121     (if cs
122         (decode-coding-region start end cs)
123       )))
124
125 (defsubst encode-mime-charset-string (string charset)
126   "Encode the STRING as MIME CHARSET."
127   (let ((cs (mime-charset-to-coding-system charset)))
128     (if cs
129         (encode-coding-string string cs)
130       string)))
131
132 (defsubst decode-mime-charset-string (string charset)
133   "Decode the STRING as MIME CHARSET."
134   (let ((cs (mime-charset-to-coding-system charset)))
135     (if cs
136         (decode-coding-string string cs)
137       string)))
138
139
140 (defvar default-mime-charset 'x-ctext
141   "Default value of MIME charset used when MIME charset is not specified.
142 It must be symbol.")
143
144 (defsubst detect-mime-charset-region (start end)
145   "Return MIME charset for region between START and END."
146   (charsets-to-mime-charset (find-charset-region start end)))
147
148
149 ;;; @ end
150 ;;;
151
152 (provide 'emu-20)
153
154 ;;; emu-20.el ends here