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 insert-binary-file-contents (filename &optional visit beg end replace)
64 "Like `insert-file-contents', q.v., but don't code and format conversion."
65 (let ((coding-system-for-read 'binary)
67 (insert-file-contents filename visit beg end replace)
70 (defun write-region-as-binary (start end filename
71 &optional append visit lockname)
72 "Like `write-region', q.v., but don't code conversion."
73 (let ((coding-system-for-read 'binary))
74 (write-region start end filename append visit lockname)
78 ;;; @@ Mule emulating aliases
80 ;;; You should not use it.
82 (defconst *noconv* 'binary
83 "Coding-system for binary.
84 This constant is defined to emulate old MULE anything older than MULE
85 2.3. It is obsolete, so don't use it.")
91 (defvar mime-charset-coding-system-alist
93 '((us-ascii . iso-8859-1)
95 (iso-2022-jp-2 . iso-2022-7bit-ss2)
100 (let ((pair (car rest)))
101 (or (find-coding-system (car pair))
102 (setq dest (cons pair dest))
104 (setq rest (cdr rest))
107 "Alist MIME CHARSET vs CODING-SYSTEM.
108 MIME CHARSET and CODING-SYSTEM must be symbol.")
110 (defsubst mime-charset-to-coding-system (charset &optional lbt)
111 "Return coding-system corresponding with CHARSET.
112 CHARSET is a symbol whose name is MIME charset.
113 If optional argument LBT (`unix', `dos' or `mac') is specified, it is
114 used as line break code type of coding-system."
115 (if (stringp charset)
116 (setq charset (intern (downcase charset)))
118 (let ((ret (assq charset mime-charset-coding-system-alist)))
120 (setq charset (cdr ret))
123 (setq charset (intern (format "%s-%s" charset lbt)))
125 (if (find-coding-system charset)
128 (defsubst mime-charset-list ()
129 "Return a list of all existing MIME-charset."
130 (nconc (mapcar (function car) mime-charset-coding-system-alist)
131 (coding-system-list)))
134 (defvar widget-mime-charset-prompt-value-history nil
135 "History of input to `widget-mime-charset-prompt-value'.")
137 (define-widget 'mime-charset 'coding-system
141 :prompt-history 'widget-mime-charset-prompt-value-history
142 :prompt-value 'widget-mime-charset-prompt-value
143 :action 'widget-mime-charset-action)
145 (defun widget-mime-charset-prompt-value (widget prompt value unbound)
146 ;; Read mime-charset from minibuffer.
148 (completing-read (format "%s (default %s) " prompt value)
151 (list (symbol-name sym))
153 (mime-charset-list)))))
155 (defun widget-mime-charset-action (widget &optional event)
156 ;; Read a mime-charset from the minibuffer.
158 (widget-mime-charset-prompt-value
160 (widget-apply widget :menu-tag-get)
161 (widget-value widget)
163 (widget-value-set widget answer)
164 (widget-apply widget :notify widget event)
167 (defcustom default-mime-charset 'x-ctext
168 "Default value of MIME-charset.
169 It is used when MIME-charset is not specified.
174 (defsubst detect-mime-charset-region (start end)
175 "Return MIME charset for region between START and END."
176 (charsets-to-mime-charset (find-charset-region start end)))
184 ;;; emu-20.el ends here