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.27 1996/05/27 12:27:59 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.
37 (defconst charset-ascii 0 "Character set of ASCII")
38 (defconst charset-jisx0208 146 "Character set of JIS X0208-1983")
40 ;;; @@ for Mule emulation
54 (defconst *internal* 3)
55 (defconst *euc-japan* 3)
57 (defun character-encode-string (str coding-system)
58 "Encode the string STR which is encoded in CODING-SYSTEM. [emu-nemacs.el]"
59 (convert-string-kanji-code str 3 coding-system)
62 (defun character-decode-string (str coding-system)
63 "Decode the string STR which is encoded in CODING-SYSTEM. [emu-nemacs.el]"
64 (convert-string-kanji-code str coding-system 3)
67 (defun character-encode-region (start end coding-system)
68 "Encode the text between START and END which is
69 encoded in CODING-SYSTEM. [emu-nemacs.el]"
72 (narrow-to-region beg end)
73 (convert-region-kanji-code start end 3 coding-system)
76 (defun character-decode-region (start end coding-system)
77 "Decode the text between START and END which is
78 encoded in CODING-SYSTEM. [emu-nemacs.el]"
81 (narrow-to-region beg end)
82 (convert-region-kanji-code start end coding-system 3)
85 (defun code-convert-string (str ic oc)
86 "Convert code in STRING from SOURCE code to TARGET code,
87 On successful converion, returns the result string,
88 else returns nil. [emu-nemacs.el; Mule emulating function]"
90 (convert-string-kanji-code str ic oc)
93 (defun code-convert-region (beg end ic oc)
94 "Convert code of the text between BEGIN and END from SOURCE
95 to TARGET. On successful conversion returns t,
96 else returns nil. [emu-nemacs.el; Mule emulating function]"
100 (narrow-to-region beg end)
101 (convert-region-kanji-code beg end ic oc)
104 (defun code-detect-region (start end)
105 "Detect coding-system of the text in the region between START and END.
106 \[emu-nemacs.el; Mule emulating function]"
109 (narrow-to-region start end)
111 (re-search-forward "[\200-\377]" nil t)
116 (defun set-file-coding-system (coding-system &optional force)
117 (set-kanji-fileio-code coding-system)
124 (defun char-charset (chr)
125 "Return the character set of char CHR.
126 \[emu-nemacs.el; XEmacs 20 emulating function]"
131 (defun char-bytes (chr)
132 "Return number of bytes CHAR will occupy in a buffer.
133 \[emu-nemacs.el; Mule emulating function]"
134 (if (< chr 128) 1 2))
136 (defun char-columns (character)
137 "Return number of columns a CHARACTER occupies when displayed.
139 (if (< character 128)
143 ;;; @@ for Mule emulation
146 (defalias 'char-leading-char 'char-charset)
148 (defalias 'char-width 'char-columns)
154 (defalias 'string-columns 'length)
156 (defun sref (str idx)
157 "Return the character in STR at index IDX.
158 \[emu-nemacs.el; Mule emulating function]"
159 (let ((chr (aref str idx)))
162 (logior (lsh (aref str (1+ idx)) 8) chr)
165 (defun string-to-char-list (str)
166 (let ((i 0)(len (length str)) dest chr)
168 (setq chr (aref str i))
171 chr (+ (lsh chr 8) (aref str i))
173 (setq dest (cons chr dest))
179 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
181 (defun find-charset-string (str)
182 "Return a list of leading-chars in the string.
183 \[emu-nemacs.el; Mule emulating function]"
184 (if (string-match "[\200-\377]" str)
188 (defun find-charset-region (start end)
189 "Return a list of leading-chars in the region between START and END.
190 \[emu-nemacs.el; Mule emulating function]"
193 (narrow-to-region start end)
195 (re-search-forward "[\200-\377]" nil t)
200 (defun check-ASCII-string (str)
203 (setq len (length str))
206 (if (>= (elt str i) 128)
212 ;;; Imported from Mule-2.3
213 (defun truncate-string (str width &optional start-column)
214 "Truncate STR to fit in WIDTH columns.
215 Optional non-nil arg START-COLUMN specifies the starting column.
216 \[emu-mule.el; Mule 2.3 emulating function]"
218 (setq start-column 0))
219 (let ((max-width (string-width str))
224 (if (>= width max-width)
225 (setq width max-width))
226 (if (>= start-column width)
228 (while (< column start-column)
229 (setq ch (aref str from)
230 column (+ column (char-columns ch))
231 from (+ from (char-bytes ch))))
232 (if (< width max-width)
235 (while (<= column width)
236 (setq ch (aref str to)
237 column (+ column (char-columns ch))
239 to (+ to (char-bytes ch))))
241 (substring str from to))))
243 ;;; @@ for Mule emulation
246 (defalias 'string-width 'length)
249 ;;; @ text property emulation
252 (setq tl:available-face-attribute-alist
254 ;;(bold . inversed-region)
255 (italic . underlined-region)
256 (underline . underlined-region)
259 ;; by YAMATE Keiichirou 1994/10/28
260 (defun attribute-add-narrow-attribute (attr from to)
261 (or (consp (symbol-value attr))
263 (let* ((attr-value (symbol-value attr))
264 (len (car attr-value))
267 (while (and (< posfrom len)
268 (> from (nth posfrom attr-value)))
269 (setq posfrom (1+ posfrom)))
271 (while (and (< posto len)
272 (> to (nth posto attr-value)))
273 (setq posto (1+ posto)))
274 (if (= posto posfrom)
275 (if (= (% posto 2) 1)
277 (= to (nth posto attr-value)))
278 (set-marker (nth posto attr-value) from)
279 (setcdr (nthcdr (1- posfrom) attr-value)
280 (cons (set-marker-type (set-marker (make-marker)
283 (cons (set-marker-type (set-marker (make-marker)
286 (nthcdr posto attr-value))))
287 (setcar attr-value (+ len 2))))
288 (if (= (% posfrom 2) 0)
289 (setq posfrom (1- posfrom))
290 (set-marker (nth posfrom attr-value) from))
291 (if (= (% posto 2) 0)
293 (setq posto (1- posto))
294 (set-marker (nth posto attr-value) to))
295 (setcdr (nthcdr posfrom attr-value)
296 (nthcdr posto attr-value)))))
298 (defalias 'tl:make-overlay 'cons)
300 (defun tl:overlay-put (overlay prop value)
301 (let ((ret (and (eq prop 'face)
302 (assq value tl:available-face-attribute-alist)
305 (attribute-add-narrow-attribute (cdr ret)
306 (car overlay)(cdr overlay))
313 (provide 'emu-nemacs)
315 ;;; emu-nemacs.el ends here