tm 7.65.
[elisp/apel.git] / emu-nemacs.el
index d3911ff..986c3b6 100644 (file)
@@ -5,9 +5,9 @@
 ;;; Copyright (C) 1993 .. 1996 MORIOKA Tomohiko
 ;;;
 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;;; modified by KOBAYASHI Shuhei <shuhei@cmpt01.phys.tohoku.ac.jp>
+;;; modified by KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
 ;;; Version:
-;;;    $Id: emu-nemacs.el,v 7.8 1996/03/14 16:25:39 morioka Exp $
+;;;    $Id: emu-nemacs.el,v 7.27 1996/05/27 12:27:59 morioka Exp $
 ;;; Keywords: emulation, compatibility, NEmacs, Mule
 ;;;
 ;;; This file is part of tl (Tiny Library).
 (require 'emu-18)
 
 
-;;; @ constants
+;;; @ character set
 ;;;
 
-(defconst emacs-major-version (string-to-int emacs-version))
+(defconst charset-ascii 0 "Character set of ASCII")
+(defconst charset-jisx0208 146 "Character set of JIS X0208-1983")
 
-
-;;; @ leading-char
+;;; @@ for Mule emulation
 ;;;
 
 (defconst lc-ascii 0)
 (defconst lc-jp  146)
 
-(defun char-leading-char (chr)
-  "Return leading character of CHAR.
-\[emu-nemacs.el; Mule emulating function]"
-  (if (< chr 128)
-      lc-ascii
-    lc-jp))
-
-(defalias 'get-lc 'char-leading-char)
-
 
-;;; @ coding-system
+;;; @ coding system
 ;;;
 
 (defconst *noconv*    0)
 (defconst *internal*  3)
 (defconst *euc-japan* 3)
 
+(defun character-encode-string (str coding-system)
+  "Encode the string STR which is encoded in CODING-SYSTEM. [emu-nemacs.el]"
+  (convert-string-kanji-code str 3 coding-system)
+  )
+
+(defun character-decode-string (str coding-system)
+  "Decode the string STR which is encoded in CODING-SYSTEM. [emu-nemacs.el]"
+  (convert-string-kanji-code str coding-system 3)
+  )
+
+(defun character-encode-region (start end coding-system)
+  "Encode the text between START and END which is
+encoded in CODING-SYSTEM. [emu-nemacs.el]"
+  (save-excursion
+    (save-restriction
+      (narrow-to-region beg end)
+      (convert-region-kanji-code start end 3 coding-system)
+      )))
+
+(defun character-decode-region (start end coding-system)
+  "Decode the text between START and END which is
+encoded in CODING-SYSTEM. [emu-nemacs.el]"
+  (save-excursion
+    (save-restriction
+      (narrow-to-region beg end)
+      (convert-region-kanji-code start end coding-system 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,
@@ -75,12 +94,16 @@ else returns nil. [emu-nemacs.el; Mule emulating function]"
   "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 (not (eq ic oc))
-      (convert-region-kanji-code beg end ic oc)))
+  (if (/= ic oc)
+      (save-excursion
+       (save-restriction
+         (narrow-to-region beg end)
+         (convert-region-kanji-code beg end ic oc)
+         ))))
 
 (defun code-detect-region (start end)
   "Detect coding-system of the text in the region between START and END.
-\[emu-orig.el; Mule emulating function]"
+\[emu-nemacs.el; Mule emulating function]"
   (if (save-excursion
        (save-restriction
          (narrow-to-region start end)
@@ -95,23 +118,49 @@ else returns nil. [emu-nemacs.el; Mule emulating function]"
   )
 
 
-;;; @ character and string
+;;; @ character
 ;;;
 
+(defun char-charset (chr)
+  "Return the character set of char CHR.
+\[emu-nemacs.el; XEmacs 20 emulating function]"
+  (if (< chr 128)
+      charset-ascii
+    charset-jisx0208))
+
 (defun char-bytes (chr)
   "Return number of bytes CHAR will occupy in a buffer.
-\[Mule compatible function in tm-nemacs]"
+\[emu-nemacs.el; Mule emulating function]"
   (if (< chr 128) 1 2))
 
-(defun char-width (chr)
-  "Return number of columns CHAR will occupy when displayed.
-\[Mule compatible function in tm-nemacs]"
-  (if (< chr 128) 1 2))
+(defun char-columns (character)
+  "Return number of columns a CHARACTER occupies when displayed.
+\[emu-nemacs.el]"
+  (if (< character 128)
+      1
+    2))
+
+;;; @@ for Mule emulation
+;;;
+
+(defalias 'char-leading-char 'char-charset)
+
+(defalias 'char-width 'char-columns)
+
+
+;;; @ string
+;;;
 
-(defun string-width (str)
-  "Return number of columns STRING will occupy.
-\[Mule compatible function in tm-nemacs]"
-  (length str))
+(defalias 'string-columns 'length)
+
+(defun sref (str idx)
+  "Return the character in STR at index IDX.
+\[emu-nemacs.el; Mule emulating function]"
+  (let ((chr (aref str idx)))
+    (if (< chr 128)
+       chr
+      (logior (lsh (aref str (1+ idx)) 8) chr)
+      )))
 
 (defun string-to-char-list (str)
   (let ((i 0)(len (length str)) dest chr)
@@ -127,6 +176,8 @@ else returns nil. [emu-nemacs.el; Mule emulating function]"
     (reverse dest)
     ))
 
+(fset 'string-to-int-list (symbol-function 'string-to-char-list))
+
 (defun find-charset-string (str)
   "Return a list of leading-chars in the string.
 \[emu-nemacs.el; Mule emulating function]"
@@ -176,19 +227,24 @@ Optional non-nil arg START-COLUMN specifies the starting column.
        ""
       (while (< column start-column)
        (setq ch (aref str from)
-             column (+ column (char-width ch))
+             column (+ column (char-columns ch))
              from (+ from (char-bytes ch))))
       (if (< width max-width)
          (progn
            (setq to from)
            (while (<= column width)
              (setq ch (aref str to)
-                   column (+ column (char-width ch))
+                   column (+ column (char-columns ch))
                    to-prev to
                    to (+ to (char-bytes ch))))
            (setq to to-prev)))
       (substring str from to))))
 
+;;; @@ for Mule emulation
+;;;
+
+(defalias 'string-width 'length)
+
 
 ;;; @ text property emulation
 ;;;
@@ -250,8 +306,6 @@ Optional non-nil arg START-COLUMN specifies the starting column.
                                        (car overlay)(cdr overlay))
       )))
 
-(defun tl:add-text-properties (start end properties &optional object)) 
-
 
 ;;; @ end
 ;;;