update.
[elisp/apel.git] / emu.el
diff --git a/emu.el b/emu.el
index a026678..cd62652 100644 (file)
--- a/emu.el
+++ b/emu.el
        ))
 
 (require 'poem)
-
-(cond (running-xemacs
-       (if (featurep 'mule)
-          ;; for XEmacs with MULE
-          (require 'emu-x20)
-        ;; for XEmacs without MULE
-        (require 'emu-latin1)
-        ))
-      (running-mule-merged-emacs
-       ;; for Emacs 20.1 and 20.2
-       (require 'emu-e20)
-       )
-      ((boundp 'MULE)
-       ;; for MULE 1.* and 2.*
-       (require 'emu-mule)
+(require 'mcharset)
+
+(cond ((featurep 'mule)
+       (cond ((featurep 'xemacs)
+             ;; for XEmacs with MULE
+             (require 'emu-x20)
+             )
+            ((>= emacs-major-version 20)
+             ;; for Emacs 20
+             (require 'emu-e20)
+             (defalias 'insert-binary-file-contents-literally
+               'insert-file-contents-literally)
+             )
+            (t
+             ;; for MULE 1.* and 2.*
+             (require 'emu-mule)
+             ))
        )
       ((boundp 'NEMACS)
        ;; for NEmacs and NEpoch
-       (require 'emu-nemacs)
+
+       ;; old MULE emulation
+       (defconst *noconv*    0)
+       (defconst *sjis*      1)
+       (defconst *junet*     2)
+       (defconst *ctext*     2)
+       (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 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)))
+          ))
        )
       (t
-       ;; for Emacs 19
-       (require 'emu-latin1)
+       ;; for Emacs 19 and XEmacs without MULE
+       
+       ;; old MULE emulation
+       (defconst *internal* nil)
+       (defconst *ctext* nil)
+       (defconst *noconv* nil)
+       
+       (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-latin1.el; old MULE emulating function]"
+        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-latin1.el; old MULE emulating function]"
+        t)
        ))
 
 
@@ -112,61 +156,24 @@ This constant is defined to emulate old MULE anything older than MULE 2.3.
 It is obsolete, so don't use it."))
 
 
-;;; @ MIME charset
-;;;
-
-(defun charsets-to-mime-charset (charsets)
-  "Return MIME charset from list of charset CHARSETS.
-This function refers variable `charsets-mime-charset-alist'
-and `default-mime-charset'."
-  (if charsets
-      (or (catch 'tag
-           (let ((rest charsets-mime-charset-alist)
-                 cell)
-             (while (setq cell (car rest))
-               (if (catch 'not-subset
-                     (let ((set1 charsets)
-                           (set2 (car cell))
-                           obj)
-                       (while set1
-                         (setq obj (car set1))
-                         (or (memq obj set2)
-                             (throw 'not-subset nil))
-                         (setq set1 (cdr set1)))
-                       t))
-                   (throw 'tag (cdr cell)))
-               (setq rest (cdr rest)))))
-         default-mime-charset)))
-
-
-;;; @ Emacs 20.3 emulation
-;;;
-
-(defmacro-maybe string-as-unibyte (string)
-  "Return a unibyte string with the same individual bytes as STRING.
-If STRING is unibyte, the result is STRING itself.
-\[Emacs 20.3 emulating macro]"
-  string)
-
-(defmacro-maybe string-as-multibyte (string)
-  "Return a multibyte string with the same individual bytes as STRING.
-If STRING is multibyte, the result is STRING itself.
-\[Emacs 20.3 emulating macro]"
-  string)
-
-
-;;; @ for XEmacs 20
+;;; @ without code-conversion
 ;;;
 
-(or (fboundp 'char-int)
-    (fset 'char-int (symbol-function 'identity))
-    )
-(or (fboundp 'int-char)
-    (fset 'int-char (symbol-function 'identity))
-    )
-(or (fboundp 'char-or-char-int-p)
-    (fset 'char-or-char-int-p (symbol-function 'integerp))
-    )
+(defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
+(make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
+
+(defun-maybe 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]"
+  (as-binary-input-file
+   ;; Returns list absolute file name and length of data inserted.
+   (insert-file-contents-literally filename visit beg end replace)))
 
 
 ;;; @ for text/richtext and text/enriched