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)
38 (defmacro as-binary-process (&rest body)
39 `(let (selective-display ; Disable ^M to nl translation.
40 (coding-system-for-read 'binary)
41 (coding-system-for-write 'binary))
44 (defmacro as-binary-input-file (&rest body)
45 `(let ((coding-system-for-read 'binary))
48 (defmacro as-binary-output-file (&rest body)
49 `(let ((coding-system-for-write 'binary))
52 (defun insert-binary-file-contents-literally (filename
53 &optional visit beg end replace)
54 "Like `insert-file-contents-literally', q.v., but don't code conversion.
55 A buffer may be modified in several ways after reading into the buffer due
56 to advanced Emacs features, such as file-name-handlers, format decoding,
58 This function ensures that none of these modifications will take place."
59 (let ((coding-system-for-read 'binary))
60 (insert-file-contents-literally filename visit beg end replace)
63 (defun write-region-as-binary (start end filename
64 &optional append visit lockname)
65 "Like `write-region', q.v., but don't code conversion."
66 (let ((coding-system-for-read 'binary))
67 (write-region start end filename append visit lockname)
71 ;;; @@ Mule emulating aliases
73 ;;; You should not use it.
75 (defconst *noconv* 'binary
76 "Coding-system for binary.
77 This constant is defined to emulate old MULE anything older than MULE
78 2.3. It is obsolete, so don't use it.")
84 (defvar mime-charset-coding-system-alist
86 '((us-ascii . iso-8859-1)
88 (iso-2022-jp-2 . iso-2022-7bit-ss2)
93 (let ((pair (car rest)))
94 (or (find-coding-system (car pair))
95 (setq dest (cons pair dest))
97 (setq rest (cdr rest))
100 "Alist MIME CHARSET vs CODING-SYSTEM.
101 MIME CHARSET and CODING-SYSTEM must be symbol.")
103 (defsubst mime-charset-to-coding-system (charset &optional lbt)
104 "Return coding-system corresponding with CHARSET.
105 CHARSET is a symbol whose name is MIME charset.
106 If optional argument LBT (`unix', `dos' or `mac') is specified, it is
107 used as line break code type of coding-system."
108 (if (stringp charset)
109 (setq charset (intern (downcase charset)))
111 (let ((ret (assq charset mime-charset-coding-system-alist)))
113 (setq charset (cdr ret))
116 (setq charset (intern (format "%s-%s" charset lbt)))
118 (if (find-coding-system charset)
121 (defsubst mime-charset-list ()
122 "Return a list of all existing MIME-charset."
123 (nconc (mapcar (function car) mime-charset-coding-system-alist)
124 (coding-system-list)))
127 (defvar widget-mime-charset-prompt-value-history nil
128 "History of input to `widget-mime-charset-prompt-value'.")
130 (define-widget 'mime-charset 'coding-system
134 :prompt-history 'widget-mime-charset-prompt-value-history
135 :prompt-value 'widget-mime-charset-prompt-value
136 :action 'widget-mime-charset-action)
138 (defun widget-mime-charset-prompt-value (widget prompt value unbound)
139 ;; Read mime-charset from minibuffer.
141 (completing-read (format "%s (default %s) " prompt value)
144 (list (symbol-name sym))
146 (mime-charset-list)))))
148 (defun widget-mime-charset-action (widget &optional event)
149 ;; Read a mime-charset from the minibuffer.
151 (widget-mime-charset-prompt-value
153 (widget-apply widget :menu-tag-get)
154 (widget-value widget)
156 (widget-value-set widget answer)
157 (widget-apply widget :notify widget event)
160 (defcustom default-mime-charset 'x-ctext
161 "Default value of MIME-charset.
162 It is used when MIME-charset is not specified.
167 (defsubst detect-mime-charset-region (start end)
168 "Return MIME charset for region between START and END."
169 (charsets-to-mime-charset (find-charset-region start end)))
177 ;;; emu-20.el ends here