rearrangement.
[elisp/apel.git] / emu-mule.el
index 2ecb877..9821aec 100644 (file)
@@ -3,6 +3,7 @@
 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
 
 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;         Katsumi Yamaoka <yamaoka@jpl.org>
 ;; Keywords: emulation, compatibility, Mule
 
 ;; This file is part of emu.
@@ -28,7 +29,7 @@
 ;;;
 
 (cond (running-emacs-19
-       (require 'emu-19)
+       (require 'emu-e19)
        
        ;; Suggested by SASAKI Osamu <osamu@shuugr.bekkoame.or.jp>
        ;; (cf. [os2-emacs-ja:78])
 (defalias 'charset-columns     'char-width)
 (defalias 'charset-direction   'char-direction)
 
+(defun charset-chars (charset)
+  "Return the number of characters per dimension of CHARSET."
+  (if (= (logand (nth 2 (character-set charset)) 1) 1)
+      96
+    94))
+
 
 ;;; @ coding system
 ;;;
 ;;; @ binary access
 ;;;
 
-(defun insert-binary-file-contents-literally
-  (filename &optional visit beg end replace)
+(defun insert-file-contents-as-binary (filename
+                                      &optional visit beg end replace)
+  "Like `insert-file-contents', q.v., but don't code and format conversion.
+Like `insert-file-contents-literary', but it allows find-file-hooks,
+automatic uncompression, etc.
+
+Namely this function ensures that only format decoding and character
+code conversion will not take place."
+  (let (mc-flag
+       (file-coding-system-for-read *noconv*))
+    (insert-file-contents filename visit beg end replace)
+    ))
+
+(defalias 'insert-binary-file-contents 'insert-file-contents-as-binary)
+(make-obsolete 'insert-binary-file-contents 'insert-file-contents-as-binary)
+
+(defun insert-file-contents-as-raw-text (filename
+                                        &optional visit beg end replace)
+  "Like `insert-file-contents', q.v., but don't code and format conversion.
+Like `insert-file-contents-literary', but it allows find-file-hooks,
+automatic uncompression, etc.
+Like `insert-file-contents-as-binary', but it converts line-break
+code."
+  (save-excursion
+    (save-restriction
+      (narrow-to-region (point)(point))
+      (insert-file-contents-as-binary filename visit beg end replace)
+      (goto-char (point-min))
+      (while (re-search-forward "\r$" nil t)
+       (replace-match "")
+       ))))
+
+(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,
@@ -152,14 +191,6 @@ find-file-hooks, etc.
     (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."
-  (let (mc-flag
-       (file-coding-system *noconv*))
-    (insert-file-contents filename visit beg end replace)
-    ))
-
 (if running-emacs-19_29-or-later
     ;; for MULE 2.3 based on Emacs 19.34.
     (defun write-region-as-binary (start end filename
@@ -211,6 +242,14 @@ find-file-hooks, etc.
        (decode-coding-string string cs)
       string)))
 
+(defun write-region-as-mime-charset (charset start end filename)
+  "Like `write-region', q.v., but code-convert by MIME CHARSET."
+  (let ((file-coding-system
+        (or (mime-charset-to-coding-system charset)
+            *noconv*)))
+    (write-region start end filename append visit)
+    ))
+
 
 ;;; @@ to coding-system
 ;;;
@@ -303,14 +342,46 @@ It must be symbol.")
    (cons lc-ascii (find-charset-region start end))))
 
 
+;;; @ buffer representation
+;;;
+
+(defsubst-maybe set-buffer-multibyte (flag)
+  "Set the multibyte flag of the current buffer to FLAG.
+If FLAG is t, this makes the buffer a multibyte buffer.
+If FLAG is nil, this makes the buffer a single-byte buffer.
+The buffer contents remain unchanged as a sequence of bytes
+but the contents viewed as characters do change.
+\[Emacs 20.3 emulating function]"
+  (setq mc-flag flag)
+  )
+
+
 ;;; @ character
 ;;;
 
 (defalias 'char-charset 'char-leading-char)
 
-(defalias 'char-length 'char-bytes)
+(defun split-char (character)
+  "Return list of charset and one or two position-codes of CHARACTER."
+  (let ((p (1- (char-bytes character)))
+       dest)
+    (while (>= p 1)
+      (setq dest (cons (- (char-component character p) 128) dest)
+           p (1- p))
+      )
+    (cons (char-charset character) dest)
+    ))
+
+(defmacro char-next-index (char index)
+  "Return index of character succeeding CHAR whose index is INDEX."
+  (` (+ (, index) (char-bytes (, char)))))
+
+;;; @@ obsoleted aliases
+;;;
+;;; You should not use them.
 
-(defalias 'char-columns 'char-width)
+(defalias 'char-length 'char-bytes)
+;;(defalias 'char-columns 'char-width)
 
 
 ;;; @ string
@@ -354,6 +425,8 @@ Optional non-nil arg START-COLUMN specifies the starting column.
 ;;;
   )
 
+(defalias 'looking-at-as-unibyte 'looking-at)
+
 
 ;;; @ regulation
 ;;;