This commit was generated by cvs2svn to compensate for changes in r411,
[elisp/apel.git] / emu-nemacs.el
index 215a1ca..c485326 100644 (file)
-;;;
 ;;; emu-nemacs.el --- Mule 2 emulation module for NEmacs
-;;;
-;;; Copyright (C) 1995 Free Software Foundation, Inc.
-;;; Copyright (C) 1994,1995 MORIOKA Tomohiko
-;;;
-;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;;; Version:
-;;;    $Id: emu-nemacs.el,v 7.1 1995/10/11 11:49:55 morioka Exp $
-;;; Keywords: emulation, compatibility, NEmacs, Mule
-;;;
-;;; This file is part of tl and tm (Tools for MIME).
-;;;
+
+;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
+
+;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;; Version:
+;;     $Id: emu-nemacs.el,v 7.40 1996/08/18 06:39:40 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; 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)
 
 
-;;; @ 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")
 
+(defun charset-description (charset)
+  "Return description of CHARSET. [emu-nemacs.el]"
+  (if (< charset 128)
+      (documentation-property 'charset-ascii 'variable-documentation)
+    (documentation-property 'charset-jisx0208 'variable-documentation)
+    ))
 
-;;; @ leading-char
-;;;
+(defun charset-registry (charset)
+  "Return registry name of CHARSET. [emu-nemacs.el]"
+  (if (< charset 128)
+      "ASCII"
+    "JISX0208.1983"))
 
-(defconst lc-ascii 0)
-(defconst lc-jp  146)
+(defun charset-columns (charset)
+  "Return number of columns a CHARSET occupies when displayed.
+\[emu-nemacs.el]"
+  (if (< charset 128)
+      1
+    2))
+
+(defun charset-direction (charset)
+  "Return the direction of a character of CHARSET by
+  0 (left-to-right) or 1 (right-to-left). [emu-nemacs.el]"
+  0)
 
