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.48 1996/09/23 20:31:12 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 (defun find-charset-region (start end)
70 "Return a list of charsets in the region between START and END.
71 \[emu-nemacs.el; Mule emulating function]"
74 (narrow-to-region start end)
76 (re-search-forward "[\200-\377]" nil t)
81 (defun check-ASCII-string (str)
84 (setq len (length str))
87 (if (>= (elt str i) 128)
93 ;;; @@ for old MULE emulation
103 (defconst *noconv* 0)
107 (defconst *internal* 3)
108 (defconst *euc-japan* 3)
110 (defun decode-coding-string (string coding-system)
111 "Decode the STRING which is encoded in CODING-SYSTEM.
112 \[emu-nemacs.el; EMACS 20 emulating function]"
113 (if (eq coding-system 3)
115 (convert-string-kanji-code string coding-system 3)
118 (defun encode-coding-string (string coding-system)
119 "Encode the STRING to CODING-SYSTEM.
120 \[emu-nemacs.el; EMACS 20 emulating function]"
121 (if (eq coding-system 3)
123 (convert-string-kanji-code string 3 coding-system)
126 (defun decode-coding-region (start end coding-system)
127 "Decode the text between START and END which is encoded in CODING-SYSTEM.
128 \[emu-nemacs.el; EMACS 20 emulating function]"
132 (narrow-to-region start end)
133 (convert-region-kanji-code start end coding-system 3)
136 (defun encode-coding-region (start end coding-system)
137 "Encode the text between START and END to CODING-SYSTEM.
138 \[emu-nemacs.el; EMACS 20 emulating function]"
142 (narrow-to-region start end)
143 (convert-region-kanji-code start end 3 coding-system)
146 (defun detect-coding-region (start end)
147 "Detect coding-system of the text in the region between START and END.
148 \[emu-nemacs.el; Emacs 20 emulating function]"
151 (narrow-to-region start end)
153 (re-search-forward "[\200-\377]" nil t)
158 (defalias 'set-buffer-file-coding-system 'set-kanji-fileio-code)
160 (defmacro as-binary-process (&rest body)
161 (` (let (selective-display ; Disable ^M to nl translation.
164 (default-kanji-process-code 0)
165 program-kanji-code-alist)
169 (defmacro as-binary-input-file (&rest body)
175 ;;; @@ for old MULE emulation
178 (defun code-convert-string (str ic oc)
179 "Convert code in STRING from SOURCE code to TARGET code,
180 On successful converion, returns the result string,
181 else returns nil. [emu-nemacs.el; Mule emulating function]"
183 (convert-string-kanji-code str ic oc)
186 (defun code-convert-region (beg end ic oc)
187 "Convert code of the text between BEGIN and END from SOURCE
188 to TARGET. On successful conversion returns t,
189 else returns nil. [emu-nemacs.el; Mule emulating function]"
193 (narrow-to-region beg end)
194 (convert-region-kanji-code beg end ic oc)
201 (defvar charsets-mime-charset-alist
202 (list (cons (list charset-ascii) 'us-ascii)))
204 (defvar default-mime-charset 'iso-2022-jp)
206 (defvar mime-charset-coding-system-alist
211 (defun mime-charset-to-coding-system (charset)
212 (if (stringp charset)
213 (setq charset (intern (downcase charset)))
215 (cdr (assq charset mime-charset-coding-system-alist))
218 (defun detect-mime-charset-region (start end)
219 "Return MIME charset for region between START and END.
223 (narrow-to-region start end)
225 (re-search-forward "[\200-\377]" nil t)
230 (defun encode-mime-charset-region (start end charset)
231 "Encode the text between START and END as MIME CHARSET.
233 (let ((cs (mime-charset-to-coding-system charset)))
238 (narrow-to-region start end)
239 (convert-region-kanji-code start end 3 cs)
243 (defun decode-mime-charset-region (start end charset)
244 "Decode the text between START and END as MIME CHARSET.
246 (let ((cs (mime-charset-to-coding-system charset)))
251 (narrow-to-region start end)
252 (convert-region-kanji-code start end cs 3)
256 (defun encode-mime-charset-string (string charset)
257 "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
258 (let ((cs (mime-charset-to-coding-system charset)))
260 (convert-string-kanji-code string 3 cs)
263 (defun decode-mime-charset-string (string charset)
264 "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
265 (let ((cs (mime-charset-to-coding-system charset)))
267 (convert-string-kanji-code string cs 3)
274 (defun char-charset (chr)
275 "Return the character set of char CHR.
276 \[emu-nemacs.el; XEmacs 20 emulating function]"
281 (defun char-bytes (chr)
282 "Return number of bytes CHAR will occupy in a buffer.
283 \[emu-nemacs.el; Mule emulating function]"
284 (if (< chr 128) 1 2))
286 (defalias 'char-length 'char-bytes)
288 (defun char-columns (character)
289 "Return number of columns a CHARACTER occupies when displayed.
291 (if (< character 128)
295 ;;; @@ for Mule emulation
298 (defalias 'char-leading-char 'char-charset)
300 (defalias 'char-width 'char-columns)
306 (defalias 'string-columns 'length)
308 (defun sref (str idx)
309 "Return the character in STR at index IDX.
310 \[emu-nemacs.el; Mule emulating function]"
311 (let ((chr (aref str idx)))
314 (logior (lsh (aref str (1+ idx)) 8) chr)
317 (defun string-to-char-list (str)
318 (let ((i 0)(len (length str)) dest chr)
320 (setq chr (aref str i))
323 chr (+ (lsh chr 8) (aref str i))
325 (setq dest (cons chr dest))
331 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
333 ;;; Imported from Mule-2.3
334 (defun truncate-string (str width &optional start-column)
335 "Truncate STR to fit in WIDTH columns.
336 Optional non-nil arg START-COLUMN specifies the starting column.
337 \[emu-mule.el; Mule 2.3 emulating function]"
339 (setq start-column 0))
340 (let ((max-width (string-width str))
345 (if (>= width max-width)
346 (setq width max-width))
347 (if (>= start-column width)
349 (while (< column start-column)
350 (setq ch (aref str from)
351 column (+ column (char-columns ch))
352 from (+ from (char-bytes ch))))
353 (if (< width max-width)
356 (while (<= column width)
357 (setq ch (aref str to)
358 column (+ column (char-columns ch))
360 to (+ to (char-bytes ch))))
362 (substring str from to))))
364 ;;; @@ for Mule emulation
367 (defalias 'string-width 'length)
370 ;;; @ text property emulation
373 (setq tl:available-face-attribute-alist
375 ;;(bold . inversed-region)
376 (italic . underlined-region)
377 (underline . underlined-region)
380 ;; by YAMATE Keiichirou 1994/10/28
381 (defun attribute-add-narrow-attribute (attr from to)
382 (or (consp (symbol-value attr))
384 (let* ((attr-value (symbol-value attr))
385 (len (car attr-value))
388 (while (and (< posfrom len)
389 (> from (nth posfrom attr-value)))
390 (setq posfrom (1+ posfrom)))
392 (while (and (< posto len)
393 (> to (nth posto attr-value)))
394 (setq posto (1+ posto)))
395 (if (= posto posfrom)
396 (if (= (% posto 2) 1)
398 (= to (nth posto attr-value)))
399 (set-marker (nth posto attr-value) from)
400 (setcdr (nthcdr (1- posfrom) attr-value)
401 (cons (set-marker-type (set-marker (make-marker)
404 (cons (set-marker-type (set-marker (make-marker)
407 (nthcdr posto attr-value))))
408 (setcar attr-value (+ len 2))))
409 (if (= (% posfrom 2) 0)
410 (setq posfrom (1- posfrom))
411 (set-marker (nth posfrom attr-value) from))
412 (if (= (% posto 2) 0)
414 (setq posto (1- posto))
415 (set-marker (nth posto attr-value) to))
416 (setcdr (nthcdr posfrom attr-value)
417 (nthcdr posto attr-value)))))
419 (defalias 'tl:make-overlay 'cons)
421 (defun tl:overlay-put (overlay prop value)
422 (let ((ret (and (eq prop 'face)
423 (assq value tl:available-face-attribute-alist)
426 (attribute-add-narrow-attribute (cdr ret)
427 (car overlay)(cdr overlay))
434 (provide 'emu-nemacs)
436 ;;; emu-nemacs.el ends here