source: projects/emacsen-common/trunk/apel-sample/usr/share/emacs/site-lisp/apel/mcharset.el @ 7238

Revision 7238, 3.4 KB checked in by daisuke, 12 years ago (diff)

import emacsen-common

Line 
1;;; mcharset.el --- MIME charset API
2
3;; Copyright (C) 1997,1998,1999,2000 Free Software Foundation, Inc.
4
5;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6;; Keywords: emulation, compatibility, Mule
7
8;; This file is part of APEL (A Portable Emacs Library).
9
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.
14
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.
19
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.
24
25;;; Code:
26
27(require 'poe)
28(require 'pcustom)
29
30(cond ((featurep 'mule)
31       (if (>= emacs-major-version 20)
32           (require 'mcs-20)
33         ;; for MULE 1.* and 2.*
34         (require 'mcs-om)))
35      ((boundp 'NEMACS)
36       ;; for Nemacs and Nepoch
37       (require 'mcs-nemacs))
38      (t
39       (require 'mcs-ltn1)))
40
41(defcustom default-mime-charset-for-write
42  (if (mime-charset-p 'utf-8)
43      'utf-8
44    default-mime-charset)
45  "Default value of MIME-charset for encoding.
46It may be used when suitable MIME-charset is not found.
47It must be symbol."
48  :group 'i18n
49  :type 'mime-charset)
50
51(defcustom default-mime-charset-detect-method-for-write
52  nil
53  "Function called when suitable MIME-charset is not found to encode.
54It must be nil or function.
55If it is nil, variable `default-mime-charset-for-write' is used.
56If it is a function, interface must be (TYPE CHARSETS &rest ARGS).
57CHARSETS is list of charset.
58If TYPE is 'region, ARGS has START and END."
59  :group 'i18n
60  :type '(choice function (const nil)))
61
62(defun charsets-to-mime-charset (charsets)
63  "Return MIME charset from list of charset CHARSETS.
64Return nil if suitable mime-charset is not found."
65  (if charsets
66      (catch 'tag
67        (let ((rest charsets-mime-charset-alist)
68              cell)
69          (while (setq cell (car rest))
70            (if (catch 'not-subset
71                  (let ((set1 charsets)
72                        (set2 (car cell))
73                        obj)
74                    (while set1
75                      (setq obj (car set1))
76                      (or (memq obj set2)
77                          (throw 'not-subset nil))
78                      (setq set1 (cdr set1)))
79                    t))
80                (throw 'tag (cdr cell)))
81            (setq rest (cdr rest)))
82          ))))
83
84(defun find-mime-charset-by-charsets (charsets &optional mode &rest args)
85  "Like `charsets-to-mime-charset', but it does not return nil.
86
87When suitable mime-charset is not found and variable
88`default-mime-charset-detect-method-for-write' is not nil,
89`find-mime-charset-by-charsets' calls the variable as function and
90return the return value of the function.
91Interface of the function is (MODE CHARSETS &rest ARGS).
92
93When suitable mime-charset is not found and variable
94`default-mime-charset-detect-method-for-write' is nil,
95variable `default-mime-charset-for-write' is returned."
96  (or (charsets-to-mime-charset charsets)
97      (if default-mime-charset-detect-method-for-write
98          (apply default-mime-charset-detect-method-for-write
99                 mode charsets args)
100        default-mime-charset-for-write)))
101
102
103;;; @ end
104;;;
105
106(require 'product)
107(product-provide (provide 'mcharset) (require 'apel-ver))
108
109;;; mcharset.el ends here
Note: See TracBrowser for help on using the repository browser.