1 ;;; mcs-nemacs.el --- MIME charset implementation for Nemacs
3 ;; Copyright (C) 1995,1996,1997,1998,2000 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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 (defvar charsets-mime-charset-alist
28 '(((ascii) . us-ascii)))
30 (defvar default-mime-charset 'iso-2022-jp)
32 (defvar mime-charset-coding-system-alist
37 (defsubst lbt-to-string (lbt)
38 (cdr (assq lbt '((nil . nil)
45 (defun mime-charset-to-coding-system (charset &optional lbt)
47 (setq charset (intern (downcase charset)))
49 (cdr (assq charset mime-charset-coding-system-alist)))
51 (fset 'mime-charset-p 'mime-charset-to-coding-system)
53 (defun detect-mime-charset-region (start end)
54 "Return MIME charset for region between START and END.
58 (narrow-to-region start end)
60 (re-search-forward "[\200-\377]" nil t)))
64 (defun encode-mime-charset-region (start end charset &optional lbt)
65 "Encode the text between START and END as MIME CHARSET.
67 (let ((cs (mime-charset-to-coding-system charset))
68 (nl (lbt-to-string lbt)))
73 (narrow-to-region start end)
74 (convert-region-kanji-code start end 3 cs)
77 (goto-char (point-min))
78 (while (search-forward "\n" nil t)
83 (defun decode-mime-charset-region (start end charset &optional lbt)
84 "Decode the text between START and END as MIME CHARSET.
86 (let ((cs (mime-charset-to-coding-system charset))
87 (nl (lbt-to-string lbt)))
92 (narrow-to-region start end)
93 (convert-region-kanji-code start end cs 3)
96 (goto-char (point-min))
97 (while (search-forward nl nil t)
98 (replace-match "\n")))
102 (defun encode-mime-charset-string (string charset &optional lbt)
103 "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
106 (encode-mime-charset-region (point-min)(point-max) charset lbt)
109 (defun decode-mime-charset-string (string charset &optional lbt)
110 "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
113 (decode-mime-charset-region (point-min)(point-max) charset lbt)
116 (defun write-region-as-mime-charset (charset start end filename)
117 "Like `write-region', q.v., but code-convert by MIME CHARSET.
119 (let ((kanji-fileio-code
120 (or (mime-charset-to-coding-system charset) 0)))
121 (write-region start end filename)))
128 (product-provide (provide 'mcs-nemacs) (require 'apel-ver))
130 ;;; mcs-nemacs.el ends here