1 ;;; emu-nemacs.el --- emu API implementation for NEmacs
3 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, NEmacs, mule
8 ;; This file is part of emu.
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.
33 ;;; @@ for old MULE emulation
40 (defconst *internal* 3)
41 (defconst *euc-japan* 3)
43 (defun code-convert-string (str ic oc)
44 "Convert code in STRING from SOURCE code to TARGET code,
45 On successful converion, returns the result string,
46 else returns nil. [emu-nemacs.el; Mule emulating function]"
48 (convert-string-kanji-code str ic oc)
51 (defun code-convert-region (beg end ic oc)
52 "Convert code of the text between BEGIN and END from SOURCE
53 to TARGET. On successful conversion returns t,
54 else returns nil. [emu-nemacs.el; Mule emulating function]"
58 (narrow-to-region beg end)
59 (convert-region-kanji-code beg end ic oc)))
63 ;;; @ without code-conversion
66 (fset 'insert-binary-file-contents 'insert-file-contents-as-binary)
68 (defun insert-binary-file-contents-literally (filename
69 &optional visit beg end replace)
70 "Like `insert-file-contents-literally', q.v., but don't code conversion.
71 A buffer may be modified in several ways after reading into the buffer due
72 to advanced Emacs features, such as file-name-handlers, format decoding,
74 This function ensures that none of these modifications will take place.
77 ;; Returns list absolute file name and length of data inserted.
78 (insert-file-contents-literally filename visit beg end replace)))
84 (defvar charsets-mime-charset-alist
85 '(((ascii) . us-ascii)))
87 (defvar default-mime-charset 'iso-2022-jp)
89 (defvar mime-charset-coding-system-alist
94 (defun mime-charset-to-coding-system (charset)
96 (setq charset (intern (downcase charset)))
98 (cdr (assq charset mime-charset-coding-system-alist)))
100 (defun detect-mime-charset-region (start end)
101 "Return MIME charset for region between START and END.
105 (narrow-to-region start end)
107 (re-search-forward "[\200-\377]" nil t)))
111 (defun encode-mime-charset-region (start end charset)
112 "Encode the text between START and END as MIME CHARSET.
114 (let ((cs (mime-charset-to-coding-system charset)))
119 (narrow-to-region start end)
120 (convert-region-kanji-code start end 3 cs))))
123 (defun decode-mime-charset-region (start end charset &optional lbt)
124 "Decode the text between START and END as MIME CHARSET.
126 (let ((cs (mime-charset-to-coding-system charset))
127 (nl (cdr (assq lbt '((CRLF . "\r\n") (CR . "\r")
128 (dos . "\r\n") (mac . "\r"))))))
133 (narrow-to-region start end)
134 (convert-region-kanji-code start end cs 3)
137 (goto-char (point-min))
138 (while (search-forward nl nil t)
139 (replace-match "\n")))
143 (defun encode-mime-charset-string (string charset)
144 "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
145 (let ((cs (mime-charset-to-coding-system charset)))
147 (convert-string-kanji-code string 3 cs)
150 (defun decode-mime-charset-string (string charset &optional lbt)
151 "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
154 (decode-mime-charset-region (point-min)(point-max) charset lbt)
157 (defun write-region-as-mime-charset (charset start end filename)
158 "Like `write-region', q.v., but code-convert by MIME CHARSET.
160 (let ((kanji-fileio-code
161 (or (mime-charset-to-coding-system charset)
163 (write-region start end filename)))
169 (provide 'emu-nemacs)
171 ;;; emu-nemacs.el ends here