tm 7.9.
[elisp/apel.git] / emu-nemacs.el
1 ;;;
2 ;;; emu-nemacs.el --- Mule 2 emulation module for NEmacs
3 ;;;
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1994,1995 MORIOKA Tomohiko
6 ;;;
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Version:
9 ;;;     $Id: emu-nemacs.el,v 6.1 1995/09/21 00:07:24 morioka Exp morioka $
10 ;;; Keywords: emulation, compatibility, NEmacs, Mule
11 ;;;
12 ;;; This file is part of tl and tm (Tools for MIME).
13 ;;;
14
15 (require 'emu-18)
16
17
18 ;;; @ constants
19 ;;;
20
21 (defconst emacs-major-version (string-to-int emacs-version))
22
23
24 ;;; @ leading-char
25 ;;;
26
27 (defconst lc-ascii 0)
28 (defconst lc-jp  146)
29
30 (defun char-leading-char (chr)
31   "Return leading character of CHAR.
32 \[emu-nemacs.el; Mule emulating function]"
33   (if (< chr 128)
34       lc-ascii
35     lc-jp))
36
37 (defalias 'get-lc 'char-leading-char)
38
39
40 ;;; @ coding-system
41 ;;;
42
43 (defconst *junet* 2)
44 (defconst *internal* 3)
45 (defconst *euc-japan* 3)
46
47 (defun code-convert-string (str ic oc)
48   "Convert code in STRING from SOURCE code to TARGET code,
49 On successful converion, returns the result string,
50 else returns nil. [emu-nemacs.el; Mule emulating function]"
51   (if (not (eq ic oc))
52       (convert-string-kanji-code str ic oc)
53     str))
54
55
56 ;;; @ character and string
57 ;;;
58
59 (defun char-bytes (chr)
60   "Return number of bytes CHAR will occupy in a buffer.
61  [Mule compatible function in tm-nemacs]"
62   (if (< chr 128) 1 2))
63
64 (defun char-width (chr)
65   "Return number of columns CHAR will occupy when displayed.
66  [Mule compatible function in tm-nemacs]"
67   (if (< chr 128) 1 2))
68
69 ;; by mol. 1993/9/26
70 (defun string-width (str)
71   "Return number of columns STRING will occupy.
72  [Mule compatible function in tm-nemacs]"
73   (length str))
74
75 (defun string-to-char-list (str)
76   (let ((i 0)(len (length str)) dest chr)
77     (while (< i len)
78       (setq chr (aref str i))
79       (if (>= chr 128)
80           (setq i (1+ i)
81                 chr (+ (lsh chr 8) (aref str i))
82                 ))
83       (setq dest (cons chr dest))
84       (setq i (1+ i))
85       )
86     (reverse dest)
87     ))
88
89 (defun check-ASCII-string (str)
90   (let ((i 0)
91         len)
92     (setq len (length str))
93     (catch 'label
94       (while (< i len)
95         (if (>= (elt str i) 128)
96             (throw 'label nil))
97         (setq i (+ i 1))
98         )
99       str)))
100
101
102 ;;; @ text property emulation
103 ;;;
104
105 (setq tl:available-face-attribute-alist
106       '(
107         ;;(bold      . inversed-region)
108         (italic    . underlined-region)
109         (underline . underlined-region)
110         ))
111
112 ;; by YAMATE Keiichirou 1994/10/28
113 (defun attribute-add-narrow-attribute (attr from to)
114   (or (consp (symbol-value attr))
115       (set attr (list 1)))
116   (let* ((attr-value (symbol-value attr))
117          (len (car attr-value))
118          (posfrom 1)
119          posto)
120     (while (and (< posfrom len)
121                 (> from (nth posfrom attr-value)))
122       (setq posfrom (1+ posfrom)))
123     (setq posto posfrom)
124     (while (and (< posto len)
125                 (> to (nth posto attr-value)))
126       (setq posto (1+ posto)))
127     (if  (= posto posfrom)
128         (if (= (% posto 2) 1)
129             (if (and (< to len)
130                      (= to (nth posto attr-value)))
131                 (set-marker (nth posto attr-value) from)
132               (setcdr (nthcdr (1- posfrom) attr-value)
133                       (cons (set-marker-type (set-marker (make-marker)
134                                                          from)
135                                              'point-type)
136                             (cons (set-marker-type (set-marker (make-marker)
137                                                                to)
138                                                    nil)
139                                   (nthcdr posto attr-value))))
140               (setcar attr-value (+ len 2))))
141       (if (= (% posfrom 2) 0)
142           (setq posfrom (1- posfrom))
143         (set-marker (nth posfrom attr-value) from))
144       (if (= (% posto 2) 0)
145           nil
146         (setq posto (1- posto))
147         (set-marker (nth posto attr-value) to))
148       (setcdr (nthcdr posfrom attr-value)
149               (nthcdr posto attr-value)))))
150
151 (defalias 'tl:make-overlay 'cons)
152
153 (defun tl:overlay-put (overlay prop value)
154   (let ((ret (and (eq prop 'face)
155                   (assq value tl:available-face-attribute-alist)
156                   )))
157     (if ret
158         (attribute-add-narrow-attribute (cdr ret)
159                                         (car overlay)(cdr overlay))
160       )))
161
162 (defun tl:add-text-properties (start end properties &optional object)) 
163
164
165 ;;; @ end
166 ;;;
167
168 (provide 'emu-nemacs)