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.32 1996/07/11 13:59:54 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 (defun charset-description (charset)
41 "Return description of CHARSET. [emu-nemacs.el]"
43 (documentation-property 'charset-ascii 'variable-documentation)
44 (documentation-property 'charset-jisx0208 'variable-documentation)
47 (defun charset-registry (charset)
48 "Return registry name of CHARSET. [emu-nemacs.el]"
53 (defun charset-columns (charset)
54 "Return number of columns a CHARSET occupies when displayed.
60 (defun charset-direction (charset)
61 "Return the direction of a character of CHARSET by
62 0 (left-to-right) or 1 (right-to-left). [emu-nemacs.el]"
65 (defun find-charset-string (str)
66 "Return a list of charsets in the string.
67 \[emu-nemacs.el; Mule emulating function]"
68 (if (string-match "[\200-\377]" str)
72 (defun find-charset-region (start end)
73 "Return a list of charsets in the region between START and END.
74 \[emu-nemacs.el; Mule emulating function]"
77 (narrow-to-region start end)
79 (re-search-forward "[\200-\377]" nil t)
84 (defun check-ASCII-string (str)
87 (setq len (length str))
90 (if (>= (elt str i) 128)
96 ;;; @@ for Mule emulation
106 (defconst *noconv* 0)
110 (defconst *internal* 3)
111 (defconst *euc-japan* 3)
113 (defun character-encode-string (str coding-system)
114 "Encode the string STR which is encoded in CODING-SYSTEM. [emu-nemacs.el]"
115 (convert-string-kanji-code str 3 coding-system)
118 (defun character-decode-string (str coding-system)
119 "Decode the string STR which is encoded in CODING-SYSTEM. [emu-nemacs.el]"
120 (convert-string-kanji-code str coding-system 3)
123 (defun character-encode-region (start end coding-system)
124 "Encode the text between START and END which is
125 encoded in CODING-SYSTEM. [emu-nemacs.el]"
128 (narrow-to-region beg end)
129 (convert-region-kanji-code start end 3 coding-system)
132 (defun character-decode-region (start end coding-system)
133 "Decode the text between START and END which is
134 encoded in CODING-SYSTEM. [emu-nemacs.el]"
137 (narrow-to-region beg end)
138 (convert-region-kanji-code start end coding-system 3)
141 (defun code-convert-string (str ic oc)
142 "Convert code in STRING from SOURCE code to TARGET code,
143 On successful converion, returns the result string,
144 else returns nil. [emu-nemacs.el; Mule emulating function]"
146 (convert-string-kanji-code str ic oc)
149 (defun code-convert-region (beg end ic oc)
150 "Convert code of the text between BEGIN and END from SOURCE
151 to TARGET. On successful conversion returns t,
152 else returns nil. [emu-nemacs.el; Mule emulating function]"
156 (narrow-to-region beg end)
157 (convert-region-kanji-code beg end ic oc)
160 (defun code-detect-region (start end)
161 "Detect coding-system of the text in the region between START and END.
162 \[emu-nemacs.el; Mule emulating function]"
165 (narrow-to-region start end)
167 (re-search-forward "[\200-\377]" nil t)
172 (defun set-file-coding-system (coding-system &optional force)
173 (set-kanji-fileio-code coding-system)
176 (defmacro as-binary-process (&rest body)
177 (` (let (selective-display ; Disable ^M to nl translation.
180 (default-kanji-process-code 0)
181 program-kanji-code-alist)
189 (defvar charsets-mime-charset-alist
190 (list (cons (list charset-ascii) 'us-ascii)))
192 (defvar default-mime-charset 'iso-2022-jp)
194 (defvar mime-charset-coding-system-alist
199 (defun mime-charset-to-coding-system (charset)
200 (if (stringp charset)
201 (setq charset (intern (downcase charset)))
203 (cdr (assq charset mime-charset-coding-system-alist))
206 (defun detect-mime-charset-region (start end)
207 "Return MIME charset for region between START and END.
211 (narrow-to-region start end)
213 (re-search-forward "[\200-\377]" nil t)
218 (defun encode-mime-charset-region (start end charset)
219 "Encode the text between START and END which is
220 encoded in MIME CHARSET. [emu-nemacs.el]"
221 (let ((cs (mime-charset-to-coding-system charset)))
225 (narrow-to-region start end)
226 (convert-region-kanji-code start end 3 cs)
229 (defun encode-mime-charset-string (string charset)
230 "Encode the STRING which is encoded in MIME CHARSET. [emu-nemacs.el]"
231 (let ((cs (mime-charset-to-coding-system charset)))
233 (convert-string-kanji-code string 3 cs)
240 (defun char-charset (chr)
241 "Return the character set of char CHR.
242 \[emu-nemacs.el; XEmacs 20 emulating function]"
247 (defun char-bytes (chr)
248 "Return number of bytes CHAR will occupy in a buffer.
249 \[emu-nemacs.el; Mule emulating function]"
250 (if (< chr 128) 1 2))
252 (defalias 'char-length 'char-bytes)
254 (defun char-columns (character)
255 "Return number of columns a CHARACTER occupies when displayed.
257 (if (< character 128)
261 ;;; @@ for Mule emulation
264 (defalias 'char-leading-char 'char-charset)
266 (defalias 'char-width 'char-columns)
272 (defalias 'string-columns 'length)
274 (defun sref (str idx)
275 "Return the character in STR at index IDX.
276 \[emu-nemacs.el; Mule emulating function]"
277 (let ((chr (aref str idx)))
280 (logior (lsh (aref str (1+ idx)) 8) chr)
283 (defun string-to-char-list (str)
284 (let ((i 0)(len (length str)) dest chr)
286 (setq chr (aref str i))
289 chr (+ (lsh chr 8) (aref str i))
291 (setq dest (cons chr dest))
297 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
299 ;;; Imported from Mule-2.3
300 (defun truncate-string (str width &optional start-column)
301 "Truncate STR to fit in WIDTH columns.
302 Optional non-nil arg START-COLUMN specifies the starting column.
303 \[emu-mule.el; Mule 2.3 emulating function]"
305 (setq start-column 0))
306 (let ((max-width (string-width str))
311 (if (>= width max-width)
312 (setq width max-width))
313 (if (>= start-column width)
315 (while (< column start-column)
316 (setq ch (aref str from)
317 column (+ column (char-columns ch))
318 from (+ from (char-bytes ch))))
319 (if (< width max-width)
322 (while (<= column width)
323 (setq ch (aref str to)
324 column (+ column (char-columns ch))
326 to (+ to (char-bytes ch))))
328 (substring str from to))))
330 ;;; @@ for Mule emulation
333 (defalias 'string-width 'length)
336 ;;; @ text property emulation
339 (setq tl:available-face-attribute-alist
341 ;;(bold . inversed-region)
342 (italic . underlined-region)
343 (underline . underlined-region)
346 ;; by YAMATE Keiichirou 1994/10/28
347 (defun attribute-add-narrow-attribute (attr from to)
348 (or (consp (symbol-value attr))
350 (let* ((attr-value (symbol-value attr))
351 (len (car attr-value))
354 (while (and (< posfrom len)
355 (> from (nth posfrom attr-value)))
356 (setq posfrom (1+ posfrom)))
358 (while (and (< posto len)
359 (> to (nth posto attr-value)))
360 (setq posto (1+ posto)))
361 (if (= posto posfrom)
362 (if (= (% posto 2) 1)
364 (= to (nth posto attr-value)))
365 (set-marker (nth posto attr-value) from)
366 (setcdr (nthcdr (1- posfrom) attr-value)
367 (cons (set-marker-type (set-marker (make-marker)
370 (cons (set-marker-type (set-marker (make-marker)
373 (nthcdr posto attr-value))))
374 (setcar attr-value (+ len 2))))
375 (if (= (% posfrom 2) 0)
376 (setq posfrom (1- posfrom))
377 (set-marker (nth posfrom attr-value) from))
378 (if (= (% posto 2) 0)
380 (setq posto (1- posto))
381 (set-marker (nth posto attr-value) to))
382 (setcdr (nthcdr posfrom attr-value)
383 (nthcdr posto attr-value)))))
385 (defalias 'tl:make-overlay 'cons)
387 (defun tl:overlay-put (overlay prop value)
388 (let ((ret (and (eq prop 'face)
389 (assq value tl:available-face-attribute-alist)
392 (attribute-add-narrow-attribute (cdr ret)
393 (car overlay)(cdr overlay))
400 (provide 'emu-nemacs)
402 ;;; emu-nemacs.el ends here