1 ;;; mcs-20.el --- MIME charset 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 APEL (A Portable Emacs Library).
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)
34 (eval-when-compile (require 'wid-edit))
40 (defcustom mime-charset-coding-system-alist
42 '((us-ascii . raw-text)
44 (iso-2022-jp-2 . iso-2022-7bit-ss2)
47 (x-unknown . undecided)
51 (let ((pair (car rest)))
52 (or (find-coding-system (car pair))
53 (setq dest (cons pair dest))
55 (setq rest (cdr rest))
58 "Alist MIME CHARSET vs CODING-SYSTEM.
59 MIME CHARSET and CODING-SYSTEM must be symbol."
61 :type '(repeat (cons symbol coding-system)))
63 (defsubst mime-charset-to-coding-system (charset &optional lbt)
64 "Return coding-system corresponding with CHARSET.
65 CHARSET is a symbol whose name is MIME charset.
66 If optional argument LBT (`CRLF', `LF', `CR', `unix', `dos' or `mac')
67 is specified, it is used as line break code type of coding-system."
69 (setq charset (intern (downcase charset)))
71 (let ((ret (assq charset mime-charset-coding-system-alist)))
73 (setq charset (cdr ret))
76 (setq charset (intern (format "%s-%s" charset
77 (cond ((eq lbt 'CRLF) 'dos)
82 (if (find-coding-system charset)
86 (defsubst mime-charset-list ()
87 "Return a list of all existing MIME-charset."
88 (nconc (mapcar (function car) mime-charset-coding-system-alist)
89 (coding-system-list)))
92 (defvar widget-mime-charset-prompt-value-history nil
93 "History of input to `widget-mime-charset-prompt-value'.")
95 (define-widget 'mime-charset 'coding-system
99 :prompt-history 'widget-mime-charset-prompt-value-history
100 :prompt-value 'widget-mime-charset-prompt-value
101 :action 'widget-mime-charset-action)
103 (defun widget-mime-charset-prompt-value (widget prompt value unbound)
104 ;; Read mime-charset from minibuffer.
106 (completing-read (format "%s (default %s) " prompt value)
109 (list (symbol-name sym))))
110 (mime-charset-list)))))
112 (defun widget-mime-charset-action (widget &optional event)
113 ;; Read a mime-charset from the minibuffer.
115 (widget-mime-charset-prompt-value
117 (widget-apply widget :menu-tag-get)
118 (widget-value widget)
120 (widget-value-set widget answer)
121 (widget-apply widget :notify widget event)
124 (defcustom default-mime-charset 'x-ctext
125 "Default value of MIME-charset.
126 It is used when MIME-charset is not specified.
131 (defsubst detect-mime-charset-region (start end)
132 "Return MIME charset for region between START and END."
133 (charsets-to-mime-charset (find-charset-region start end)))
135 (defun write-region-as-mime-charset (charset start end filename
136 &optional append visit lockname)
137 "Like `write-region', q.v., but encode by MIME CHARSET."
138 (let ((coding-system-for-write
139 (or (mime-charset-to-coding-system charset)
141 (write-region start end filename append visit lockname)))
149 ;;; mcs-20.el ends here