1 ;;; emu-nemacs.el --- Mule 2 emulation module for NEmacs
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-nemacs.el,v 7.49 1996/10/01 13:26:34 morioka Exp $
7 ;; Keywords: emulation, compatibility, NEmacs, mule
9 ;; This file is part of tl (Tiny Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
34 (defconst charset-ascii 0 "Character set of ASCII")
35 (defconst charset-jisx0208 146 "Character set of JIS X0208-1983")
37 (defun charset-description (charset)
38 "Return description of CHARSET. [emu-nemacs.el]"
40 (documentation-property 'charset-ascii 'variable-documentation)
41 (documentation-property 'charset-jisx0208 'variable-documentation)
44 (defun charset-registry (charset)
45 "Return registry name of CHARSET. [emu-nemacs.el]"
50 (defun charset-columns (charset)
51 "Return number of columns a CHARSET occupies when displayed.
57 (defun charset-direction (charset)
58 "Return the direction of a character of CHARSET by
59 0 (left-to-right) or 1 (right-to-left). [emu-nemacs.el]"
62 (defun find-charset-string (str)
63 "Return a list of charsets in the string.
64 \[emu-nemacs.el; Mule emulating function]"
65 (if (string-match "[\200-\377]" str)
69 (defalias 'find-non-ascii-charset-string 'find-charset-string)
71 (defun find-charset-region (start end)
72 "Return a list of charsets in the region between START and END.
73 \[emu-nemacs.el; Mule emulating function]"
76 (narrow-to-region start end)
78 (re-search-forward "[\200-\377]" nil t)
83 (defalias 'find-non-ascii-charset-region 'find-charset-region)
85 (defun check-ASCII-string (str)
88 (setq len (length str))
91 (if (>= (elt str i) 128)
97 ;;; @@ for old MULE emulation
100 (defconst lc-ascii 0)
107 (defconst *noconv* 0)
111 (defconst *internal* 3)
112 (defconst *euc-japan* 3)
114 (defun decode-coding-string (string coding-system)
115 "Decode the STRING which is encoded in CODING-SYSTEM.
116 \[emu-nemacs.el; EMACS 20 emulating function]"
117 (if (eq coding-system 3)
119 (convert-string-kanji-code string coding-system 3)
122 (defun encode-coding-string (string coding-system)
123 "Encode the STRING to CODING-SYSTEM.
124 \[emu-nemacs.el; EMACS 20 emulating function]"
125 (if (eq coding-system 3)
127 (convert-string-kanji-code string 3 coding-system)
130 (defun decode-coding-region (start end coding-system)
131 "Decode the text between START and END which is encoded in CODING-SYSTEM.
132 \[emu-nemacs.el; EMACS 20 emulating function]"
136 (narrow-to-region start end)
137 (convert-region-kanji-code start end coding-system 3)
140 (defun encode-coding-region (start end coding-system)
141 "Encode the text between START and END to CODING-SYSTEM.
142 \[emu-nemacs.el; EMACS 20 emulating function]"
146 (narrow-to-region start end)
147 (convert-region-kanji-code start end 3 coding-system)
150 (defun detect-coding-region (start end)
151 "Detect coding-system of the text in the region between START and END.
152 \[emu-nemacs.el; Emacs 20 emulating function]"
155 (narrow-to-region start end)
157 (re-search-forward "[\200-\377]" nil t)
162 (defalias 'set-buffer-file-coding-system 'set-kanji-fileio-code)
164 (defmacro as-binary-process (&rest body)
165 (` (let (selective-display ; Disable ^M to nl translation.
168 (default-kanji-process-code 0)
169 program-kanji-code-alist)
173 (defmacro as-binary-input-file (&rest body)
179 ;;; @@ for old MULE emulation
182 (defun code-convert-string (str ic oc)
183 "Convert code in STRING from SOURCE code to TARGET code,
184 On successful converion, returns the result string,
185 else returns nil. [emu-nemacs.el; Mule emulating function]"
187 (convert-string-kanji-code str ic oc)
190 (defun code-convert-region (beg end ic oc)
191 "Convert code of the text between BEGIN and END from SOURCE
192 to TARGET. On successful conversion returns t,
193 else returns nil. [emu-nemacs.el; Mule emulating function]"
197 (narrow-to-region beg end)
198 (convert-region-kanji-code beg end ic oc)
205 (defvar charsets-mime-charset-alist
206 (list (cons (list charset-ascii) 'us-ascii)))
208 (defvar default-mime-charset 'iso-2022-jp)
210 (defvar mime-charset-coding-system-alist
215 (defun mime-charset-to-coding-system (charset)
216 (if (stringp charset)
217 (setq charset (intern (downcase charset)))
219 (cdr (assq charset mime-charset-coding-system-alist))
222 (defun detect-mime-charset-region (start end)
223 "Return MIME charset for region between START and END.
227 (narrow-to-region start end)
229 (re-search-forward "[\200-\377]" nil t)
234 (defun encode-mime-charset-region (start end charset)
235 "Encode the text between START and END as MIME CHARSET.
237 (let ((cs (mime-charset-to-coding-system charset)))
242 (narrow-to-region start end)
243 (convert-region-kanji-code start end 3 cs)
247 (defun decode-mime-charset-region (start end charset)
248 "Decode the text between START and END as MIME CHARSET.
250 (let ((cs (mime-charset-to-coding-system charset)))
255 (narrow-to-region start end)
256 (convert-region-kanji-code start end cs 3)
260 (defun encode-mime-charset-string (string charset)
261 "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
262 (let ((cs (mime-charset-to-coding-system charset)))
264 (convert-string-kanji-code string 3 cs)
267 (defun decode-mime-charset-string (string charset)
268 "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
269 (let ((cs (mime-charset-to-coding-system charset)))
271 (convert-string-kanji-code string cs 3)
278 (defun char-charset (chr)
279 "Return the character set of char CHR.
280 \[emu-nemacs.el; XEmacs 20 emulating function]"
285 (defun char-bytes (chr)
286 "Return number of bytes CHAR will occupy in a buffer.
287 \[emu-nemacs.el; Mule emulating function]"
288 (if (< chr 128) 1 2))
290 (defalias 'char-length 'char-bytes)
292 (defun char-columns (character)
293 "Return number of columns a CHARACTER occupies when displayed.
295 (if (< character 128)
299 ;;; @@ for Mule emulation
302 (defalias 'char-leading-char 'char-charset)
304 (defalias 'char-width 'char-columns)
310 (defalias 'string-columns 'length)
312 (defun sref (str idx)
313 "Return the character in STR at index IDX.
314 \[emu-nemacs.el; Mule emulating function]"
315 (let ((chr (aref str idx)))
318 (logior (lsh (aref str (1+ idx)) 8) chr)
321 (defun string-to-char-list (str)
322 (let ((i 0)(len (length str)) dest chr)
324 (setq chr (aref str i))
327 chr (+ (lsh chr 8) (aref str i))
329 (setq dest (cons chr dest))
335 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
337 ;;; Imported from Mule-2.3
338 (defun truncate-string (str width &optional start-column)
339 "Truncate STR to fit in WIDTH columns.
340 Optional non-nil arg START-COLUMN specifies the starting column.
341 \[emu-mule.el; Mule 2.3 emulating function]"
343 (setq start-column 0))
344 (let ((max-width (string-width str))
349 (if (>= width max-width)
350 (setq width max-width))
351 (if (>= start-column width)
353 (while (< column start-column)
354 (setq ch (aref str from)
355 column (+ column (char-columns ch))
356 from (+ from (char-bytes ch))))
357 (if (< width max-width)
360 (while (<= column width)
361 (setq ch (aref str to)
362 column (+ column (char-columns ch))
364 to (+ to (char-bytes ch))))
366 (substring str from to))))
368 ;;; @@ for Mule emulation
371 (defalias 'string-width 'length)
374 ;;; @ text property emulation
377 (setq tl:available-face-attribute-alist
379 ;;(bold . inversed-region)
380 (italic . underlined-region)
381 (underline . underlined-region)
384 ;; by YAMATE Keiichirou 1994/10/28
385 (defun attribute-add-narrow-attribute (attr from to)
386 (or (consp (symbol-value attr))
388 (let* ((attr-value (symbol-value attr))
389 (len (car attr-value))
392 (while (and (< posfrom len)
393 (> from (nth posfrom attr-value)))
394 (setq posfrom (1+ posfrom)))
396 (while (and (< posto len)
397 (> to (nth posto attr-value)))
398 (setq posto (1+ posto)))
399 (if (= posto posfrom)
400 (if (= (% posto 2) 1)
402 (= to (nth posto attr-value)))
403 (set-marker (nth posto attr-value) from)
404 (setcdr (nthcdr (1- posfrom) attr-value)
405 (cons (set-marker-type (set-marker (make-marker)
408 (cons (set-marker-type (set-marker (make-marker)
411 (nthcdr posto attr-value))))
412 (setcar attr-value (+ len 2))))
413 (if (= (% posfrom 2) 0)
414 (setq posfrom (1- posfrom))
415 (set-marker (nth posfrom attr-value) from))
416 (if (= (% posto 2) 0)
418 (setq posto (1- posto))
419 (set-marker (nth posto attr-value) to))
420 (setcdr (nthcdr posfrom attr-value)
421 (nthcdr posto attr-value)))))
423 (defalias 'tl:make-overlay 'cons)
425 (defun tl:overlay-put (overlay prop value)
426 (let ((ret (and (eq prop 'face)
427 (assq value tl:available-face-attribute-alist)
430 (attribute-add-narrow-attribute (cdr ret)
431 (car overlay)(cdr overlay))
438 (provide 'emu-nemacs)
440 ;;; emu-nemacs.el ends here