1 ;;; emu-20.el --- emu API implementation for Emacs 20 and XEmacs/mule
3 ;; Copyright (C) 1997,1998 Free Software Foundation, Inc.
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 ;; This module requires Emacs 20.0.93, XEmacs 20.3-b5 (with mule)
33 (eval-when-compile (require 'wid-edit))
36 ;;; @ without code-conversion
39 (defmacro as-binary-process (&rest body)
40 `(let (selective-display ; Disable ^M to nl translation.
41 (coding-system-for-read 'binary)
42 (coding-system-for-write 'binary))
45 (defmacro as-binary-input-file (&rest body)
46 `(let ((coding-system-for-read 'binary))
49 (defmacro as-binary-output-file (&rest body)
50 `(let ((coding-system-for-write 'binary))
53 (defun write-region-as-binary (start end filename
54 &optional append visit lockname)
55 "Like `write-region', q.v., but don't encode."
56 (let ((coding-system-for-write 'binary))
57 (write-region start end filename append visit lockname)
60 (defun insert-file-contents-as-binary (filename
61 &optional visit beg end replace)
62 "Like `insert-file-contents', q.v., but don't code and format conversion.
63 Like `insert-file-contents-literary', but it allows find-file-hooks,
64 automatic uncompression, etc.
66 Namely this function ensures that only format decoding and character
67 code conversion will not take place."
68 (let ((coding-system-for-read 'binary)
70 (insert-file-contents filename visit beg end replace)
73 (defun insert-file-contents-as-raw-text (filename
74 &optional visit beg end replace)
75 "Like `insert-file-contents', q.v., but don't code and format conversion.
76 Like `insert-file-contents-literary', but it allows find-file-hooks,
77 automatic uncompression, etc.
78 Like `insert-file-contents-as-binary', but it converts line-break
80 (let ((coding-system-for-read 'raw-text)
82 (insert-file-contents filename visit beg end replace)
86 ;;; @@ Mule emulating aliases
88 ;;; You should not use it.
90 (defconst *noconv* 'binary
91 "Coding-system for binary.
92 This constant is defined to emulate old MULE anything older than MULE
93 2.3. It is obsolete, so don't use it.")
99 (defcustom mime-charset-coding-system-alist
101 '((us-ascii . raw-text)
102 (gb2312 . cn-gb-2312)
103 (iso-2022-jp-2 . iso-2022-7bit-ss2)
108 (let ((pair (car rest)))
109 (or (find-coding-system (car pair))
110 (setq dest (cons pair dest))
112 (setq rest (cdr rest))
115 "Alist MIME CHARSET vs CODING-SYSTEM.
116 MIME CHARSET and CODING-SYSTEM must be symbol."
118 :type '(repeat (cons symbol coding-system)))
120 (defsubst mime-charset-to-coding-system (charset &optional lbt)
121 "Return coding-system corresponding with CHARSET.
122 CHARSET is a symbol whose name is MIME charset.
123 If optional argument LBT (`unix', `dos' or `mac') is specified, it is
124 used as line break code type of coding-system."
125 (if (stringp charset)
126 (setq charset (intern (downcase charset)))
128 (let ((ret (assq charset mime-charset-coding-system-alist)))
130 (setq charset (cdr ret))
133 (setq charset (intern (format "%s-%s" charset lbt)))
135 (if (find-coding-system charset)
138 (defsubst mime-charset-list ()
139 "Return a list of all existing MIME-charset."
140 (nconc (mapcar (function car) mime-charset-coding-system-alist)
141 (coding-system-list)))
144 (defvar widget-mime-charset-prompt-value-history nil
145 "History of input to `widget-mime-charset-prompt-value'.")
147 (define-widget 'mime-charset 'coding-system
151 :prompt-history 'widget-mime-charset-prompt-value-history
152 :prompt-value 'widget-mime-charset-prompt-value
153 :action 'widget-mime-charset-action)
155 (defun widget-mime-charset-prompt-value (widget prompt value unbound)
156 ;; Read mime-charset from minibuffer.
158 (completing-read (format "%s (default %s) " prompt value)
161 (list (symbol-name sym))
163 (mime-charset-list)))))
165 (defun widget-mime-charset-action (widget &optional event)
166 ;; Read a mime-charset from the minibuffer.
168 (widget-mime-charset-prompt-value
170 (widget-apply widget :menu-tag-get)
171 (widget-value widget)
173 (widget-value-set widget answer)
174 (widget-apply widget :notify widget event)
177 (defcustom default-mime-charset 'x-ctext
178 "Default value of MIME-charset.
179 It is used when MIME-charset is not specified.
184 (defsubst detect-mime-charset-region (start end)
185 "Return MIME charset for region between START and END."
186 (charsets-to-mime-charset (find-charset-region start end)))
188 (defun write-region-as-mime-charset (charset start end filename
189 &optional append visit lockname)
190 "Like `write-region', q.v., but encode by MIME CHARSET."
191 (let ((coding-system-for-write
192 (or (mime-charset-to-coding-system charset)
194 (write-region start end filename append visit lockname)
203 ;;; emu-20.el ends here