(write-region-as-binary): New file.
[elisp/apel.git] / emu-nemacs.el
index 385369f..ece9aa1 100644 (file)
@@ -1,31 +1,27 @@
-;;;
-;;; emu-nemacs.el --- Mule 2 emulation module for NEmacs
-;;;
-;;; Copyright (C) 1995 Free Software Foundation, Inc.
-;;; Copyright (C) 1993 .. 1996 MORIOKA Tomohiko
-;;;
-;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;;; modified by KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
-;;; Version:
-;;;    $Id: emu-nemacs.el,v 7.39 1996/07/15 08:24:46 morioka Exp $
-;;; Keywords: emulation, compatibility, NEmacs, Mule
-;;;
-;;; This file is part of tl (Tiny Library).
-;;;
-;;; This program is free software; you can redistribute it and/or
-;;; modify it under the terms of the GNU General Public License as
-;;; published by the Free Software Foundation; either version 2, or
-;;; (at your option) any later version.
-;;;
-;;; This program is distributed in the hope that it will be useful,
-;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-;;; General Public License for more details.
-;;;
-;;; You should have received a copy of the GNU General Public License
-;;; along with This program.  If not, write to the Free Software
-;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-;;;
+;;; emu-nemacs.el --- emu API implementation for NEmacs
+
+;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
+
+;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;; Keywords: emulation, compatibility, NEmacs, mule
+
+;; This file is part of emu.
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2, or (at
+;; your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
 ;;; Code:
 
 (require 'emu-18)
@@ -69,6 +65,8 @@
       (list lc-jp)
     ))
 
+(defalias 'find-non-ascii-charset-string 'find-charset-string)
+
 (defun find-charset-region (start end)
   "Return a list of charsets in the region between START and END.
 \[emu-nemacs.el; Mule emulating function]"
@@ -81,6 +79,8 @@
       (list lc-jp)
     ))
 
+(defalias 'find-non-ascii-charset-region 'find-charset-region)
+
 (defun check-ASCII-string (str)
   (let ((i 0)
        len)
@@ -93,7 +93,7 @@
        )
       str)))
 
-;;; @@ for Mule emulation
+;;; @@ for old MULE emulation
 ;;;
 
 (defconst lc-ascii 0)
 (defconst *internal*  3)
 (defconst *euc-japan* 3)
 
-(defun code-convert-string (str ic oc)
-  "Convert code in STRING from SOURCE code to TARGET code,
-On successful converion, returns the result string,
-else returns nil. [emu-nemacs.el; Mule emulating function]"
-  (if (not (eq ic oc))
-      (convert-string-kanji-code str ic oc)
-    str))
+(defun decode-coding-string (string coding-system)
+  "Decode the STRING which is encoded in CODING-SYSTEM.
+\[emu-nemacs.el; EMACS 20 emulating function]"
+  (if (eq coding-system 3)
+      string
+    (convert-string-kanji-code string coding-system 3)
+    ))
 
