1 ;;; mcharset.el --- MIME charset API
3 ;; Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
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.
30 (cond ((featurep 'mule)
31 (cond ((featurep 'xemacs)
34 ((>= emacs-major-version 20)
38 ;; for MULE 1.* and 2.*
43 ;; for Nemacs and Nepoch
50 (defcustom default-mime-charset-for-write
51 (if (and (fboundp 'find-coding-system)
52 (find-coding-system 'utf-8))
55 "Default value of MIME-charset for encoding.
56 It may be used when suitable MIME-charset is not found.
61 (defcustom default-mime-charset-detect-method-for-write
63 "Function called when suitable MIME-charset is not found to encode.
64 It must be nil or function.
65 If it is nil, variable `default-mime-charset-for-write' is used.
66 If it is a function, interface must be (TYPE CHARSETS &rest ARGS).
67 CHARSETS is list of charset.
68 If TYPE is 'region, ARGS has START and END."
70 :type '(choice function (const nil)))
72 (defun charsets-to-mime-charset (charsets)
73 "Return MIME charset from list of charset CHARSETS.
74 Return nil if suitable mime-charset is not found."
77 (let ((rest charsets-mime-charset-alist)
79 (while (setq cell (car rest))
80 (if (catch 'not-subset
87 (throw 'not-subset nil))
88 (setq set1 (cdr set1)))
90 (throw 'tag (cdr cell)))
91 (setq rest (cdr rest)))
94 (defun find-mime-charset-by-charsets (charsets &optional mode &rest args)
95 "Like `charsets-to-mime-charset', but it does not return nil.
97 When suitable mime-charset is not found and variable
98 `default-mime-charset-detect-method-for-write' is not nil,
99 `find-mime-charset-by-charsets' calls the variable as function and
100 return the return value of the function.
101 Interface of the function is (MODE CHARSETS &rest ARGS).
103 When suitable mime-charset is not found and variable
104 `default-mime-charset-detect-method-for-write' is nil,
105 variable `default-mime-charset-for-write' is returned."
106 (or (charsets-to-mime-charset charsets)
107 (if default-mime-charset-detect-method-for-write
108 (apply default-mime-charset-detect-method-for-write
110 default-mime-charset-for-write)))
118 ;;; mcharset.el ends here