-(defun char-leading-char (chr)
-  "Return leading character of CHAR.
+(defun find-charset-string (str)
+  "Return a list of charsets in the string.
 \[emu-nemacs.el; Mule emulating function]"
-  (if (< chr 128)
-      lc-ascii
-    lc-jp))
+  (if (string-match "[\200-\377]" str)
+      (list lc-jp)
+    ))
+
+(defun find-charset-region (start end)
+  "Return a list of charsets in the region between START and END.
+\[emu-nemacs.el; Mule emulating function]"
+  (if (save-excursion
+       (save-restriction
+         (narrow-to-region start end)
+         (goto-char start)
+         (re-search-forward "[\200-\377]" nil t)
+         ))
+      (list lc-jp)
+    ))
+
+(defun check-ASCII-string (str)
+  (let ((i 0)
+       len)
+    (setq len (length str))
+    (catch 'label
+      (while (< i len)
+       (if (>= (elt str i) 128)
+           (throw 'label nil))
+       (setq i (+ i 1))
+       )
+      str)))
 
-(defalias 'get-lc 'char-leading-char)
+;;; @@ for Mule emulation
+;;;
+
+(defconst lc-ascii 0)
+(defconst lc-jp  146)
 
 
-;;; @ coding-system
+;;; @ coding system
 ;;;
 
-(defconst *junet* 2)
-(defconst *internal* 3)
+(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)
@@ -52,25 +116,169 @@ else returns nil. [emu-nemacs.el; Mule emulating function]"
       (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)
+         ))))
+
+(defun decode-coding-string (string coding-system)
+  "Decode the STRING which is encoded in CODING-SYSTEM.
+\[emu-nemacs.el]"
+  (if (eq coding-system 3)
+      string
+    (convert-string-kanji-code string coding-system 3)
+    ))
+
+(defun code-detect-region (start end)
+  "Detect coding-system of the text in the region between START and END.
+\[emu-nemacs.el; Mule emulating function]"
+  (if (save-excursion
+       (save-restriction
+         (narrow-to-region start end)
+         (goto-char start)
+         (re-search-forward "[\200-\377]" nil t)
+         ))
+      *euc-japan*
+    ))
+
+(defun set-file-coding-system (coding-system &optional force)
+  (set-kanji-fileio-code coding-system)
+  )
+
+(defmacro as-binary-process (&rest body)
+  (` (let (selective-display   ; Disable ^M to nl translation.
+          ;; NEmacs
+          kanji-flag
+          (default-kanji-process-code 0)
+          program-kanji-code-alist)
+       (,@ body)
+       )))
+
+
+;;; @ MIME charset
+;;;
+
+(defvar charsets-mime-charset-alist
+  (list (cons (list charset-ascii) 'us-ascii)))
+
+(defvar default-mime-charset 'iso-2022-jp)
 
-;;; @ character and string
+(defvar mime-charset-coding-system-alist
+  '((iso-2022-jp     . 2)
+    (shift_jis       . 1)
+    ))
+
+(defun mime-charset-to-coding-system (charset)
+  (if (stringp charset)
+      (setq charset (intern (downcase charset)))
+    )
+  (cdr (assq charset mime-charset-coding-system-alist))
+  )
+
+(defun detect-mime-charset-region (start end)
+  "Return MIME charset for region between START and END.
+\[emu-nemacs.el]"
+  (if (save-excursion
+       (save-restriction
+         (narrow-to-region start end)
+         (goto-char start)
+         (re-search-forward "[\200-\377]" nil t)
+         ))
+      default-mime-charset
+    'us-ascii))
+
+(defun encode-mime-charset-region (start end charset)
+  "Encode the text between START and END as MIME CHARSET.
+\[emu-nemacs.el]"
+  (let ((cs (mime-charset-to-coding-system charset)))
+    (and (numberp cs)
+        (or (= cs 3)
+            (save-excursion
+              (save-restriction
+                (narrow-to-region start end)
+                (convert-region-kanji-code start end 3 cs)
+                ))
+            ))))
+
+(defun decode-mime-charset-region (start end charset)
+  "Decode the text between START and END as MIME CHARSET.
+\[emu-nemacs.el]"
+  (let ((cs (mime-charset-to-coding-system charset)))
+    (and (numberp cs)
+        (or (= cs 3)
+            (save-excursion
+              (save-restriction
+                (narrow-to-region start end)
+                (convert-region-kanji-code start end cs 3)
+                ))
+            ))))
+
+(defun encode-mime-charset-string (string charset)
+  "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
+  (let ((cs (mime-charset-to-coding-system charset)))
+    (if cs
+       (convert-string-kanji-code string 3 cs)
+      string)))
+
+(defun decode-mime-charset-string (string charset)
+  "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
+  (let ((cs (mime-charset-to-coding-system charset)))
+    (if cs
+       (convert-string-kanji-code string cs 3)
+      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))
+(defalias 'char-length 'char-bytes)
+
+(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
+;;;
+
+(defalias 'string-columns 'length)
 
-;; by mol. 1993/9/26
-(defun string-width (str)
-  "Return number of columns STRING will occupy.
- [Mule compatible function in tm-nemacs]"
-  (length str))
+(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)
@@ -86,32 +294,43 @@ else returns nil. [emu-nemacs.el; Mule emulating function]"
     (reverse dest)
     ))
 
-(defun find-charset-string (str)
-  (if (string-match "[\200-\377]" str)
-      (list lc-jp)
-    ))
-
-(defun find-charset-region (start end)
-  (if (save-excursion
-       (save-restriction
-         (narrow-to-region start end)
-         (goto-char start)
-         (re-search-forward "[\200-\377]" nil t)
-         ))
-      (list lc-jp)
-    ))
+(fset 'string-to-int-list (symbol-function 'string-to-char-list))
+
+;;; Imported from Mule-2.3
+(defun truncate-string (str width &optional start-column)
+  "Truncate STR to fit in WIDTH columns.
+Optional non-nil arg START-COLUMN specifies the starting column.
+\[emu-mule.el; Mule 2.3 emulating function]"
+  (or start-column
+      (setq start-column 0))
+  (let ((max-width (string-width str))
+       (len (length str))
+       (from 0)
+       (column 0)
+       to-prev to ch)
+    (if (>= width max-width)
+       (setq width max-width))
+    (if (>= start-column width)
+       ""
+      (while (< column start-column)
+       (setq ch (aref str from)
+             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-columns ch))
+                   to-prev to
+                   to (+ to (char-bytes ch))))
+           (setq to to-prev)))
+      (substring str from to))))
+
+;;; @@ for Mule emulation
+;;;
 
-(defun check-ASCII-string (str)
-  (let ((i 0)
-       len)
-    (setq len (length str))
-    (catch 'label
-      (while (< i len)
-       (if (>= (elt str i) 128)
-           (throw 'label nil))
-       (setq i (+ i 1))
-       )
-      str)))
+(defalias 'string-width 'length)
 
 
 ;;; @ text property emulation
@@ -174,10 +393,10 @@ else returns nil. [emu-nemacs.el; Mule emulating function]"
                                        (car overlay)(cdr overlay))
       )))
 
-(defun tl:add-text-properties (start end properties &optional object)) 
-
 
 ;;; @ end
 ;;;
 
 (provide 'emu-nemacs)
+
+;;; emu-nemacs.el ends here