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))
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)
61 ;;; @@ Mule emulating aliases
63 ;;; You should not use it.
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.")
74 (defcustom mime-charset-coding-system-alist
76 '((us-ascii . raw-text)
78 (iso-2022-jp-2 . iso-2022-7bit-ss2)
83 (let ((pair (car rest)))
84 (or (find-coding-system (car pair))
85 (setq dest (cons pair dest))
87 (setq rest (cdr rest))
90 "Alist MIME CHARSET vs CODING-SYSTEM.
91 MIME CHARSET and CODING-SYSTEM must be symbol."
93 :type '(repeat (cons symbol coding-system)))
95 (defsubst mime-charset-to-coding-system (charset &optional lbt)
96 "Return coding-system corresponding with CHARSET.
97 CHARSET is a symbol whose name is MIME charset.
98 If optional argument LBT (`unix', `dos' or `mac') is specified, it is
99 used as line break code type of coding-system."
100 (if (stringp charset)
101 (setq charset (intern (downcase charset)))
103 (let ((ret (assq charset mime-charset-coding-system-alist)))
105 (setq charset (cdr ret))
108 (setq charset (intern (format "%s-%s" charset lbt)))
110 (if (find-coding-system charset)
113 (defsubst mime-charset-list ()
114 "Return a list of all existing MIME-charset."
115 (nconc (mapcar (function car) mime-charset-coding-system-alist)
116 (coding-system-list)))
119 (defvar widget-mime-charset-prompt-value-history nil
120 "History of input to `widget-mime-charset-prompt-value'.")
122 (define-widget 'mime-charset 'coding-system
126 :prompt-history 'widget-mime-charset-prompt-value-history
127 :prompt-value 'widget-mime-charset-prompt-value
128 :action 'widget-mime-charset-action)
130 (defun widget-mime-charset-prompt-value (widget prompt value unbound)
131 ;; Read mime-charset from minibuffer.
133 (completing-read (format "%s (default %s) " prompt value)
136 (list (symbol-name sym))
138 (mime-charset-list)))))
140 (defun widget-mime-charset-action (widget &optional event)
141 ;; Read a mime-charset from the minibuffer.
143 (widget-mime-charset-prompt-value
145 (widget-apply widget :menu-tag-get)
146 (widget-value widget)
148 (widget-value-set widget answer)
149 (widget-apply widget :notify widget event)
152 (defcustom default-mime-charset 'x-ctext
153 "Default value of MIME-charset.
154 It is used when MIME-charset is not specified.
159 (defsubst detect-mime-charset-region (start end)
160 "Return MIME charset for region between START and END."
161 (charsets-to-mime-charset (find-charset-region start end)))
163 (defun write-region-as-mime-charset (charset start end filename
164 &optional append visit lockname)
165 "Like `write-region', q.v., but encode by MIME CHARSET."
166 (let ((coding-system-for-write
167 (or (mime-charset-to-coding-system charset)
169 (write-region start end filename append visit lockname)
178 ;;; emu-20.el ends here