1 ;;; emu-nemacs.el --- emu API implementation for NEmacs
3 ;; Copyright (C) 1995,1996,1997 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-nemacs.el,v 7.53 1997/04/05 16:23:23 morioka Exp $
7 ;; Keywords: emulation, compatibility, NEmacs, mule
9 ;; This file is part of emu.
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)
178 (defmacro as-binary-output-file (&rest body)
184 ;;; @@ for old MULE emulation
187 (defun code-convert-string (str ic oc)
188 "Convert code in STRING from SOURCE code to TARGET code,
189 On successful converion, returns the result string,
190 else returns nil. [emu-nemacs.el; Mule emulating function]"
192 (convert-string-kanji-code str ic oc)
195 (defun code-convert-region (beg end ic oc)
196 "Convert code of the text between BEGIN and END from SOURCE
197 to TARGET. On successful conversion returns t,
198 else returns nil. [emu-nemacs.el; Mule emulating function]"
202 (narrow-to-region beg end)
203 (convert-region-kanji-code beg end ic oc)
210 (defun insert-binary-file-contents-literally
211 (filename &optional visit beg end replace)
212 "Like `insert-file-contents-literally', q.v., but don't code conversion.
213 A buffer may be modified in several ways after reading into the buffer due
214 to advanced Emacs features, such as file-name-handlers, format decoding,
215 find-file-hooks, etc.
216 This function ensures that none of these modifications will take place.
219 (insert-file-contents-literally filename visit beg end replace)
226 (defvar charsets-mime-charset-alist
227 (list (cons (list charset-ascii) 'us-ascii)))
229 (defvar default-mime-charset 'iso-2022-jp)
231 (defvar mime-charset-coding-system-alist
236 (defun mime-charset-to-coding-system (charset)
237 (if (stringp charset)
238 (setq charset (intern (downcase charset)))
240 (cdr (assq charset mime-charset-coding-system-alist))
243 (defun detect-mime-charset-region (start end)
244 "Return MIME charset for region between START and END.
248 (narrow-to-region start end)
250 (re-search-forward "[\200-\377]" nil t)
255 (defun encode-mime-charset-region (start end charset)
256 "Encode the text between START and END as MIME CHARSET.
258 (let ((cs (mime-charset-to-coding-system charset)))
263 (narrow-to-region start end)
264 (convert-region-kanji-code start end 3 cs)
268 (defun decode-mime-charset-region (start end charset)
269 "Decode the text between START and END as MIME CHARSET.
271 (let ((cs (mime-charset-to-coding-system charset)))
276 (narrow-to-region start end)
277 (convert-region-kanji-code start end cs 3)
281 (defun encode-mime-charset-string (string charset)
282 "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
283 (let ((cs (mime-charset-to-coding-system charset)))
285 (convert-string-kanji-code string 3 cs)
288 (defun decode-mime-charset-string (string charset)
289 "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
290 (let ((cs (mime-charset-to-coding-system charset)))
292 (convert-string-kanji-code string cs 3)
299 (defun char-charset (chr)
300 "Return the character set of char CHR.
301 \[emu-nemacs.el; XEmacs 20 emulating function]"
306 (defun char-bytes (chr)
307 "Return number of bytes CHAR will occupy in a buffer.
308 \[emu-nemacs.el; Mule emulating function]"
309 (if (< chr 128) 1 2))
311 (defalias 'char-length 'char-bytes)
313 (defun char-columns (character)
314 "Return number of columns a CHARACTER occupies when displayed.
316 (if (< character 128)
320 ;;; @@ for Mule emulation
323 (defalias 'char-leading-char 'char-charset)
325 (defalias 'char-width 'char-columns)
331 (defalias 'string-columns 'length)
333 (defun sref (str idx)
334 "Return the character in STR at index IDX.
335 \[emu-nemacs.el; Mule emulating function]"
336 (let ((chr (aref str idx)))
339 (logior (lsh (aref str (1+ idx)) 8) chr)
342 (defun string-to-char-list (str)
343 (let ((i 0)(len (length str)) dest chr)
345 (setq chr (aref str i))
348 chr (+ (lsh chr 8) (aref str i))
350 (setq dest (cons chr dest))
356 (fset 'string-to-int-list (symbol-function 'string-to-char-list))
358 ;;; Imported from Mule-2.3
359 (defun truncate-string (str width &optional start-column)
360 "Truncate STR to fit in WIDTH columns.
361 Optional non-nil arg START-COLUMN specifies the starting column.
362 \[emu-mule.el; Mule 2.3 emulating function]"
364 (setq start-column 0))
365 (let ((max-width (string-width str))
370 (if (>= width max-width)
371 (setq width max-width))
372 (if (>= start-column width)
374 (while (< column start-column)
375 (setq ch (aref str from)
376 column (+ column (char-columns ch))
377 from (+ from (char-bytes ch))))
378 (if (< width max-width)
381 (while (<= column width)
382 (setq ch (aref str to)
383 column (+ column (char-columns ch))
385 to (+ to (char-bytes ch))))
387 (substring str from to))))
389 ;;; @@ for Mule emulation
392 (defalias 'string-width 'length)
395 ;;; @ text property emulation
398 (defvar emu:available-face-attribute-alist
400 ;;(bold . inversed-region)
401 (italic . underlined-region)
402 (underline . underlined-region)
405 ;; by YAMATE Keiichirou 1994/10/28
406 (defun attribute-add-narrow-attribute (attr from to)
407 (or (consp (symbol-value attr))
409 (let* ((attr-value (symbol-value attr))
410 (len (car attr-value))
413 (while (and (< posfrom len)
414 (> from (nth posfrom attr-value)))
415 (setq posfrom (1+ posfrom)))
417 (while (and (< posto len)
418 (> to (nth posto attr-value)))
419 (setq posto (1+ posto)))
420 (if (= posto posfrom)
421 (if (= (% posto 2) 1)
423 (= to (nth posto attr-value)))
424 (set-marker (nth posto attr-value) from)
425 (setcdr (nthcdr (1- posfrom) attr-value)
426 (cons (set-marker-type (set-marker (make-marker)
429 (cons (set-marker-type (set-marker (make-marker)
432 (nthcdr posto attr-value))))
433 (setcar attr-value (+ len 2))))
434 (if (= (% posfrom 2) 0)
435 (setq posfrom (1- posfrom))
436 (set-marker (nth posfrom attr-value) from))
437 (if (= (% posto 2) 0)
439 (setq posto (1- posto))
440 (set-marker (nth posto attr-value) to))
441 (setcdr (nthcdr posfrom attr-value)
442 (nthcdr posto attr-value)))))
444 (defalias 'make-overlay 'cons)
446 (defun overlay-put (overlay prop value)
447 (let ((ret (and (eq prop 'face)
448 (assq value emu:available-face-attribute-alist)
451 (attribute-add-narrow-attribute (cdr ret)
452 (car overlay)(cdr overlay))
459 (provide 'emu-nemacs)
461 ;;; emu-nemacs.el ends here