2 ;;; emu-nemacs.el --- Mule 2 emulation module for NEmacs
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1993 .. 1996 MORIOKA Tomohiko
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; modified by KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
10 ;;; $Id: emu-nemacs.el,v 7.19 1996/05/09 15:06:53 morioka Exp $
11 ;;; Keywords: emulation, compatibility, NEmacs, Mule
13 ;;; This file is part of tl (Tiny Library).
15 ;;; This program is free software; you can redistribute it and/or
16 ;;; modify it under the terms of the GNU General Public License as
17 ;;; published by the Free Software Foundation; either version 2, or
18 ;;; (at your option) any later version.
20 ;;; This program is distributed in the hope that it will be useful,
21 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;;; General Public License for more details.
25 ;;; You should have received a copy of the GNU General Public License
26 ;;; along with This program. If not, write to the Free Software
27 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
40 (defun char-charset (chr)
41 "Return the character set of char CHR.
42 \[emu-nemacs.el; XEmacs 20 emulating function]"
47 (defalias 'char-leading-char 'char-charset)
57 (defconst *internal* 3)
58 (defconst *euc-japan* 3)
60 (defun character-encode-string (str coding-system)
61 "Encode the string STR which is encoded in CODING-SYSTEM. [emu-nemacs.el]"
62 (convert-string-kanji-code str 3 coding-system)
65 (defun character-decode-string (str coding-system)
66 "Decode the string STR which is encoded in CODING-SYSTEM. [emu-nemacs.el]"
67 (convert-string-kanji-code str coding-system 3)
70 (defun character-encode-region (start end coding-system)
71 "Encode the text between START and END which is
72 encoded in CODING-SYSTEM. [emu-nemacs.el]"
75 (narrow-to-region beg end)
76 (convert-region-kanji-code start end 3 coding-system)
79 (defun character-decode-region (start end coding-system)
80 "Decode the text between START and END which is
81 encoded in CODING-SYSTEM. [emu-nemacs.el]"
84 (narrow-to-region beg end)
85 (convert-region-kanji-code start end coding-system 3)
88 (defun code-convert-string (str ic oc)
89 "Convert code in STRING from SOURCE code to TARGET code,
90 On successful converion, returns the result string,
91 else returns nil. [emu-nemacs.el; Mule emulating function]"
93 (convert-string-kanji-code str ic oc)
96 (defun code-convert-region (beg end ic oc)
97 "Convert code of the text between BEGIN and END from SOURCE
98 to TARGET. On successful conversion returns t,
99 else returns nil. [emu-nemacs.el; Mule emulating function]"
103 (narrow-to-region beg end)
104 (convert-region-kanji-code beg end ic oc)
107 (defun code-detect-region (start end)
108 "Detect coding-system of the text in the region between START and END.
109 \[emu-nemacs.el; Mule emulating function]"
112 (narrow-to-region start end)
114 (re-search-forward "[\200-\377]" nil t)
119 (defun set-file-coding-system (coding-system &optional force)
120 (set-kanji-fileio-code coding-system)
124 ;;; @ character and string
127 (defun char-bytes (chr)
128 "Return number of bytes CHAR will occupy in a buffer.
129 \[emu-nemacs.el; Mule emulating function]"
130 (if (< chr 128) 1 2))
132 (defun char-width (chr)
133 "Return number of columns CHAR will occupy when displayed.
134 \[emu-nemacs.el; Mule emulating function]"
135 (if (< chr 128) 1 2))
137 (defun string-width (str)
138 "Return number of columns STRING will occupy.
139 \[emu-nemacs.el; Mule emulating function]"
142 (defun sref (str idx)
143 "Return the character in STR at index IDX.
144 \[emu-nemacs.el; Mule emulating function]"
145 (let ((chr (aref str idx)))
148 (logior (lsh (aref str (1+ idx)) 8) chr)
151 (defun string-to-char-list (str)
152 (let ((i 0)(len (length str)) dest chr)
154 (setq chr (aref str i))
157 chr (+ (lsh chr 8) (aref str i))
159 (setq dest (cons chr dest))
165 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
167 (defun find-charset-string (str)
168 "Return a list of leading-chars in the string.
169 \[emu-nemacs.el; Mule emulating function]"
170 (if (string-match "[\200-\377]" str)
174 (defun find-charset-region (start end)
175 "Return a list of leading-chars in the region between START and END.
176 \[emu-nemacs.el; Mule emulating function]"
179 (narrow-to-region start end)
181 (re-search-forward "[\200-\377]" nil t)
186 (defun check-ASCII-string (str)
189 (setq len (length str))
192 (if (>= (elt str i) 128)
198 ;;; Imported from Mule-2.3
199 (defun truncate-string (str width &optional start-column)
200 "Truncate STR to fit in WIDTH columns.
201 Optional non-nil arg START-COLUMN specifies the starting column.
202 \[emu-mule.el; Mule 2.3 emulating function]"
204 (setq start-column 0))
205 (let ((max-width (string-width str))
210 (if (>= width max-width)
211 (setq width max-width))
212 (if (>= start-column width)
214 (while (< column start-column)
215 (setq ch (aref str from)
216 column (+ column (char-width ch))
217 from (+ from (char-bytes ch))))
218 (if (< width max-width)
221 (while (<= column width)
222 (setq ch (aref str to)
223 column (+ column (char-width ch))
225 to (+ to (char-bytes ch))))
227 (substring str from to))))
230 ;;; @ text property emulation
233 (setq tl:available-face-attribute-alist
235 ;;(bold . inversed-region)
236 (italic . underlined-region)
237 (underline . underlined-region)
240 ;; by YAMATE Keiichirou 1994/10/28
241 (defun attribute-add-narrow-attribute (attr from to)
242 (or (consp (symbol-value attr))
244 (let* ((attr-value (symbol-value attr))
245 (len (car attr-value))
248 (while (and (< posfrom len)
249 (> from (nth posfrom attr-value)))
250 (setq posfrom (1+ posfrom)))
252 (while (and (< posto len)
253 (> to (nth posto attr-value)))
254 (setq posto (1+ posto)))
255 (if (= posto posfrom)
256 (if (= (% posto 2) 1)
258 (= to (nth posto attr-value)))
259 (set-marker (nth posto attr-value) from)
260 (setcdr (nthcdr (1- posfrom) attr-value)
261 (cons (set-marker-type (set-marker (make-marker)
264 (cons (set-marker-type (set-marker (make-marker)
267 (nthcdr posto attr-value))))
268 (setcar attr-value (+ len 2))))
269 (if (= (% posfrom 2) 0)
270 (setq posfrom (1- posfrom))
271 (set-marker (nth posfrom attr-value) from))
272 (if (= (% posto 2) 0)
274 (setq posto (1- posto))
275 (set-marker (nth posto attr-value) to))
276 (setcdr (nthcdr posfrom attr-value)
277 (nthcdr posto attr-value)))))
279 (defalias 'tl:make-overlay 'cons)
281 (defun tl:overlay-put (overlay prop value)
282 (let ((ret (and (eq prop 'face)
283 (assq value tl:available-face-attribute-alist)
286 (attribute-add-narrow-attribute (cdr ret)
287 (car overlay)(cdr overlay))
294 (provide 'emu-nemacs)
296 ;;; emu-nemacs.el ends here