-(defun code-convert-region (beg end ic oc)
-  "Convert code of the text between BEGIN and END from SOURCE
-to TARGET. On successful conversion returns t,
-else returns nil. [emu-nemacs.el; Mule emulating function]"
+(defun encode-coding-string (string coding-system)
+  "Encode the STRING to CODING-SYSTEM.
+\[emu-nemacs.el; EMACS 20 emulating function]"
+  (if (eq coding-system 3)
+      string
+    (convert-string-kanji-code string 3 coding-system)
+    ))
+
+(defun decode-coding-region (start end coding-system)
+  "Decode the text between START and END which is encoded in CODING-SYSTEM.
+\[emu-nemacs.el; EMACS 20 emulating function]"
   (if (/= ic oc)
       (save-excursion
        (save-restriction
-         (narrow-to-region beg end)
-         (convert-region-kanji-code beg end ic oc)
+         (narrow-to-region start end)
+         (convert-region-kanji-code start end coding-system 3)
+         ))))
+
+(defun encode-coding-region (start end coding-system)
+  "Encode the text between START and END to CODING-SYSTEM.
+\[emu-nemacs.el; EMACS 20 emulating function]"
+  (if (/= ic oc)
+      (save-excursion
+       (save-restriction
+         (narrow-to-region start end)
+         (convert-region-kanji-code start end 3 coding-system)
          ))))
 
-(defun code-detect-region (start end)
+(defun detect-coding-region (start end)
   "Detect coding-system of the text in the region between START and END.
-\[emu-nemacs.el; Mule emulating function]"
+\[emu-nemacs.el; Emacs 20 emulating function]"
   (if (save-excursion
        (save-restriction
          (narrow-to-region start end)
@@ -141,9 +158,7 @@ else returns nil. [emu-nemacs.el; Mule emulating function]"
       *euc-japan*
     ))
 
-(defun set-file-coding-system (coding-system &optional force)
-  (set-kanji-fileio-code coding-system)
-  )
+(defalias 'set-buffer-file-coding-system 'set-kanji-fileio-code)
 
 (defmacro as-binary-process (&rest body)
   (` (let (selective-display   ; Disable ^M to nl translation.
@@ -154,6 +169,63 @@ else returns nil. [emu-nemacs.el; Mule emulating function]"
        (,@ body)
        )))
 
+(defmacro as-binary-input-file (&rest body)
+  (` (let (kanji-flag)
+       (,@ body)
+       )))
+
+(defmacro as-binary-output-file (&rest body)
+  (` (let (kanji-flag)
+       (,@ body)
+       )))
+
+
+;;; @@ for old MULE emulation
+;;;
+
+(defun code-convert-string (str ic oc)
+  "Convert code in STRING from SOURCE code to TARGET code,
+On successful converion, returns the result string,
+else returns nil. [emu-nemacs.el; Mule emulating function]"
+  (if (not (eq ic oc))
+      (convert-string-kanji-code str ic oc)
+    str))
+
+(defun code-convert-region (beg end ic oc)
+  "Convert code of the text between BEGIN and END from SOURCE
+to TARGET. On successful conversion returns t,
+else returns nil. [emu-nemacs.el; Mule emulating function]"
+  (if (/= ic oc)
+      (save-excursion
+       (save-restriction
+         (narrow-to-region beg end)
+         (convert-region-kanji-code beg end ic oc)
+         ))))
+
+
+;;; @ binary access
+;;;
+
+(defun insert-binary-file-contents-literally
+  (filename &optional visit beg end replace)
+  "Like `insert-file-contents-literally', q.v., but don't code conversion.
+A buffer may be modified in several ways after reading into the buffer due
+to advanced Emacs features, such as file-name-handlers, format decoding,
+find-file-hooks, etc.
+  This function ensures that none of these modifications will take place.
+\[emu-nemacs.el]"
+  (let (kanji-flag)
+    (insert-file-contents-literally filename visit beg end replace)
+    ))
+
+(defun insert-binary-file-contents
+  (filename &optional visit beg end replace)
+  "Like `insert-file-contents', q.v., but don't code and format conversion.
+\[emu-nemacs.el]"
+  (let (kanji-flag)
+    (insert-file-contents filename visit beg end replace)
+    ))
+
 
 ;;; @ MIME charset
 ;;;
@@ -330,12 +402,12 @@ Optional non-nil arg START-COLUMN specifies the starting column.
 ;;; @ text property emulation
 ;;;
 
-(setq tl:available-face-attribute-alist
-      '(
-       ;;(bold      . inversed-region)
-       (italic    . underlined-region)
-       (underline . underlined-region)
-       ))
+(defvar emu:available-face-attribute-alist
+  '(
+    ;;(bold      . inversed-region)
+    (italic    . underlined-region)
+    (underline . underlined-region)
+    ))
 
 ;; by YAMATE Keiichirou 1994/10/28
 (defun attribute-add-narrow-attribute (attr from to)
@@ -376,11 +448,11 @@ Optional non-nil arg START-COLUMN specifies the starting column.
       (setcdr (nthcdr posfrom attr-value)
              (nthcdr posto attr-value)))))
 
-(defalias 'tl:make-overlay 'cons)
+(defalias 'make-overlay 'cons)
 
-(defun tl:overlay-put (overlay prop value)
+(defun overlay-put (overlay prop value)
   (let ((ret (and (eq prop 'face)
-                 (assq value tl:available-face-attribute-alist)
+                 (assq value emu:available-face-attribute-alist)
                  )))
     (if ret
        (attribute-add-narrow-attribute (cdr ret)