1 ;;; mcs-nemacs.el --- MIME charset implementation for Nemacs
3 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
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 (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)
47 (setq charset (intern (downcase charset)))
49 (cdr (assq charset mime-charset-coding-system-alist)))
51 (defun detect-mime-charset-region (start end)
52 "Return MIME charset for region between START and END.
56 (narrow-to-region start end)
58 (re-search-forward "[\200-\377]" nil t)))
62 (defun encode-mime-charset-region (start end charset &optional lbt)
63 "Encode the text between START and END as MIME CHARSET.
65 (let ((cs (mime-charset-to-coding-system charset))
66 (nl (lbt-to-string lbt)))
71 (narrow-to-region start end)
72 (convert-region-kanji-code start end 3 cs)
75 (goto-char (point-min))
76 (while (search-forward "\n" nil t)
81 (defun decode-mime-charset-region (start end charset &optional lbt)
82 "Decode the text between START and END as MIME CHARSET.
84 (let ((cs (mime-charset-to-coding-system charset))
85 (nl (lbt-to-string lbt)))
90 (narrow-to-region start end)
91 (convert-region-kanji-code start end cs 3)
94 (goto-char (point-min))
95 (while (search-forward nl nil t)
96 (replace-match "\n")))
100 (defun encode-mime-charset-string (string charset &optional lbt)
101 "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
104 (encode-mime-charset-region (point-min)(point-max) charset lbt)
107 (defun decode-mime-charset-string (string charset &optional lbt)
108 "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
111 (decode-mime-charset-region (point-min)(point-max) charset lbt)
114 (defun write-region-as-mime-charset (charset start end filename)
115 "Like `write-region', q.v., but code-convert by MIME CHARSET.
117 (let ((kanji-fileio-code
118 (or (mime-charset-to-coding-system charset) 0)))
119 (write-region start end filename)))
125 (provide 'mcs-nemacs)
127 ;;; mcs-nemacs.el ends here